Search in sources :

Example 1 with FormMapViewModel

use of org.odk.collect.android.activities.viewmodels.FormMapViewModel 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 FormMapViewModel

use of org.odk.collect.android.activities.viewmodels.FormMapViewModel in project collect by opendatakit.

the class FormMapViewModelTest method deletedInstance_hasDeletedClickAction.

// Should not actually be possible from UI because geometry is deleted on sent instance delete
@Test
public void deletedInstance_hasDeletedClickAction() {
    FormMapViewModel viewModel = new FormMapViewModel(TEST_FORM_1, testInstancesRepository);
    List<FormMapViewModel.MappableFormInstance> instances = viewModel.getMappableFormInstances();
    assertThat(instances.get(0).getClickAction(), is(FormMapViewModel.ClickAction.DELETED_TOAST));
}
Also used : FormMapViewModel(org.odk.collect.android.activities.viewmodels.FormMapViewModel) Test(org.junit.Test)

Example 3 with FormMapViewModel

use of org.odk.collect.android.activities.viewmodels.FormMapViewModel 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 4 with FormMapViewModel

use of org.odk.collect.android.activities.viewmodels.FormMapViewModel in project collect by opendatakit.

the class FormMapViewModelTest method getDeletedDateOf_returnsDeletedDate.

@Test
public void getDeletedDateOf_returnsDeletedDate() {
    FormMapViewModel viewModel = new FormMapViewModel(TEST_FORM_1, testInstancesRepository);
    assertThat(viewModel.getDeletedDateOf(0L), is(testInstances[0].getDeletedDate()));
}
Also used : FormMapViewModel(org.odk.collect.android.activities.viewmodels.FormMapViewModel) Test(org.junit.Test)

Example 5 with FormMapViewModel

use of org.odk.collect.android.activities.viewmodels.FormMapViewModel in project collect by opendatakit.

the class FormMapViewModelTest method getTotalInstanceCount_returnsCountOfAllInstances.

@Test
public void getTotalInstanceCount_returnsCountOfAllInstances() {
    FormMapViewModel viewModel = new FormMapViewModel(TEST_FORM_1, testInstancesRepository);
    assertThat(viewModel.getTotalInstanceCount(), is(7));
}
Also used : FormMapViewModel(org.odk.collect.android.activities.viewmodels.FormMapViewModel) Test(org.junit.Test)

Aggregations

FormMapViewModel (org.odk.collect.android.activities.viewmodels.FormMapViewModel)13 Test (org.junit.Test)12 Instance (org.odk.collect.forms.instances.Instance)2 InMemInstancesRepository (org.odk.collect.formstest.InMemInstancesRepository)2 Nullable (androidx.annotation.Nullable)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 Form (org.odk.collect.forms.Form)1