Search in sources :

Example 76 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_playsAudio.

@Test
public void whenPromptHasAutoplayAudio_playsAudio() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withAudioURI(REFERENCES.get(0).first).withAdditionalAttribute("autoplay", "audio").build();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(true));
    verify(audioHelper).playInOrder(asList(new Clip(prompt.getIndex().toString(), REFERENCES.get(0).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Example 77 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method setData_whenPromptHasDifferentAudioFile_deletesOriginalAnswer.

@Test
public void setData_whenPromptHasDifferentAudioFile_deletesOriginalAnswer() throws Exception {
    File originalFile = questionMediaManager.addAnswerFile(File.createTempFile("blah1", ".mp3"));
    FormEntryPrompt prompt = promptWithAnswer(new StringData(originalFile.getName()));
    when(prompt.getIndex()).thenReturn(formIndex);
    AudioWidget widget = createWidget(prompt);
    File newFile = questionMediaManager.addAnswerFile(File.createTempFile("blah2", ".mp3"));
    widget.setData(newFile);
    assertThat(questionMediaManager.originalFiles.get("questionIndex"), equalTo(originalFile.getAbsolutePath()));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) StringData(org.javarosa.core.model.data.StringData) File(java.io.File) Test(org.junit.Test)

Example 78 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method setData_whenFileExists_replacesOriginalFileWithNewFile.

@Test
public void setData_whenFileExists_replacesOriginalFileWithNewFile() throws Exception {
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah1", ".mp3"));
    FormEntryPrompt prompt = promptWithAnswer(new StringData(answerFile.getName()));
    when(prompt.getIndex()).thenReturn(formIndex);
    AudioWidget widget = createWidget(prompt);
    File newFile = questionMediaManager.addAnswerFile(File.createTempFile("blah2", ".mp3"));
    widget.setData(newFile);
    assertThat(questionMediaManager.recentFiles.get("questionIndex"), equalTo(newFile.getAbsolutePath()));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) StringData(org.javarosa.core.model.data.StringData) File(java.io.File) Test(org.junit.Test)

Example 79 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class DateWidgetTest method clickingButton_callsDisplayDatePickerDialogWithSelectedDate_whenPromptHasAnswer.

@Test
public void clickingButton_callsDisplayDatePickerDialogWithSelectedDate_whenPromptHasAnswer() {
    FormEntryPrompt prompt = promptWithQuestionDefAndAnswer(questionDef, new DateData(dateAnswer.toDate()));
    DateWidget widget = createWidget(prompt);
    widget.binding.dateButton.performClick();
    verify(widgetUtils).showDatePickerDialog(widgetActivity, DateTimeWidgetUtils.getDatePickerDetails(prompt.getQuestion().getAppearanceAttr()), dateAnswer);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DateData(org.javarosa.core.model.data.DateData) Test(org.junit.Test)

Example 80 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class DateWidgetTest method setData_updatesValueDisplayedInAnswerTextView.

@Test
public void setData_updatesValueDisplayedInAnswerTextView() {
    FormEntryPrompt prompt = promptWithQuestionDefAndAnswer(questionDef, null);
    DatePickerDetails datePickerDetails = DateTimeWidgetUtils.getDatePickerDetails(prompt.getQuestion().getAppearanceAttr());
    DateWidget widget = createWidget(prompt);
    widget.setData(dateAnswer);
    assertEquals(widget.binding.dateAnswerText.getText(), DateTimeWidgetUtils.getDateTimeLabel(dateAnswer.toDate(), datePickerDetails, false, widget.getContext()));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DatePickerDetails(org.odk.collect.android.logic.DatePickerDetails) Test(org.junit.Test)

Aggregations

FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)114 Test (org.junit.Test)92 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)45 Clip (org.odk.collect.audioclips.Clip)13 FormIndex (org.javarosa.core.model.FormIndex)10 File (java.io.File)9 SelectChoice (org.javarosa.core.model.SelectChoice)7 StringData (org.javarosa.core.model.data.StringData)7 IFormElement (org.javarosa.core.model.IFormElement)5 QuestionDef (org.javarosa.core.model.QuestionDef)5 FormController (org.odk.collect.android.javarosawrapper.FormController)5 GroupDef (org.javarosa.core.model.GroupDef)4 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)4 DatePickerDetails (org.odk.collect.android.logic.DatePickerDetails)4 ArrayList (java.util.ArrayList)3 DateData (org.javarosa.core.model.data.DateData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 LocalDateTime (org.joda.time.LocalDateTime)3 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)3