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));
}
Aggregations