|
| 1 | +package com.vaadin.flow.component.datetimepicker; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Before; |
| 5 | +import org.junit.Test; |
| 6 | +import org.openqa.selenium.Keys; |
| 7 | + |
| 8 | +import com.vaadin.flow.component.datetimepicker.testbench.DateTimePickerElement; |
| 9 | +import com.vaadin.flow.testutil.TestPath; |
| 10 | +import com.vaadin.testbench.TestBenchElement; |
| 11 | +import com.vaadin.tests.AbstractComponentIT; |
| 12 | + |
| 13 | +import static com.vaadin.flow.component.datetimepicker.ClearValuePage.CLEAR_BUTTON; |
| 14 | + |
| 15 | +@TestPath("vaadin-date-time-picker/clear-value") |
| 16 | +public class ClearValueIT extends AbstractComponentIT { |
| 17 | + private DateTimePickerElement dateTimePicker; |
| 18 | + private TestBenchElement dateInput; |
| 19 | + private TestBenchElement timeInput; |
| 20 | + |
| 21 | + @Before |
| 22 | + public void init() { |
| 23 | + open(); |
| 24 | + dateTimePicker = $(DateTimePickerElement.class).first(); |
| 25 | + dateInput = dateTimePicker.$("input").first(); |
| 26 | + timeInput = dateTimePicker.$("input").last(); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void setDateInputValue_clearValue_inputValueIsEmpty() { |
| 31 | + dateInput.sendKeys("1/1/2022", Keys.ENTER); |
| 32 | + Assert.assertEquals("1/1/2022", dateInput.getPropertyString("value")); |
| 33 | + |
| 34 | + $("button").id(CLEAR_BUTTON).click(); |
| 35 | + Assert.assertEquals("", dateInput.getPropertyString("value")); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void setTimeInputValue_clearValue_inputValueIsEmpty() { |
| 40 | + timeInput.sendKeys("12:00 PM", Keys.ENTER); |
| 41 | + Assert.assertEquals("12:00 PM", timeInput.getPropertyString("value")); |
| 42 | + |
| 43 | + $("button").id(CLEAR_BUTTON).click(); |
| 44 | + Assert.assertEquals("", timeInput.getPropertyString("value")); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void setDateAndTimeInputValue_clearValue_inputValueIsEmpty() { |
| 49 | + dateInput.sendKeys("1/1/2022", Keys.ENTER); |
| 50 | + timeInput.sendKeys("12:00 PM", Keys.ENTER); |
| 51 | + Assert.assertEquals("1/1/2022", dateInput.getPropertyString("value")); |
| 52 | + Assert.assertEquals("12:00 PM", timeInput.getPropertyString("value")); |
| 53 | + |
| 54 | + $("button").id(CLEAR_BUTTON).click(); |
| 55 | + Assert.assertEquals("", dateInput.getPropertyString("value")); |
| 56 | + Assert.assertEquals("", timeInput.getPropertyString("value")); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void badInput_setDateInputValue_clearValue_inputValueIsEmpty() { |
| 61 | + dateInput.sendKeys("INVALID", Keys.ENTER); |
| 62 | + Assert.assertEquals("INVALID", dateInput.getPropertyString("value")); |
| 63 | + |
| 64 | + $("button").id(CLEAR_BUTTON).click(); |
| 65 | + Assert.assertEquals("", dateInput.getPropertyString("value")); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void badInput_setTimeInputValue_clearValue_inputValueIsEmpty() { |
| 70 | + timeInput.sendKeys("INVALID", Keys.ENTER); |
| 71 | + Assert.assertEquals("INVALID", timeInput.getPropertyString("value")); |
| 72 | + |
| 73 | + $("button").id(CLEAR_BUTTON).click(); |
| 74 | + Assert.assertEquals("", timeInput.getPropertyString("value")); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void badInput_setDateAndTimeInputValue_clearValue_inputValueIsEmpty() { |
| 79 | + dateInput.sendKeys("INVALID", Keys.ENTER); |
| 80 | + timeInput.sendKeys("INVALID", Keys.ENTER); |
| 81 | + Assert.assertEquals("INVALID", dateInput.getPropertyString("value")); |
| 82 | + Assert.assertEquals("INVALID", timeInput.getPropertyString("value")); |
| 83 | + |
| 84 | + $("button").id(CLEAR_BUTTON).click(); |
| 85 | + Assert.assertEquals("", dateInput.getPropertyString("value")); |
| 86 | + Assert.assertEquals("", timeInput.getPropertyString("value")); |
| 87 | + } |
| 88 | +} |
0 commit comments