use of org.odk.collect.android.formentry.saving.FormSaveViewModel in project collect by opendatakit.
the class FormEntryMenuDelegateTest method setup.
@Before
public void setup() {
activity = RobolectricHelpers.createThemedActivity(AppCompatActivity.class, R.style.Theme_MaterialComponents);
FormController formController = mock(FormController.class);
answersProvider = mock(AnswersProvider.class);
formSaveViewModel = mock(FormSaveViewModel.class);
audioRecorder = mock(AudioRecorder.class);
when(audioRecorder.isRecording()).thenReturn(false);
formEntryViewModel = mock(FormEntryViewModel.class);
when(formEntryViewModel.hasBackgroundRecording()).thenReturn(new MutableNonNullLiveData<>(false));
BackgroundLocationViewModel backgroundLocationViewModel = mock(BackgroundLocationViewModel.class);
backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(new MutableNonNullLiveData<>(true));
formEntryMenuDelegate = new FormEntryMenuDelegate(activity, answersProvider, mock(FormIndexAnimationHandler.class), formSaveViewModel, formEntryViewModel, audioRecorder, backgroundLocationViewModel, backgroundAudioViewModel, TestSettingsProvider.getSettingsProvider());
formEntryMenuDelegate.formLoaded(formController);
}
use of org.odk.collect.android.formentry.saving.FormSaveViewModel in project collect by opendatakit.
the class FormSaveViewModelTest method deleteAnswerFile_whenAnswerFileHasAlreadyBeenDeleted_onRecreatingViewModel_actuallyDeletesNewFile.
@Test
public void deleteAnswerFile_whenAnswerFileHasAlreadyBeenDeleted_onRecreatingViewModel_actuallyDeletesNewFile() {
viewModel.deleteAnswerFile("index", "blah1");
FormSaveViewModel restoredViewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, null, scheduler, mock(AudioRecorder.class), currentProjectProvider);
restoredViewModel.formLoaded(formController);
restoredViewModel.deleteAnswerFile("index", "blah2");
verify(mediaUtils).deleteMediaFile("blah2");
}
use of org.odk.collect.android.formentry.saving.FormSaveViewModel in project collect by opendatakit.
the class FormSaveViewModelTest method ignoreChanges_whenFormControllerNotSet_doesNothing.
@Test
public void ignoreChanges_whenFormControllerNotSet_doesNothing() {
FormSaveViewModel viewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, null, scheduler, mock(AudioRecorder.class), currentProjectProvider);
// Checks nothing explodes
viewModel.ignoreChanges();
}
use of org.odk.collect.android.formentry.saving.FormSaveViewModel in project collect by opendatakit.
the class FormSaveViewModelTest method setup.
@Before
public void setup() {
// Useful given some methods will execute AsyncTasks
Robolectric.getBackgroundThreadScheduler().pause();
formController = mock(FormController.class);
logger = mock(AuditEventLogger.class);
mediaUtils = mock(MediaUtils.class);
Analytics analytics = mock(Analytics.class);
when(formController.getAuditEventLogger()).thenReturn(logger);
when(logger.isChangeReasonRequired()).thenReturn(false);
audioRecorder = mock(AudioRecorder.class);
currentProjectProvider = mock(CurrentProjectProvider.class);
when(currentProjectProvider.getCurrentProject()).thenReturn(Project.Companion.getDEMO_PROJECT());
viewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, analytics, scheduler, audioRecorder, currentProjectProvider);
viewModel.formLoaded(formController);
}
use of org.odk.collect.android.formentry.saving.FormSaveViewModel in project collect by opendatakit.
the class FormSaveViewModelTest method replaceAnswerFile_whenAnswerFileHasAlreadyBeenReplaced_afterRecreatingViewModel_deletesPreviousReplacement.
@Test
public void replaceAnswerFile_whenAnswerFileHasAlreadyBeenReplaced_afterRecreatingViewModel_deletesPreviousReplacement() {
viewModel.replaceAnswerFile("index", "blah1");
FormSaveViewModel restoredViewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, null, scheduler, mock(AudioRecorder.class), currentProjectProvider);
restoredViewModel.formLoaded(formController);
restoredViewModel.replaceAnswerFile("index", "blah2");
verify(mediaUtils).deleteMediaFile("blah1");
}
Aggregations