Search in sources :

Example 1 with InMemInstancesRepository

use of org.odk.collect.formstest.InMemInstancesRepository in project collect by opendatakit.

the class FormMapViewModelTest method clearingInstanceGeometry_isReflectedInInstanceCountsAndList.

@Test
public void clearingInstanceGeometry_isReflectedInInstanceCountsAndList() {
    FormMapViewModel viewModel = new FormMapViewModel(TEST_FORM_1, testInstancesRepository);
    List<FormMapViewModel.MappableFormInstance> mappableInstances = viewModel.getMappableFormInstances();
    assertThat(viewModel.getTotalInstanceCount(), is(7));
    assertThat(mappableInstances.size(), is(6));
    assertThat(mappableInstances.get(5).getClickAction(), is(FormMapViewModel.ClickAction.NOT_VIEWABLE_TOAST));
    ((InMemInstancesRepository) testInstancesRepository).removeInstanceById(6L);
    ((InMemInstancesRepository) testInstancesRepository).save(new Instance.Builder().dbId(6L).formId("formId1").formVersion("2019103101").geometryType("").geometry("").canEditWhenComplete(false).status(Instance.STATUS_SUBMISSION_FAILED).build());
    mappableInstances = viewModel.getMappableFormInstances();
    assertThat(viewModel.getTotalInstanceCount(), is(7));
    assertThat(mappableInstances.size(), is(5));
    assertThat(mappableInstances.get(4).getClickAction(), is(FormMapViewModel.ClickAction.OPEN_READ_ONLY));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InMemInstancesRepository(org.odk.collect.formstest.InMemInstancesRepository) FormMapViewModel(org.odk.collect.android.activities.viewmodels.FormMapViewModel) Test(org.junit.Test)

Example 2 with InMemInstancesRepository

use of org.odk.collect.formstest.InMemInstancesRepository in project collect by opendatakit.

the class FormMapViewModelTest method addingAnInstance_isReflectedInInstanceCountsAndList.

@Test
public void addingAnInstance_isReflectedInInstanceCountsAndList() {
    FormMapViewModel viewModel = new FormMapViewModel(TEST_FORM_1, testInstancesRepository);
    List<FormMapViewModel.MappableFormInstance> instances = viewModel.getMappableFormInstances();
    assertThat(viewModel.getTotalInstanceCount(), is(7));
    assertThat(instances.size(), is(6));
    Instance newInstance = new Instance.Builder().dbId(8L).formId("formId1").formVersion("2019103101").geometryType("Point").geometry("{\"type\":\"Point\",\"coordinates\":[127.6, 11.1]}").canEditWhenComplete(true).status(Instance.STATUS_COMPLETE).build();
    ((InMemInstancesRepository) testInstancesRepository).save(newInstance);
    instances = viewModel.getMappableFormInstances();
    assertThat(viewModel.getTotalInstanceCount(), is(8));
    assertThat(instances.size(), is(7));
    assertThat(instances.get(6).getClickAction(), is(FormMapViewModel.ClickAction.OPEN_EDIT));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InMemInstancesRepository(org.odk.collect.formstest.InMemInstancesRepository) FormMapViewModel(org.odk.collect.android.activities.viewmodels.FormMapViewModel) Test(org.junit.Test)

Example 3 with InMemInstancesRepository

use of org.odk.collect.formstest.InMemInstancesRepository in project collect by opendatakit.

the class InstanceUploaderUtilsTest method getTestInstancesRepository.

private InMemInstancesRepository getTestInstancesRepository() {
    InMemInstancesRepository instancesRepository = new InMemInstancesRepository();
    for (int i = 1; i <= NUMBER_OF_INSTANCES_TO_SEND; i++) {
        long time = System.currentTimeMillis();
        Instance instance = new Instance.Builder().dbId((long) i).displayName("InstanceTest").formId("instanceTest").status(Instance.STATUS_COMPLETE).lastStatusChangeDate(time).build();
        instancesRepository.save(instance);
    }
    return instancesRepository;
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InMemInstancesRepository(org.odk.collect.formstest.InMemInstancesRepository)

Aggregations

Instance (org.odk.collect.forms.instances.Instance)3 InMemInstancesRepository (org.odk.collect.formstest.InMemInstancesRepository)3 Test (org.junit.Test)2 FormMapViewModel (org.odk.collect.android.activities.viewmodels.FormMapViewModel)2