Search in sources :

Example 6 with DatePickerDetails

use of org.odk.collect.android.logic.DatePickerDetails 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)

Example 7 with DatePickerDetails

use of org.odk.collect.android.logic.DatePickerDetails in project collect by opendatakit.

the class DateTimeWidgetTest method whenPromptHasAnswer_answerTextViewShowsCorrectDateAndTime.

@Test
public void whenPromptHasAnswer_answerTextViewShowsCorrectDateAndTime() {
    FormEntryPrompt prompt = promptWithQuestionDefAndAnswer(questionDef, new DateTimeData(localDateTime.toDate()));
    DatePickerDetails datePickerDetails = DateTimeWidgetUtils.getDatePickerDetails(prompt.getQuestion().getAppearanceAttr());
    DateTimeWidget widget = createWidget(prompt);
    assertEquals(widget.binding.dateWidget.dateAnswerText.getText(), DateTimeWidgetUtils.getDateTimeLabel(localDateTime.toDate(), datePickerDetails, false, widget.getContext()));
    assertEquals(widget.binding.timeWidget.timeAnswerText.getText(), DateTimeUtils.getTimeData(localDateTime.toDateTime()).getDisplayText());
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DateTimeData(org.javarosa.core.model.data.DateTimeData) DatePickerDetails(org.odk.collect.android.logic.DatePickerDetails) Test(org.junit.Test)

Example 8 with DatePickerDetails

use of org.odk.collect.android.logic.DatePickerDetails in project collect by opendatakit.

the class DateTimeWidgetUtilsTest method setUp.

@Before
public void setUp() {
    dateTimeWidgetUtils = new DateTimeWidgetUtils();
    activity = RobolectricHelpers.createThemedActivity(WidgetTestActivity.class, R.style.Theme_MaterialComponents);
    datePickerDetails = mock(DatePickerDetails.class);
    when(datePickerDetails.getDatePickerType()).thenReturn(GREGORIAN);
    date = new LocalDateTime().withYear(2010).withMonthOfYear(5).withDayOfMonth(12);
    gregorian = new DatePickerDetails(DatePickerDetails.DatePickerType.GREGORIAN, DatePickerDetails.DatePickerMode.CALENDAR);
    gregorianSpinners = new DatePickerDetails(DatePickerDetails.DatePickerType.GREGORIAN, DatePickerDetails.DatePickerMode.SPINNERS);
    gregorianMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.GREGORIAN, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    gregorianYear = new DatePickerDetails(DatePickerDetails.DatePickerType.GREGORIAN, DatePickerDetails.DatePickerMode.YEAR);
    ethiopian = new DatePickerDetails(DatePickerDetails.DatePickerType.ETHIOPIAN, DatePickerDetails.DatePickerMode.SPINNERS);
    ethiopianMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.ETHIOPIAN, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    ethiopianYear = new DatePickerDetails(DatePickerDetails.DatePickerType.ETHIOPIAN, DatePickerDetails.DatePickerMode.YEAR);
    coptic = new DatePickerDetails(DatePickerDetails.DatePickerType.COPTIC, DatePickerDetails.DatePickerMode.SPINNERS);
    copticMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.COPTIC, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    copticYear = new DatePickerDetails(DatePickerDetails.DatePickerType.COPTIC, DatePickerDetails.DatePickerMode.YEAR);
    islamic = new DatePickerDetails(DatePickerDetails.DatePickerType.ISLAMIC, DatePickerDetails.DatePickerMode.SPINNERS);
    islamicMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.ISLAMIC, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    islamicYear = new DatePickerDetails(DatePickerDetails.DatePickerType.ISLAMIC, DatePickerDetails.DatePickerMode.YEAR);
    bikramSambat = new DatePickerDetails(DatePickerDetails.DatePickerType.BIKRAM_SAMBAT, DatePickerDetails.DatePickerMode.SPINNERS);
    bikramSambatMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.BIKRAM_SAMBAT, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    bikramSambatYear = new DatePickerDetails(DatePickerDetails.DatePickerType.BIKRAM_SAMBAT, DatePickerDetails.DatePickerMode.YEAR);
    myanmar = new DatePickerDetails(DatePickerDetails.DatePickerType.MYANMAR, DatePickerDetails.DatePickerMode.SPINNERS);
    myanmarMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.MYANMAR, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    myanmarYear = new DatePickerDetails(DatePickerDetails.DatePickerType.MYANMAR, DatePickerDetails.DatePickerMode.YEAR);
    persian = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.SPINNERS);
    persianMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.MONTH_YEAR);
    persianYear = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.YEAR);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) WidgetTestActivity(org.odk.collect.android.support.WidgetTestActivity) DatePickerDetails(org.odk.collect.android.logic.DatePickerDetails) Before(org.junit.Before)

Aggregations

DatePickerDetails (org.odk.collect.android.logic.DatePickerDetails)8 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)4 Test (org.junit.Test)4 Before (org.junit.Before)3 LocalDateTime (org.joda.time.LocalDateTime)2 DateData (org.javarosa.core.model.data.DateData)1 DateTimeData (org.javarosa.core.model.data.DateTimeData)1 WidgetTestActivity (org.odk.collect.android.support.WidgetTestActivity)1