use of org.activityinfo.store.testing.IncidentForm in project activityinfo by bedatadriven.
the class RecordTreeLoaderTest method subforms.
@Test
public void subforms() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
RecordRef rootRecordRef = incidentForm.getRecordRef(0);
Observable<Maybe<RecordTree>> recordTree = setup.getFormStore().getRecordTree(rootRecordRef);
Connection<Maybe<RecordTree>> recordTreeView = setup.connect(recordTree);
Iterable<FormInstance> subRecords = recordTreeView.assertLoaded().get().getSubRecords(rootRecordRef, ReferralSubForm.FORM_ID);
assertThat(Iterables.size(subRecords), equalTo(4));
}
use of org.activityinfo.store.testing.IncidentForm in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormExport.
@Test
public void testSubFormExport() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).addColumns(ImmutableTableColumn.builder().label("My PCODE").formula(IncidentForm.PROTECTION_CODE_FIELD_ID.asString()).build()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<TableModel> exportModel = setup.connect(viewModel.computeExportModel(Observable.just(ReferralSubForm.FORM_ID), Observable.just(ExportScope.SELECTED)));
System.out.println(Json.stringify(exportModel.assertLoaded().toJson(), 2));
assertThat(exportModel.assertLoaded().getFormId(), equalTo(ReferralSubForm.FORM_ID));
assertThat(exportModel.assertLoaded().getColumns(), hasSize(3));
TableColumn firstColumn = exportModel.assertLoaded().getColumns().get(0);
assertThat(firstColumn.getLabel(), equalTo(Optional.of("My PCODE")));
assertThat(firstColumn.getFormula(), equalTo(new CompoundExpr(new SymbolNode(ColumnModel.PARENT_SYMBOL), IncidentForm.PROTECTION_CODE_FIELD_ID).asExpression()));
}
use of org.activityinfo.store.testing.IncidentForm in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormPane.
@Test
public void testSubFormPane() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<EffectiveTableModel> subTableView = setup.connect(viewModel.getEffectiveSubTable(ReferralSubForm.FORM_ID));
Connection<ColumnSet> subTable = setup.connect(subTableView.assertLoaded().getColumnSet());
// The sub table should not include parent forms
for (EffectiveTableColumn subColumn : subTableView.assertLoaded().getColumns()) {
if (subColumn.getLabel().equals(incidentForm.getUrgencyField().getLabel())) {
throw new AssertionError("Sub table should not include parent fields");
}
}
// Initially there should be no rows because there is no selection
assertThat(subTable.assertLoaded().getNumRows(), equalTo(0));
// Once we make a selection, then the column set should update to show the sub records of the selected
// parent record
subTable.resetChangeCounter();
viewModel.select(incidentForm.getRecordRef(0));
setup.runScheduled();
subTable.assertChanged();
assertThat(subTable.assertLoaded().getNumRows(), equalTo(4));
}
Aggregations