Search in sources :

Example 1 with DeleteRecordAction

use of org.activityinfo.ui.client.table.view.DeleteRecordAction 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

Optional (com.google.common.base.Optional)1 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)1 TableModel (org.activityinfo.model.analysis.TableModel)1 RecordRef (org.activityinfo.model.type.RecordRef)1 DeleteRecordAction (org.activityinfo.ui.client.table.view.DeleteRecordAction)1 Test (org.junit.Test)1