|
| 1 | +package com.codename1.ui.spinner; |
| 2 | + |
| 3 | +import com.codename1.junit.FormTest; |
| 4 | +import com.codename1.junit.UITestBase; |
| 5 | +import com.codename1.testing.TestCodenameOneImplementation; |
| 6 | +import com.codename1.ui.Display; |
| 7 | +import com.codename1.ui.Form; |
| 8 | +import com.codename1.ui.Dialog; |
| 9 | +import com.codename1.ui.layouts.BoxLayout; |
| 10 | + |
| 11 | +import java.util.Calendar; |
| 12 | +import java.util.Date; |
| 13 | +import java.util.TimeZone; |
| 14 | + |
| 15 | +import static org.junit.jupiter.api.Assertions.*; |
| 16 | + |
| 17 | +class PickerDateTimeTest extends UITestBase { |
| 18 | + |
| 19 | + @FormTest |
| 20 | + void pickerRetainsDateAndTimeAfterProgrammaticSelection() { |
| 21 | + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 22 | + calendar.set(Calendar.YEAR, 2020); |
| 23 | + calendar.set(Calendar.MONTH, Calendar.APRIL); |
| 24 | + calendar.set(Calendar.DAY_OF_MONTH, 3); |
| 25 | + calendar.set(Calendar.HOUR_OF_DAY, 22); |
| 26 | + calendar.set(Calendar.MINUTE, 30); |
| 27 | + calendar.set(Calendar.SECOND, 0); |
| 28 | + calendar.set(Calendar.MILLISECOND, 0); |
| 29 | + Date target = calendar.getTime(); |
| 30 | + |
| 31 | + Picker picker = new Picker(); |
| 32 | + picker.setType(Display.PICKER_TYPE_DATE_AND_TIME); |
| 33 | + picker.setUseLightweightPopup(true); |
| 34 | + picker.setDate(target); |
| 35 | + |
| 36 | + Form form = new Form(BoxLayout.y()); |
| 37 | + form.add(picker); |
| 38 | + form.show(); |
| 39 | + |
| 40 | + TestCodenameOneImplementation impl = TestCodenameOneImplementation.getInstance(); |
| 41 | + impl.tapComponent(picker); |
| 42 | + |
| 43 | + if (Display.getInstance().getCurrent() instanceof Dialog) { |
| 44 | + ((Dialog) Display.getInstance().getCurrent()).dispose(); |
| 45 | + } |
| 46 | + |
| 47 | + Date chosen = picker.getDate(); |
| 48 | + assertNotNull(chosen, "Picker should expose a selected date"); |
| 49 | + |
| 50 | + Calendar picked = Calendar.getInstance(TimeZone.getTimeZone("UTC")); |
| 51 | + picked.setTime(chosen); |
| 52 | + |
| 53 | + assertEquals(calendar.get(Calendar.YEAR), picked.get(Calendar.YEAR)); |
| 54 | + assertEquals(calendar.get(Calendar.MONTH), picked.get(Calendar.MONTH)); |
| 55 | + assertEquals(calendar.get(Calendar.DAY_OF_MONTH), picked.get(Calendar.DAY_OF_MONTH)); |
| 56 | + assertEquals(calendar.get(Calendar.HOUR_OF_DAY), picked.get(Calendar.HOUR_OF_DAY)); |
| 57 | + assertEquals(calendar.get(Calendar.MINUTE), picked.get(Calendar.MINUTE)); |
| 58 | + } |
| 59 | +} |
0 commit comments