Search in sources :

Example 1 with FormSaveViewModel

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);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) BackgroundLocationViewModel(org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) AnswersProvider(org.odk.collect.android.formentry.questions.AnswersProvider) Before(org.junit.Before)

Example 2 with FormSaveViewModel

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");
}
Also used : FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Test(org.junit.Test)

Example 3 with FormSaveViewModel

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();
}
Also used : FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Test(org.junit.Test)

Example 4 with FormSaveViewModel

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);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) CurrentProjectProvider(org.odk.collect.android.projects.CurrentProjectProvider) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Analytics(org.odk.collect.analytics.Analytics) Before(org.junit.Before)

Example 5 with FormSaveViewModel

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");
}
Also used : FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Test(org.junit.Test)

Aggregations

FormSaveViewModel (org.odk.collect.android.formentry.saving.FormSaveViewModel)7 AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)6 Test (org.junit.Test)3 BackgroundLocationViewModel (org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel)3 FormController (org.odk.collect.android.javarosawrapper.FormController)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 Analytics (org.odk.collect.analytics.Analytics)2 AMRAppender (org.odk.collect.android.audio.AMRAppender)2 M4AAppender (org.odk.collect.android.audio.M4AAppender)2 BackgroundAudioViewModel (org.odk.collect.android.formentry.BackgroundAudioViewModel)2 FormEntryViewModel (org.odk.collect.android.formentry.FormEntryViewModel)2 RecordingHandler (org.odk.collect.android.formentry.RecordingHandler)2 IdentityPromptViewModel (org.odk.collect.android.formentry.audit.IdentityPromptViewModel)2 CurrentProjectProvider (org.odk.collect.android.projects.CurrentProjectProvider)2 ExternalAppRecordingRequester (org.odk.collect.android.widgets.utilities.ExternalAppRecordingRequester)2 FormControllerWaitingForDataRegistry (org.odk.collect.android.widgets.utilities.FormControllerWaitingForDataRegistry)2 InternalRecordingRequester (org.odk.collect.android.widgets.utilities.InternalRecordingRequester)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1