Search in sources :

Example 1 with IncidentForm

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));
}
Also used : Maybe(org.activityinfo.promise.Maybe) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) IncidentForm(org.activityinfo.store.testing.IncidentForm) Test(org.junit.Test)

Example 2 with IncidentForm

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()));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) TableColumn(org.activityinfo.model.analysis.TableColumn) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) IncidentForm(org.activityinfo.store.testing.IncidentForm) Test(org.junit.Test)

Example 3 with IncidentForm

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));
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) IncidentForm(org.activityinfo.store.testing.IncidentForm) Test(org.junit.Test)

Aggregations

IncidentForm (org.activityinfo.store.testing.IncidentForm)3 Test (org.junit.Test)3 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)2 TableModel (org.activityinfo.model.analysis.TableModel)2 ImmutableTableColumn (org.activityinfo.model.analysis.ImmutableTableColumn)1 TableColumn (org.activityinfo.model.analysis.TableColumn)1 FormInstance (org.activityinfo.model.form.FormInstance)1 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)1 SymbolNode (org.activityinfo.model.formula.SymbolNode)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 RecordRef (org.activityinfo.model.type.RecordRef)1 Maybe (org.activityinfo.promise.Maybe)1