use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.
the class SelectMultiWidgetTest 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());
SelectMultiWidget a = getSpyWidget();
AudioVideoImageTextLabel avitLabel = (AudioVideoImageTextLabel) a.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));
}
use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.
the class AuditEventLoggerTest method setup.
@Before
public void setup() {
FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withAnswerDisplayText("The answer").build();
when(formController.getQuestionPrompt(any())).thenReturn(prompt);
}
use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.
the class FormSaveViewModelTest method whenFormSaverFinishes_saved_andFormIsCurrentlyOnRepeat_logsSaveAndQuestionAuditEventsAfterFlush.
@Test
public void whenFormSaverFinishes_saved_andFormIsCurrentlyOnRepeat_logsSaveAndQuestionAuditEventsAfterFlush() throws RepeatsInFieldListException {
when(formController.getEvent()).thenReturn(EVENT_REPEAT);
FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withIndex("index1").withAnswerDisplayText("answer").build();
when(formController.getQuestionPrompts()).thenReturn(Arrays.asList(prompt).toArray(new FormEntryPrompt[] {}));
viewModel.saveForm(Uri.parse("file://form"), true, "", false);
whenFormSaverFinishes(SaveFormToDisk.SAVED);
InOrder verifier = inOrder(logger);
verifier.verify(logger).flush();
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.FORM_SAVE, false, CURRENT_TIME);
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.QUESTION, prompt.getIndex(), true, prompt.getAnswerValue().getDisplayText(), CURRENT_TIME, null);
}
use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.
the class FormSaveViewModelTest method whenFormSaverFinishes_saved_andFormIsCurrentlyOnGroup_logsSaveAndQuestionAuditEventsAfterFlush.
@Test
public void whenFormSaverFinishes_saved_andFormIsCurrentlyOnGroup_logsSaveAndQuestionAuditEventsAfterFlush() throws RepeatsInFieldListException {
when(formController.getEvent()).thenReturn(EVENT_GROUP);
FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withIndex("index1").withAnswerDisplayText("answer").build();
when(formController.getQuestionPrompts()).thenReturn(Arrays.asList(prompt).toArray(new FormEntryPrompt[] {}));
viewModel.saveForm(Uri.parse("file://form"), true, "", false);
whenFormSaverFinishes(SaveFormToDisk.SAVED);
InOrder verifier = inOrder(logger);
verifier.verify(logger).flush();
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.FORM_SAVE, false, CURRENT_TIME);
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.QUESTION, prompt.getIndex(), true, prompt.getAnswerValue().getDisplayText(), CURRENT_TIME, null);
}
use of org.odk.collect.android.support.MockFormEntryPromptBuilder in project collect by opendatakit.
the class DrawWidgetTest method whenPromptHasDefaultAnswer_showsInImageView.
@Test
public void whenPromptHasDefaultAnswer_showsInImageView() 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(DEFAULT_IMAGE_ANSWER).build();
DrawWidget 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));
}
Aggregations