use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.
the class FormInputViewModelTest method inputMask.
@Test
public void inputMask() {
IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
FormInputViewModelBuilder builder = builderFor(intakeForm);
FormInputModel inputModel = new FormInputModel(new RecordRef(intakeForm.getFormId(), ResourceId.generateId()));
// Fill in required fields
inputModel = inputModel.update(intakeForm.getOpenDateFieldId(), new LocalDate(2017, 1, 1));
// Does not match input mask "000"
inputModel = inputModel.update(intakeForm.getRegNumberFieldId(), new FieldInput(TextValue.valueOf("FOOOOO")));
FormInputViewModel viewModel = builder.build(inputModel);
assertThat(viewModel.isValid(), equalTo(false));
assertThat(viewModel.getValidationErrors(intakeForm.getRegNumberFieldId()), not(empty()));
}
use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.
the class LookupKeySetTest method labelTest.
@Test
public void labelTest() {
NfiForm nfiForm = setup.getNfiForm();
VillageForm villageForm = setup.getVillageForm();
AdminLevelForm territoryForm = villageForm.getParentForm();
AdminLevelForm provinceForm = territoryForm.getParentForm().get();
Observable<Maybe<RecordTree>> nfiRecordTree = setup.getFormStore().getRecordTree(nfiForm.getRecordRef(0));
Connection<Maybe<RecordTree>> nfiRecordTreeView = setup.connect(nfiRecordTree);
RecordTree tree = nfiRecordTreeView.assertLoaded().get();
LookupKeySet lookupKeySet = new LookupKeySet(tree.getFormTree(), tree.getFormTree().getRootField(nfiForm.getVillageField().getId()).getField());
assertThat(lookupKeySet.getLookupKeys().size(), equalTo(3));
ReferenceValue referenceValue = (ReferenceValue) tree.getRoot().get(nfiForm.getVillageField().getId());
RecordRef villageRef = referenceValue.getOnlyReference();
RecordTree villageTree = tree.subTree(villageRef);
referenceValue = (ReferenceValue) villageTree.getRoot().get(villageForm.getAdminFieldId());
RecordRef territoryRef = referenceValue.getOnlyReference();
RecordTree territoryTree = villageTree.subTree(territoryRef);
referenceValue = (ReferenceValue) territoryTree.getRoot().get(territoryForm.getParentFieldId());
RecordRef provinceRef = referenceValue.getOnlyReference();
Maybe<String> villageLabel = lookupKeySet.label(tree, villageRef);
Maybe<String> territoryLabel = lookupKeySet.label(tree, territoryRef);
Maybe<String> provinceLabel = lookupKeySet.label(tree, provinceRef);
assertThat(villageLabel, equalTo(Maybe.of("Village 660")));
assertThat(territoryLabel, equalTo(Maybe.of("Territory 85")));
assertThat(provinceLabel, equalTo(Maybe.of("Province 11")));
}
use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.
the class LookupViewModelTest method overlappingHierarchies.
@Test
public void overlappingHierarchies() {
LocaliteForm locationForm = catalog.getLocaliteForm();
FormTree formTree = catalog.getFormTree(locationForm.getFormId());
LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, locationForm.getAdminField());
assertThat(viewModel.getLookupKeys(), hasSize(3));
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"));
// We also have a third level -- Health Zone or "Zone de Sante" which
// is related to province, but NOT territory.
LookupKeyViewModel healthZone = viewModel.getLookupKeys().get(2);
assertThat(healthZone.getKeyLabel(), equalTo("Zone de Sante Name"));
// Connect to the lists
Connection<List<String>> provinceList = setup.connect(province.getChoices());
Connection<List<String>> territoryList = setup.connect(territory.getChoices());
Connection<List<String>> zoneList = setup.connect(healthZone.getChoices());
// Connect to the selection
Connection<Set<RecordRef>> selection = setup.connect(viewModel.getSelectedRecords());
// Initially... no selection
assertThat(selection.assertLoaded().isEmpty(), equalTo(true));
// Initially the root level should have all choices (16)
assertThat(provinceList.assertLoaded(), hasSize(catalog.getProvince().getCount()));
// Select a province.
viewModel.select(province.getLookupKey(), province.getChoices().get().get(2));
// Choosing just a province is a valid selection, so we should now have a value
assertThat(selection.assertLoaded(), hasSize(1));
// ..and the options available to the second level
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));
zoneList.assertChanged();
// No we should still have only one selected record, but this time
// territory and not province because province is a parent of territory.
RecordRef territoryRef = new RecordRef(catalog.getTerritory().getFormId(), ResourceId.valueOf("c23"));
assertThat(selection.assertLoaded(), contains(territoryRef));
// We should ALSO be able to select a Zone de Sante
viewModel.select(healthZone.getLookupKey(), zoneList.assertLoaded().get(5));
RecordRef zoneRef = new RecordRef(catalog.getHealthZone().getFormId(), ResourceId.valueOf("c165"));
assertThat(selection.assertLoaded(), containsInAnyOrder(territoryRef, zoneRef));
}
use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.
the class LookupViewModelTest method overlappingHierarchiesInitialSelection.
@Test
public void overlappingHierarchiesInitialSelection() {
LocaliteForm locationForm = catalog.getLocaliteForm();
FormTree formTree = catalog.getFormTree(locationForm.getFormId());
LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, locationForm.getAdminField());
RecordRef territoryRef = new RecordRef(catalog.getTerritory().getFormId(), ResourceId.valueOf("c23"));
Connection<Optional<String>> province = setup.connect(viewModel.getLookupKeys().get(0).getSelectedKey());
Connection<Optional<String>> territory = setup.connect(viewModel.getLookupKeys().get(1).getSelectedKey());
Connection<Optional<String>> healthZone = setup.connect(viewModel.getLookupKeys().get(2).getSelectedKey());
// Initially the key value labels should be empty
assertThat(province.assertLoaded().isPresent(), equalTo(false));
assertThat(territory.assertLoaded().isPresent(), equalTo(false));
assertThat(healthZone.assertLoaded().isPresent(), equalTo(false));
// If the initial selection is a territory then the province and territory labels should be loaded
viewModel.setInitialSelection(Collections.singleton(territoryRef));
assertThat(province.assertLoaded().get(), equalTo("Province 11"));
assertThat(territory.assertLoaded().get(), equalTo("Territory 24"));
assertThat(healthZone.assertLoaded().isPresent(), equalTo(false));
}
use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.
the class TableToolBar method onEditRecord.
private void onEditRecord(SelectEvent event) {
Optional<RecordRef> selected = viewModel.getSelectedRecordRef().get();
if (!selected.isPresent()) {
return;
}
FormDialog dialog = new FormDialog(formStore, selected.get());
dialog.show();
}
Aggregations