Search in sources :

Example 61 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class FormInputViewModelTest method lockedMonthlySubForms.

@Test
public void lockedMonthlySubForms() {
    ClinicForm clinicForm = setup.getCatalog().getClinicForm();
    ResourceId databaseId = ResourceId.valueOf("db1");
    setup.describeDatabase(new UserDatabaseMeta.Builder().setDatabaseId(databaseId).setLabel("My Database").setOwner(true).setVersion("1").addResource(new Resource.Builder().setId(clinicForm.getFormId()).setParentId(databaseId).setLabel(clinicForm.getFormClass().getLabel()).setType(ResourceType.FORM).build()).addResource(new Resource.Builder().setId(clinicForm.getSubForm().getFormId()).setParentId(clinicForm.getFormId()).setLabel(clinicForm.getSubForm().getFormClass().getLabel()).setType(ResourceType.FORM).build()).addLock(new RecordLock.Builder().setId(ResourceId.valueOf("lock1")).setLabel("Archived").setResourceId(clinicForm.getFormId()).setDateRange(LocalDateInterval.year(2017)).build()).build());
    ResourceId consultCountFieldId = clinicForm.getSubForm().getConsultsField().getId();
    FormInputViewModelBuilder builder = builderFor(clinicForm);
    ResourceId parentRecordId = ResourceId.generateId();
    FormInputModel inputModel = new FormInputModel(new RecordRef(clinicForm.getFormId(), parentRecordId));
    FormInputViewModel viewModel = builder.build(inputModel);
    // Get the sub form view model.
    // The active ref should be set to 2017-10 by default.
    ResourceId subFormFieldId = clinicForm.getSubFormField().getId();
    SubFormViewModel subForm = viewModel.getSubForm(subFormFieldId);
    assertThat(subForm, notNullValue());
    // All of 2017 should be locked
    assertTrue(subForm.getActiveSubViewModel().isLocked());
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Resource(org.activityinfo.model.database.Resource) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) Test(org.junit.Test)

Example 62 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class LookupViewModelTest method multipleLeafKeys.

@Test
public void multipleLeafKeys() {
    IdpLocationForm locationForm = catalog.getIdpLocationForm();
    FormTree formTree = catalog.getFormTree(locationForm.getFormId());
    FormField referenceField = new FormField(ResourceId.generateFieldId(ReferenceType.TYPE_CLASS)).setType(new ReferenceType(Cardinality.SINGLE, locationForm.getFormId()));
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, referenceField);
    assertThat(viewModel.getLookupKeys(), hasSize(3));
    LookupKeyViewModel province = viewModel.getLookupKeys().get(0);
    LookupKeyViewModel type = viewModel.getLookupKeys().get(1);
    LookupKeyViewModel name = viewModel.getLookupKeys().get(2);
    Connection<List<String>> provinceChoices = setup.connect(province.getChoices());
    Connection<List<String>> typeChoices = setup.connect(type.getChoices());
    Connection<List<String>> nameChoices = setup.connect(name.getChoices());
    Connection<Optional<RecordRef>> selection = setup.connect(viewModel.getSelectedRecord());
    viewModel.select(province.getLookupKey(), provinceChoices.assertLoaded().get(0));
    assertThat(typeChoices.assertLoaded(), hasItems(equalTo("Camp"), equalTo("Clinic"), equalTo("School")));
    viewModel.select(type.getLookupKey(), "Camp");
    assertThat(nameChoices.assertLoaded(), hasItems("Location 34", "Location 54", "Location 76"));
    viewModel.select(name.getLookupKey(), "Location 76");
    assertThat(selection.assertLoaded().get(), equalTo(new RecordRef(locationForm.getFormId(), ResourceId.valueOf("c75"))));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) Optional(com.google.common.base.Optional) RecordRef(org.activityinfo.model.type.RecordRef) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType) Test(org.junit.Test)

Example 63 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class LookupViewModelTest method initialSetup.

@Test
public void initialSetup() {
    FormTree formTree = catalog.getFormTree(nfiForm.getFormId());
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, nfiForm.getVillageField());
    viewModel.select(new RecordRef(villageForm.getFormId(), ResourceId.valueOf("c207")));
    Connection<Optional<String>> provinceLabel = setup.connect(viewModel.getLookupKeys().get(0).getSelectedKey());
    Connection<Optional<String>> territoryLabel = setup.connect(viewModel.getLookupKeys().get(1).getSelectedKey());
    Connection<Optional<String>> villageLabel = setup.connect(viewModel.getLookupKeys().get(2).getSelectedKey());
    assertThat(provinceLabel.assertLoaded().get(), equalTo("Province 11"));
    assertThat(territoryLabel.assertLoaded().get(), equalTo("Territory 24"));
    assertThat(villageLabel.assertLoaded().get(), equalTo("Village 208"));
    // Change the territory
    Connection<List<String>> territoryChoices = setup.connect(viewModel.getLookupKeys().get(1).getChoices());
    String newTerritory = territoryChoices.assertLoaded().get(3);
    viewModel.select(viewModel.getLookupKeys().get(1).getLookupKey(), newTerritory);
    // Check updated labels
    assertThat(provinceLabel.assertLoaded().get(), equalTo("Province 11"));
    assertThat(territoryLabel.assertLoaded().get(), equalTo(newTerritory));
    assertThat(villageLabel.assertLoaded().isPresent(), equalTo(false));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) Optional(com.google.common.base.Optional) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 64 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class LookupViewModelTest method select.

@Test
public void select() {
    FormTree formTree = catalog.getFormTree(nfiForm.getFormId());
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, nfiForm.getVillageField());
    LookupKeyViewModel province = viewModel.getLookupKeys().get(0);
    assertThat(province.getKeyLabel(), equalTo("Province Name"));
    // The second level should now reflect these choices
    LookupKeyViewModel territory = viewModel.getLookupKeys().get(1);
    assertThat(territory.getKeyLabel(), equalTo("Territory Name"));
    // Finally the third level is where we choose the village
    LookupKeyViewModel village = viewModel.getLookupKeys().get(2);
    assertThat(village.getKeyLabel(), equalTo("Village Name"));
    // Connect to the lists
    Connection<List<String>> provinceList = setup.connect(province.getChoices());
    Connection<List<String>> territoryList = setup.connect(territory.getChoices());
    Connection<List<String>> villageList = setup.connect(village.getChoices());
    // Connect to the selection
    Connection<Optional<RecordRef>> selection = setup.connect(viewModel.getSelectedRecord());
    // Initially... no selection
    assertThat(selection.assertLoaded().isPresent(), equalTo(false));
    // Initially the root level should have all choices (16)
    assertThat(provinceList.assertLoaded(), hasSize(16));
    // Select an item in the first level, should change
    // the options available to the second level
    viewModel.select(province.getLookupKey(), province.getChoices().get().get(2));
    territoryList.assertChanged();
    System.out.println(territoryList.assertLoaded());
    assertThat(territoryList.assertLoaded(), hasSize(7));
    System.out.println(territoryList.assertLoaded());
    // Select a territory
    viewModel.select(territory.getLookupKey(), territoryList.assertLoaded().get(2));
    villageList.assertChanged();
    // Select a village
    viewModel.select(village.getLookupKey(), villageList.assertLoaded().get(5));
    assertThat(selection.assertLoaded().get(), equalTo(new RecordRef(villageForm.getFormId(), ResourceId.valueOf("c207"))));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) Optional(com.google.common.base.Optional) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 65 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class TableViewModelTest method testDeletedSelection.

@Test
public void testDeletedSelection() {
    TableModel tableModel = ImmutableTableModel.builder().formId(setup.getSurveyForm().getFormId()).build();
    TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
    Connection<Optional<SelectionViewModel>> selection = connect(viewModel.getSelectionViewModel());
    // Initially, we don't expect a selection
    assertThat(selection.assertLoaded().isPresent(), equalTo(false));
    // Ensure that when the selection is changed, the observable changes...
    selection.resetChangeCounter();
    RecordRef selectedRef = setup.getSurveyForm().getRecordRef(101);
    viewModel.select(selectedRef);
    selection.assertChanged();
    setup.runScheduled();
    assertThat(selection.assertLoaded().isPresent(), equalTo(true));
    assertThat(selection.assertLoaded().get().isEditAllowed(), equalTo(true));
    assertThat(selection.assertLoaded().get().isDeleteAllowed(), equalTo(true));
    // Now delete the selected record...
    selection.resetChangeCounter();
    DeleteRecordAction action = new DeleteRecordAction(setup.getFormStore(), "", selectedRef);
    Promise<Void> deleted = action.execute();
    setup.runScheduled();
    assertThat(deleted.getState(), equalTo(Promise.State.FULFILLED));
    // And verify that the selection is changed to empty
    selection.assertChanged();
    assertThat(selection.assertLoaded().isPresent(), equalTo(false));
}
Also used : Optional(com.google.common.base.Optional) RecordRef(org.activityinfo.model.type.RecordRef) DeleteRecordAction(org.activityinfo.ui.client.table.view.DeleteRecordAction) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Aggregations

RecordRef (org.activityinfo.model.type.RecordRef)66 Test (org.junit.Test)31 ResourceId (org.activityinfo.model.resource.ResourceId)26 ReferenceValue (org.activityinfo.model.type.ReferenceValue)26 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)14 FormInstance (org.activityinfo.model.form.FormInstance)7 FormTree (org.activityinfo.model.formTree.FormTree)7 LocalDate (org.activityinfo.model.type.time.LocalDate)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 Optional (com.google.common.base.Optional)5 FieldValue (org.activityinfo.model.type.FieldValue)5 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)5 FormClass (org.activityinfo.model.form.FormClass)4 ResultSet (java.sql.ResultSet)3 FormField (org.activityinfo.model.form.FormField)3 RecordTree (org.activityinfo.model.formTree.RecordTree)3 ColumnSet (org.activityinfo.model.query.ColumnSet)3 ColumnView (org.activityinfo.model.query.ColumnView)3 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)3 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)3