Search in sources :

Example 56 with MockFormEntryPromptBuilder

use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.

the class SignatureWidgetTest method whenPromptHasCurrentAnswer_showsInImageView.

@Test
public void whenPromptHasCurrentAnswer_showsInImageView() throws Exception {
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath();
    currentFile = new File(imagePath);
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(DrawWidgetTest.USER_SPECIFIED_IMAGE_ANSWER).build();
    SignatureWidget widget = createWidget();
    ImageView imageView = widget.getImageView();
    assertThat(imageView, notNullValue());
    Drawable drawable = imageView.getDrawable();
    assertThat(drawable, notNullValue());
    String loadedPath = shadowOf(((BitmapDrawable) drawable).getBitmap()).getCreatedFromPath();
    assertThat(loadedPath, equalTo(imagePath));
}
Also used : SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) RandomString(net.bytebuddy.utility.RandomString) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) ImageView(android.widget.ImageView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageLoader(org.odk.collect.imageloader.ImageLoader) SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) File(java.io.File) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 57 with MockFormEntryPromptBuilder

use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.

the class SelectOneWidgetTest method whenQuickAppearanceIsNotUsed_shouldNotAdvanceToNextListenerBeCalledInButtonsMode.

@Test
public void whenQuickAppearanceIsNotUsed_shouldNotAdvanceToNextListenerBeCalledInButtonsMode() {
    formEntryPrompt = new MockFormEntryPromptBuilder().withSelectChoices(asList(new SelectChoice("AAA", "AAA"), new SelectChoice("BBB", "BBB"))).build();
    SelectOneWidget widget = getWidget();
    populateRecyclerView(widget);
    // Select AAA
    clickChoice(widget, 0);
    assertThat(widget.getAnswer().getDisplayText(), is("AAA"));
    verify(listener, times(0)).advance();
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) GeneralSelectOneWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest) Test(org.junit.Test)

Example 58 with MockFormEntryPromptBuilder

use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.

the class SelectOneWidgetTest method usingReadOnlyOptionShouldMakeAllClickableElementsDisabled.

@Test
public void usingReadOnlyOptionShouldMakeAllClickableElementsDisabled() {
    // No appearance
    formEntryPrompt = new MockFormEntryPromptBuilder().withIndex("i am index").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).withReadOnly(true).build();
    populateRecyclerView(getWidget());
    AudioVideoImageTextLabel avitLabel = (AudioVideoImageTextLabel) getSpyWidget().binding.choicesRecyclerView.getLayoutManager().getChildAt(0);
    assertThat(avitLabel.isEnabled(), is(Boolean.FALSE));
    resetWidget();
    // No-buttons appearance
    formEntryPrompt = new MockFormEntryPromptBuilder(formEntryPrompt).withAppearance(Appearances.NO_BUTTONS).build();
    populateRecyclerView(getWidget());
    FrameLayout view = (FrameLayout) getSpyWidget().binding.choicesRecyclerView.getLayoutManager().getChildAt(0);
    assertThat(view.isEnabled(), is(Boolean.FALSE));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) FrameLayout(android.widget.FrameLayout) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) AudioVideoImageTextLabel(org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel) GeneralSelectOneWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest) Test(org.junit.Test)

Example 59 with MockFormEntryPromptBuilder

use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.

the class SelectOneWidgetTest method whenChoicesHaveAudio_audioButtonUsesIndexAsClipID.

@Test
public void whenChoicesHaveAudio_audioButtonUsesIndexAsClipID() throws Exception {
    formEntryPrompt = new MockFormEntryPromptBuilder().withIndex("i am index").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).withSpecialFormSelectChoiceText(asList(new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(0).first), new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(1).first))).build();
    populateRecyclerView(getWidget());
    verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 0", REFERENCES.get(0).second)));
    verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 1", REFERENCES.get(1).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) AudioButton(org.odk.collect.android.audio.AudioButton) Pair(androidx.core.util.Pair) GeneralSelectOneWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest) Test(org.junit.Test)

Example 60 with MockFormEntryPromptBuilder

use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.

the class SelectOneWidgetTest method whenAChoiceValueIsNull_selecting_doesNotSetAnswer.

@Test
public void whenAChoiceValueIsNull_selecting_doesNotSetAnswer() {
    // The two arg constructor protects against null values
    SelectChoice selectChoice = new SelectChoice();
    selectChoice.setTextID("1");
    formEntryPrompt = new MockFormEntryPromptBuilder().withSelectChoices(asList(selectChoice)).build();
    SelectOneWidget widget = getWidget();
    populateRecyclerView(widget);
    clickChoice(widget, 0);
    assertThat(widget.getAnswer(), nullValue());
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) GeneralSelectOneWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest) Test(org.junit.Test)

Aggregations

MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)69 Test (org.junit.Test)65 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)45 SelectChoice (org.javarosa.core.model.SelectChoice)21 Clip (org.odk.collect.audioclips.Clip)12 RandomString (net.bytebuddy.utility.RandomString)9 FileWidgetTest (org.odk.collect.android.widgets.base.FileWidgetTest)9 ImageView (android.widget.ImageView)8 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)8 SynchronousImageLoader (org.odk.collect.android.widgets.support.SynchronousImageLoader)8 ImageLoader (org.odk.collect.imageloader.ImageLoader)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Drawable (android.graphics.drawable.Drawable)7 GeneralSelectOneWidgetTest (org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest)7 Pair (androidx.core.util.Pair)6 TextView (android.widget.TextView)5 GeneralSelectMultiWidgetTest (org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest)5 File (java.io.File)4 ReferenceManager (org.javarosa.core.reference.ReferenceManager)4 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)4