Search in sources :

Example 11 with TableModel

use of org.activityinfo.model.analysis.TableModel 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)

Example 12 with TableModel

use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.

the class TableViewModelTest method testClassicAdminHierarchy.

@Test
public void testClassicAdminHierarchy() {
    LocaliteForm localiteForm = setup.getCatalog().getLocaliteForm();
    TableModel tableModel = ImmutableTableModel.builder().formId(localiteForm.getFormId()).build();
    TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
    EffectiveTableModel effectiveTable = setup.connect(viewModel.getEffectiveTable()).assertLoaded();
    for (EffectiveTableColumn tableColumn : effectiveTable.getColumns()) {
        System.out.println(tableColumn.getLabel() + " => " + tableColumn.getFormula().getFormula());
    }
}
Also used : LocaliteForm(org.activityinfo.store.testing.LocaliteForm) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Aggregations

TableModel (org.activityinfo.model.analysis.TableModel)12 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)11 Test (org.junit.Test)9 ImmutableTableColumn (org.activityinfo.model.analysis.ImmutableTableColumn)4 TableColumn (org.activityinfo.model.analysis.TableColumn)4 ColumnSet (org.activityinfo.model.query.ColumnSet)3 Optional (com.google.common.base.Optional)2 ArrayList (java.util.ArrayList)2 EffectiveTableModel (org.activityinfo.analysis.table.EffectiveTableModel)2 JsonValue (org.activityinfo.json.JsonValue)2 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 RecordRef (org.activityinfo.model.type.RecordRef)2 IncidentForm (org.activityinfo.store.testing.IncidentForm)2 Queue (com.google.appengine.api.taskqueue.Queue)1 Function (com.google.common.base.Function)1 VoidWork (com.googlecode.objectify.VoidWork)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1