Search in sources :

Example 1 with TestingFormStore

use of org.activityinfo.ui.client.store.TestingFormStore in project activityinfo by bedatadriven.

the class AnalysisViewModelTest method testEmptyModel.

@Test
public void testEmptyModel() {
    TestingFormStore formStore = new TestingFormStore();
    AnalysisViewModel model = new AnalysisViewModel(formStore);
    AnalysisResult result = assertLoads(model.getResultTable());
    PivotTable pivotTable = assertLoads(model.getPivotTable());
    assertTrue(pivotTable.isEmpty());
}
Also used : TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) Test(org.junit.Test)

Example 2 with TestingFormStore

use of org.activityinfo.ui.client.store.TestingFormStore in project activityinfo by bedatadriven.

the class FormInputViewModelTest method testSurveyEdit.

@Test
public void testSurveyEdit() {
    TestingFormStore store = new TestingFormStore();
    Survey survey = store.getCatalog().getSurvey();
    RecordRef recordRef = survey.getRecordRef(5);
    FormStructure stucture = fetchStructure(recordRef);
    FormInputViewModelBuilder builder = new FormInputViewModelBuilder(store, stucture.getFormTree(), new TestingActivePeriodMemory());
    FormInputModel inputModel = new FormInputModel(new RecordRef(survey.getFormId(), ResourceId.generateId()));
    FormInputViewModel viewModel = builder.build(inputModel, stucture.getExistingRecord());
    assertTrue(viewModel.isValid());
}
Also used : RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) Test(org.junit.Test)

Example 3 with TestingFormStore

use of org.activityinfo.ui.client.store.TestingFormStore in project activityinfo by bedatadriven.

the class FormInputViewModelTest method testNewlyIrrelvantFieldSetToEmpty.

@Test
public void testNewlyIrrelvantFieldSetToEmpty() {
    TestingFormStore store = new TestingFormStore();
    Survey survey = store.getCatalog().getSurvey();
    RecordRef recordRef = survey.getRecordRef(8);
    FormStructure structure = fetchStructure(recordRef);
    FormInputViewModelBuilder builder = new FormInputViewModelBuilder(store, structure.getFormTree(), new TestingActivePeriodMemory());
    FormInputModel inputModel = new FormInputModel(new RecordRef(survey.getFormId(), ResourceId.generateId()));
    // The record was saved as GENDER=Female, and PREGNANT=No
    FormInputViewModel viewModel = builder.build(inputModel, structure.getExistingRecord());
    assertThat(viewModel.getField(survey.getGenderFieldId()), equalTo(new EnumValue(survey.getFemaleId())));
    assertThat(viewModel.isRelevant(survey.getPregnantFieldId()), equalTo(true));
    assertThat(viewModel.getField(survey.getPregnantFieldId()), equalTo(new EnumValue(survey.getPregnantNo())));
    // When we change the Gender to Male, then PREGNANT should be set to empty
    inputModel = inputModel.update(survey.getGenderFieldId(), new EnumValue(survey.getMaleId()));
    viewModel = builder.build(inputModel, structure.getExistingRecord());
    assertThat(viewModel.isRelevant(survey.getPregnantFieldId()), equalTo(false));
    RecordTransaction tx = viewModel.buildTransaction();
    assertThat(tx.getChangeArray(), arrayWithSize(1));
    RecordUpdate update = tx.getChanges().iterator().next();
    assertTrue(update.getFields().get(survey.getPregnantFieldId().asString()).isJsonNull());
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) Test(org.junit.Test)

Example 4 with TestingFormStore

use of org.activityinfo.ui.client.store.TestingFormStore in project activityinfo by bedatadriven.

the class MeasureListItemStoreTest method setup.

@Before
public void setup() {
    LocaleProxy.initialize();
    formStore = new TestingFormStore();
}
Also used : TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) Before(org.junit.Before)

Example 5 with TestingFormStore

use of org.activityinfo.ui.client.store.TestingFormStore in project activityinfo by bedatadriven.

the class AnalysisViewModelTest method setup.

@Before
public void setup() {
    LocaleProxy.initialize();
    formStore = new TestingFormStore();
    survey = formStore.getCatalog().getSurvey();
    intakeForm = formStore.getCatalog().getIntakeForm();
}
Also used : TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) Before(org.junit.Before)

Aggregations

TestingFormStore (org.activityinfo.ui.client.store.TestingFormStore)5 Test (org.junit.Test)3 RecordRef (org.activityinfo.model.type.RecordRef)2 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)2 Before (org.junit.Before)2 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)1 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1