Search in sources :

Example 6 with RecordTransaction

use of org.activityinfo.model.resource.RecordTransaction in project activityinfo by bedatadriven.

the class FormStoreTest method newRecordOffline.

@Test
public void newRecordOffline() {
    TestSetup setup = new TestSetup();
    Survey survey = setup.getSurveyForm();
    // Synchronize the survey form
    setup.setConnected(true);
    setup.getFormStore().setFormOffline(survey.getFormId(), true);
    setup.runScheduled();
    // Go offline...
    setup.setConnected(false);
    // Monitor the pending queue status
    Connection<PendingStatus> pendingStatus = setup.connect(setup.getOfflineStore().getPendingStatus());
    assertThat(pendingStatus.assertLoaded().isEmpty(), equalTo(true));
    // Create a new survey record
    FormInstance newRecordTyped = survey.getGenerator().get();
    RecordTransaction tx = RecordTransaction.builder().create(newRecordTyped).build();
    // Update a record...
    Promise<Void> updateResult = setup.getFormStore().updateRecords(tx);
    assertThat(updateResult.getState(), equalTo(Promise.State.FULFILLED));
    // Now query offline...
    Connection<Maybe<FormRecord>> recordView = setup.connect(setup.getFormStore().getRecord(newRecordTyped.getRef()));
    // It should be listed as a pending change...
    assertThat(pendingStatus.assertLoaded().getCount(), equalTo(1));
    Maybe<FormRecord> record = recordView.assertLoaded();
    assertThat(record.getState(), equalTo(Maybe.State.VISIBLE));
    assertThat(record.get().getRecordId(), equalTo(newRecordTyped.getId().asString()));
    // Finally go online and ensure that results are sent to the server
    setup.setConnected(true);
    setup.getOfflineStore().syncChanges();
    // Our queue should be empty again
    assertThat(pendingStatus.assertLoaded().isEmpty(), equalTo(true));
}
Also used : Maybe(org.activityinfo.promise.Maybe) FormInstance(org.activityinfo.model.form.FormInstance) FormRecord(org.activityinfo.model.form.FormRecord) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) Test(org.junit.Test)

Aggregations

RecordTransaction (org.activityinfo.model.resource.RecordTransaction)6 Test (org.junit.Test)4 RecordRef (org.activityinfo.model.type.RecordRef)3 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)3 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)2 MessageBox (com.sencha.gxt.widget.core.client.box.MessageBox)1 CloseEvent (com.sencha.gxt.widget.core.client.event.CloseEvent)1 FormInstance (org.activityinfo.model.form.FormInstance)1 FormRecord (org.activityinfo.model.form.FormRecord)1 RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 Maybe (org.activityinfo.promise.Maybe)1 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)1 TestingFormStore (org.activityinfo.ui.client.store.TestingFormStore)1