Search in sources :

Example 46 with MockFormEntryPromptBuilder

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

the class ImageWidgetTest 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();
    ImageWidget 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 47 with MockFormEntryPromptBuilder

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

the class ImageWidgetTest method whenPromptHasDefaultAnswer_doesNotShow.

@Test
public void whenPromptHasDefaultAnswer_doesNotShow() throws Exception {
    String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath();
    ReferenceManager referenceManager = setupFakeReferenceManager(singletonList(new Pair<>(DrawWidgetTest.DEFAULT_IMAGE_ANSWER, imagePath)));
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(DrawWidgetTest.DEFAULT_IMAGE_ANSWER).build();
    ImageWidget widget = createWidget();
    ImageView imageView = widget.getImageView();
    assertThat(imageView, nullValue());
}
Also used : SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) RandomString(net.bytebuddy.utility.RandomString) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) ImageView(android.widget.ImageView) ImageLoader(org.odk.collect.imageloader.ImageLoader) SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager) Pair(androidx.core.util.Pair) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 48 with MockFormEntryPromptBuilder

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

the class RankingWidgetTest method whenSpacesInUnderlyingValuesExist_shouldAppropriateWarningBeDisplayed.

@Test
public void whenSpacesInUnderlyingValuesExist_shouldAppropriateWarningBeDisplayed() {
    formEntryPrompt = new MockFormEntryPromptBuilder().withSelectChoices(asList(new SelectChoice("a", "a a"), new SelectChoice("a", "b b"))).build();
    TextView warningTv = getWidget().findViewById(R.id.warning_text);
    assertThat(warningTv.getVisibility(), is(View.VISIBLE));
    assertThat(warningTv.getText(), is("Warning: underlying values a a, b b have spaces"));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) TextView(android.widget.TextView) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test) SelectWidgetTest(org.odk.collect.android.widgets.base.SelectWidgetTest)

Example 49 with MockFormEntryPromptBuilder

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

the class WidgetFactoryTest method testCreatingSelectMultipleListNoLabelWidget.

@Test
public void testCreatingSelectMultipleListNoLabelWidget() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_MULTI).withAppearance("something LisT-nOLabeL something").build();
    QuestionWidget widget = widgetFactory.createWidgetFromPrompt(prompt, null);
    assertThat(widget, instanceOf(ListMultiWidget.class));
    assertThat(((ListMultiWidget) widget).shouldDisplayLabel(), is(false));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) ListMultiWidget(org.odk.collect.android.widgets.items.ListMultiWidget) Test(org.junit.Test)

Example 50 with MockFormEntryPromptBuilder

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

the class WidgetFactoryTest method testCreatingSelectMultipleWidget.

@Test
public void testCreatingSelectMultipleWidget() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_MULTI).withAppearance("").build();
    QuestionWidget widget = widgetFactory.createWidgetFromPrompt(prompt, null);
    assertThat(widget, instanceOf(SelectMultiWidget.class));
    prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_MULTI).withAppearance("lorem ipsum").build();
    widget = widgetFactory.createWidgetFromPrompt(prompt, null);
    assertThat(widget, instanceOf(SelectMultiWidget.class));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) SelectMultiWidget(org.odk.collect.android.widgets.items.SelectMultiWidget) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) 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