Search in sources :

Example 1 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method decimalValueShouldNotAddPrecision.

@Test
public // that precision. For example, 9.00 becomes 9
void decimalValueShouldNotAddPrecision() {
    Double twoDecimalDouble = 9.99;
    String twoDecimalString = "9.99";
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(twoDecimalDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(twoDecimalString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(twoDecimalString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Example 2 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DaylightSavingTest method prepareDateTimeWidget.

private DateTimeWidget prepareDateTimeWidget(int year, int month, int day, int hour, int minute) {
    QuestionDef questionDefStub = mock(QuestionDef.class);
    FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
    IFormElement iformElementStub = formEntryPromptStub.getFormElement();
    when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
    when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
    when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
    when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
    DateTimeWidget dateTimeWidget = new DateTimeWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
    dateTimeWidget.setData(new LocalDateTime().withDate(year, month, day));
    dateTimeWidget.setData(new DateTime().withTime(hour, minute, 0, 0));
    return dateTimeWidget;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) DateTimeWidget(org.odk.collect.android.widgets.DateTimeWidget) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) QuestionDef(org.javarosa.core.model.QuestionDef) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 3 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DaylightSavingTest method prepareDateWidget.

private DateWidget prepareDateWidget(int year, int month, int day) {
    QuestionDef questionDefStub = mock(QuestionDef.class);
    FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
    IFormElement iformElementStub = formEntryPromptStub.getFormElement();
    when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
    when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
    when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
    when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
    DatePickerDialog datePickerDialog = mock(DatePickerDialog.class);
    DatePicker datePicker = mock(DatePicker.class);
    when(datePickerDialog.getDatePicker()).thenReturn(datePicker);
    when(datePickerDialog.getDatePicker().getYear()).thenReturn(year);
    when(datePickerDialog.getDatePicker().getMonth()).thenReturn(month);
    when(datePickerDialog.getDatePicker().getDayOfMonth()).thenReturn(day);
    return new DateWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DatePickerDialog(android.app.DatePickerDialog) DateWidget(org.odk.collect.android.widgets.DateWidget) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) DatePicker(android.widget.DatePicker) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 4 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method digitsAboveLimitOfFifteenShouldBeTruncatedFromRight.

@Test
public // This should never be possible because the EditText has a limit on it
void digitsAboveLimitOfFifteenShouldBeTruncatedFromRight() {
    Double eighteenDigitDouble = 9999999999999994.;
    String fifteenDigitString = "999999999999994";
    assertSame(15, fifteenDigitString.length());
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(eighteenDigitDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Example 5 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method integerValueShouldDisplayNoDecimalPoint.

@Test
public // Fails when double is turned to string with toString or String.format(Locale.US, "%f", d))
void integerValueShouldDisplayNoDecimalPoint() {
    Double integerDouble = 0.;
    String integerString = "0";
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(integerDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(integerString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(integerString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Aggregations

QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)15 Test (org.junit.Test)9 GeneralStringWidgetTest (org.odk.collect.android.widgets.base.GeneralStringWidgetTest)7 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)3 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)3 NonNull (androidx.annotation.NonNull)2 IFormElement (org.javarosa.core.model.IFormElement)2 QuestionDef (org.javarosa.core.model.QuestionDef)2 DatePickerDialog (android.app.DatePickerDialog)1 DatePicker (android.widget.DatePicker)1 DateTime (org.joda.time.DateTime)1 LocalDateTime (org.joda.time.LocalDateTime)1 AudioButton (org.odk.collect.android.audio.AudioButton)1 StoragePathProvider (org.odk.collect.android.storage.StoragePathProvider)1 WidgetTestActivity (org.odk.collect.android.support.WidgetTestActivity)1 CameraUtils (org.odk.collect.android.utilities.CameraUtils)1 ExternalWebPageHelper (org.odk.collect.android.utilities.ExternalWebPageHelper)1 DateTimeWidget (org.odk.collect.android.widgets.DateTimeWidget)1 DateWidget (org.odk.collect.android.widgets.DateWidget)1 GeneralExStringWidgetTest (org.odk.collect.android.widgets.base.GeneralExStringWidgetTest)1