From 82446b08feaf1c2d0b6e86a287d5c41cae45e92a Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Wed, 22 Nov 2023 16:23:46 +0200 Subject: [PATCH] Added Date(Time)PickerPw and cleanup closes #4 --- src/main/java/in/virit/mopo/ComboBoxPw.java | 10 ++ src/main/java/in/virit/mopo/DatePickerPw.java | 57 +++++++ .../java/in/virit/mopo/DateTimePickerPw.java | 67 ++++++++ src/main/java/in/virit/mopo/GridPw.java | 146 ++++++++++------- src/main/java/in/virit/mopo/Mopo.java | 48 ++++-- src/test/java/firitin/pw/DatePickerIT.java | 150 ++++++++++++++++++ .../java/firitin/pw/GridPlaywrightIT.java | 32 ++-- src/test/java/firitin/ui/DateView.java | 50 ++++++ 8 files changed, 478 insertions(+), 82 deletions(-) create mode 100644 src/main/java/in/virit/mopo/DatePickerPw.java create mode 100644 src/main/java/in/virit/mopo/DateTimePickerPw.java create mode 100644 src/test/java/firitin/pw/DatePickerIT.java create mode 100644 src/test/java/firitin/ui/DateView.java diff --git a/src/main/java/in/virit/mopo/ComboBoxPw.java b/src/main/java/in/virit/mopo/ComboBoxPw.java index 72078f5..a132d50 100644 --- a/src/main/java/in/virit/mopo/ComboBoxPw.java +++ b/src/main/java/in/virit/mopo/ComboBoxPw.java @@ -4,6 +4,9 @@ import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; +/** + * Helper class to work with vaadin-combo-box component + */ public class ComboBoxPw { private final Locator root; @@ -28,7 +31,14 @@ public void filterAndSelectFirst(String filter) { root.locator("input").press("Enter"); } + /** + * Fills given filter to the combobox. + * + * @param filter the filter string to be set + * @return the {@link ComboBoxPw} (for fluent API) + */ public ComboBoxPw filter(String filter) { + root.locator("input").clear(); root.locator("input").fill(filter); return this; } diff --git a/src/main/java/in/virit/mopo/DatePickerPw.java b/src/main/java/in/virit/mopo/DatePickerPw.java new file mode 100644 index 0000000..15152ba --- /dev/null +++ b/src/main/java/in/virit/mopo/DatePickerPw.java @@ -0,0 +1,57 @@ +package in.virit.mopo; + +import com.microsoft.playwright.Locator; + +import java.time.LocalDate; + +/** + * A helper class to work with vaadin-date-picker component. + */ +public class DatePickerPw { + + private final Locator root; + + /** + * Creates a DatePicker page object for the given locator. + * + * @param gridLocator the Playwright locator for the vaadin-date-picker to + * be interacted with + */ + public DatePickerPw(Locator gridLocator) { + this.root = gridLocator; + } + + /** + * Returns the value from the client side and parses it as + * {@link LocalDate}. + * + * @return the current value of the field + */ + public LocalDate getValue() { + String str = (String) root.evaluate("db => db.value"); + try { + return LocalDate.parse(str); + } catch (java.time.format.DateTimeParseException e) { + return null; + } + } + + /** + * Sets the value of the field. + * + * @param value the value to be set + */ + public void setValue(LocalDate value) { + root.evaluate("db => db.value = '%s'".formatted(value)); + } + + /** + * Returns the raw string value in the field. + * + * @return the string value as it is formatted in the field. Note, this may + * be locale dependent. + */ + public String getInputString() { + return root.locator("input").inputValue(); + } +} diff --git a/src/main/java/in/virit/mopo/DateTimePickerPw.java b/src/main/java/in/virit/mopo/DateTimePickerPw.java new file mode 100644 index 0000000..8b72122 --- /dev/null +++ b/src/main/java/in/virit/mopo/DateTimePickerPw.java @@ -0,0 +1,67 @@ +package in.virit.mopo; + +import com.microsoft.playwright.Locator; + +import java.time.LocalDateTime; + +/** + * A helper class to work with vaadin-date-time-picker + */ +public class DateTimePickerPw { + + private final Locator root; + + /** + * Creates a DateTimePicker page object for the given locator. + * + * @param gridLocator the Playwright locator for the vaadin-date-time-picker + * to be interacted with + */ + public DateTimePickerPw(Locator gridLocator) { + this.root = gridLocator; + } + + /** + * Sets the current value of this field + * + * @param value the value to be set + */ + public void setValue(LocalDateTime value) { + root.evaluate("db => db.value = '%s'".formatted(value)); + } + + /** + * Gets the currently set value of the field and parses it as + * {@link LocalDateTime}. + * + * @return the current value of the field + */ + public LocalDateTime getValue() { + String str = (String) root.evaluate("db => db.value"); + try { + return LocalDateTime.parse(str); + } catch (java.time.format.DateTimeParseException e) { + return null; + } + } + + /** + * Gets the string currently in the input field defining the date part. + * + * @return the string value as it is formatted in the field. Note, this may + * be locale dependent. + */ + public String getDateInputString() { + return root.locator("vaadin-date-picker input").inputValue(); + } + + /** + * Returns the string currently in the input defining the time part + * + * @return the string value as it is formatted in the field. Note, this may + * be locale dependent. + */ + public String getTimeInputString() { + return root.locator("vaadin-time-picker input").inputValue(); + } +} diff --git a/src/main/java/in/virit/mopo/GridPw.java b/src/main/java/in/virit/mopo/GridPw.java index cf00daa..b6f58e4 100644 --- a/src/main/java/in/virit/mopo/GridPw.java +++ b/src/main/java/in/virit/mopo/GridPw.java @@ -3,54 +3,16 @@ import com.microsoft.playwright.Locator; import com.microsoft.playwright.Page; +/** + * A helper class to work with the vaadin-grid component. + */ public class GridPw { - public class RowPw { - private final int rowIndex; - - private RowPw(int rowIndex) { - this.rowIndex = rowIndex; - } - - /** - * Gets the cell locator at the given index. - * - * @param cellIndex the cell index (0-based, unlike the CSS nth-child selector, whose designer should be hung by the balls, in case they have any) - * @return the cell locator - */ - public Locator getCell(int cellIndex) { - int indexInVirtualTable = (Integer) root.evaluate("g => g._getRenderedRows().indexOf(g._getRenderedRows().filter(r => r.index == %s)[0]);".formatted(rowIndex)); - indexInVirtualTable += 1; // 1-based :-) - String name = root.locator("#items tr:nth-child(%s) td:nth-child(%s) slot".formatted(indexInVirtualTable, cellIndex+1)) - .getAttribute("name"); - return root.locator("vaadin-grid-cell-content[slot='%s']".formatted(name)); - } - - /** - * Gets the cell with the given header text. - * @param headerText the header text - * @return the cell locator - */ - public Locator getCell(String headerText) { - // this depends heavily on Grid's internal implementation - // Grid developers probably have a better way to do this - String slot = root.locator("vaadin-grid-cell-content") - .filter(new Locator.FilterOptions().setHasText(headerText)) - .getAttribute("slot"); - String substring = slot.substring(slot.lastIndexOf("-") + 1); - int cellIndex = Integer.parseInt(substring); - return getCell(cellIndex); - } - - public void select() { - GridPw.this.selectRow(rowIndex); - } - } - private final Locator root; /** * Creates a Grid page object for the given grid locator. + * * @param gridLocator the Playwright locator for the grid */ public GridPw(Locator gridLocator) { @@ -59,6 +21,7 @@ public GridPw(Locator gridLocator) { /** * Creates a Grid page object for the first grid on the page. + * * @param page the Playwright page */ public GridPw(Page page) { @@ -75,6 +38,11 @@ public int getRenderedRowCount() { return evaluate; } + /** + * Returns the index of the first visible row + * + * @return the index. + */ public int getFirstVisibleRowIndex() { return (Integer) root.elementHandle().evaluate("e => e._firstVisibleIndex"); } @@ -131,7 +99,7 @@ public void scrollToIndex(int index) { }, 100); }); }"""); - // System.out.println("RETURN value = " + value); + // System.out.println("RETURN value = " + value); } /** @@ -141,20 +109,27 @@ public void scrollToIndex(int index) { */ public void selectRow(int rowIndex) { String script = """ - grid => { - var firstRowIndex = %s; - var lastRowIndex = firstRowIndex; - var rowsInDom = grid._getRenderedRows(); - var rows = Array.from(rowsInDom).filter((row) => { return row.index >= firstRowIndex && row.index <= lastRowIndex;}); - var row = rows[0]; - grid.activeItem = row._item; - } - """.formatted(rowIndex); + grid => { + var firstRowIndex = %s; + var lastRowIndex = firstRowIndex; + var rowsInDom = grid._getRenderedRows(); + var rows = Array.from(rowsInDom).filter((row) => { return row.index >= firstRowIndex && row.index <= lastRowIndex;}); + var row = rows[0]; + grid.activeItem = row._item; + } + """.formatted(rowIndex); root.elementHandle().evaluate(script); } - public RowPw getTableRow(int rowIndex) { - if(!isRowInView(rowIndex)) { + /** + * Returns a RowPw helper representing the row defined by the given index. + * + * @param rowIndex the row index + * @return the RowPw for editing the UI state or to get cell locators for + * assertions. + */ + public RowPw getRow(int rowIndex) { + if (!isRowInView(rowIndex)) { scrollToIndex(rowIndex); } return new RowPw(rowIndex); @@ -163,19 +138,76 @@ public RowPw getTableRow(int rowIndex) { /** * Checks if the given row is in the visible viewport. * - * @param rowIndex - * the row to check + * @param rowIndex the row to check * @return true if the row is at least partially in view, - * false otherwise + * false otherwise */ public boolean isRowInView(int rowIndex) { return (getFirstVisibleRowIndex() <= rowIndex && rowIndex <= getLastVisibleRowIndex()); } + /** + * Returns the index of last visible row. + * + * @return the index + */ public int getLastVisibleRowIndex() { return (Integer) root.elementHandle().evaluate("e => e._lastVisibleIndex"); } + /** + * Represents a row in the vaadin-grid component. Not that there is no DOM + * element backing this row, but this is purely virtual helper class based + * on row index. + */ + public class RowPw { + + private final int rowIndex; + + private RowPw(int rowIndex) { + this.rowIndex = rowIndex; + } + + /** + * Gets the cell locator at the given index. + * + * @param cellIndex the cell index (0-based, unlike the CSS nth-child + * selector, whose designer should be hung by the balls, in case they + * have any) + * @return the cell locator + */ + public Locator getCell(int cellIndex) { + int indexInVirtualTable = (Integer) root.evaluate("g => g._getRenderedRows().indexOf(g._getRenderedRows().filter(r => r.index == %s)[0]);".formatted(rowIndex)); + indexInVirtualTable += 1; // 1-based :-) + String name = root.locator("#items tr:nth-child(%s) td:nth-child(%s) slot".formatted(indexInVirtualTable, cellIndex + 1)) + .getAttribute("name"); + return root.locator("vaadin-grid-cell-content[slot='%s']".formatted(name)); + } + + /** + * Gets the cell with the given header text. + * + * @param headerText the header text + * @return the cell locator + */ + public Locator getCell(String headerText) { + // this depends heavily on Grid's internal implementation + // Grid developers probably have a better way to do this + String slot = root.locator("vaadin-grid-cell-content") + .filter(new Locator.FilterOptions().setHasText(headerText)) + .getAttribute("slot"); + String substring = slot.substring(slot.lastIndexOf("-") + 1); + int cellIndex = Integer.parseInt(substring); + return getCell(cellIndex); + } + + /** + * Selects the given row. + */ + public void select() { + GridPw.this.selectRow(rowIndex); + } + } } diff --git a/src/main/java/in/virit/mopo/Mopo.java b/src/main/java/in/virit/mopo/Mopo.java index 49834ca..476b7c9 100644 --- a/src/main/java/in/virit/mopo/Mopo.java +++ b/src/main/java/in/virit/mopo/Mopo.java @@ -11,22 +11,38 @@ import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; /** - * General utilities for Playwright & Vaadin. + * General utilities for Playwright and Vaadin. */ public class Mopo { private final Page page; + /** + * Constructs a new Mopo for given page + * + * @param page the page use by this Mopo instance + */ public Mopo(Page page) { this.page = page; } + /** + * Waits until the client-server communication by Vaadin has settled. + * + * @param page the page on which Vaadin app is expected to be run + */ public static void waitForConnectionToSettle(Page page) { // Default to be bit larger than the defaults for lazy value change events int minWait = 500; waitForConnectionToSettle(page, minWait); } + /** + * Waits until the client-server communication by Vaadin has settled. + * + * @param page the page on which Vaadin app is expected to be run + * @param minWait the minimum wait time spent to watch if client-server communication starts + */ public static void waitForConnectionToSettle(Page page, int minWait) { long start = System.currentTimeMillis(); @@ -42,6 +58,8 @@ public static void waitForConnectionToSettle(Page page, int minWait) { /** * Asserts that there are no JS errors in the dev console. + * + * @param page the page to be checked */ public static void assertNoJsErrors(Page page) { @@ -60,6 +78,10 @@ public static void assertNoJsErrors(Page page) { } } + /** + * Waits until the client-server communication by Vaadin + * has settled. + */ public void waitForConnectionToSettle() { waitForConnectionToSettle(page); } @@ -71,6 +93,13 @@ public void assertNoJsErrors() { assertNoJsErrors(page); } + /** + * Returns a list of routes/views(URLs) that Vaadin app in development mode contains. + * + * @param browser the browser instance + * @param page a currently open page that is used as a basis for analysis. + * @return a list of URLs pointing to known routes + */ public List getDevelopmentTimeViewNames(Browser browser, Page page) { List urls = new ArrayList<>(); @@ -102,12 +131,13 @@ public List getDevelopmentTimeViewNames(Browser browser, Page page) { /** * Executes given task in a temporarily visible UI part, like a dialog or - * form. The UI part is expected to be detached after the task. + * form. The UI part is expected to be detached after the task (implicitly + * asserted). * - * @param locator a locator to the UI part or a part within it (like a - * "Save" button) + * @param selector a selector to the UI part to be accessed or a part within it (like a + * "Save" button) * @param taskToRun the task that should be performed in the temporarily - * visible component (composition) + * visible component (composition) */ public void driveIn(String selector, Runnable taskToRun) { driveIn(page.locator(selector), taskToRun); @@ -117,11 +147,11 @@ public void driveIn(String selector, Runnable taskToRun) { * Executes given task in a temporarily visible UI part, like a dialog or * form. The UI part is expected to be hidden after the task. * - * @param locator a locator to the UI part or a part within it (like a - * "Save" button). This is used to verify that the component is shown before - * the given task is executed and hidden after the execution. + * @param locator a locator to the UI part or a part within it (like a + * "Save" button). This is used to verify that the component is shown before + * the given task is executed and hidden after the execution. * @param taskToRun the task that should be performed in the temporarily - * visible component (composition) + * visible component (composition) */ public void driveIn(Locator locator, Runnable taskToRun) { assertThat(locator).isVisible(); diff --git a/src/test/java/firitin/pw/DatePickerIT.java b/src/test/java/firitin/pw/DatePickerIT.java new file mode 100644 index 0000000..3ded84c --- /dev/null +++ b/src/test/java/firitin/pw/DatePickerIT.java @@ -0,0 +1,150 @@ +package firitin.pw; + +import com.microsoft.playwright.Browser; +import com.microsoft.playwright.BrowserType; +import com.microsoft.playwright.Locator; +import com.microsoft.playwright.Page; +import com.microsoft.playwright.Playwright; +import in.virit.mopo.DatePickerPw; +import in.virit.mopo.DateTimePickerPw; +import in.virit.mopo.Mopo; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +@Tag("playwright") +public class DatePickerIT { + private final int port = 9998; + + static Playwright playwright = Playwright.create(); + + static { + } + + private Browser browser; + private Page page; + private Mopo mopo; + + @BeforeEach + public void setup() { + browser = playwright.chromium() + .launch(new BrowserType.LaunchOptions() + .setHeadless(false) +// .setDevtools(true) + ); + + page = browser.newPage(); + page.setDefaultTimeout(5000); // die faster if needed + mopo = new Mopo(page); + } + + @AfterEach + public void closePlaywright() { + page.close(); + browser.close(); + } + + @Test + public void doStuffWithDatePickerPw() { + + page.navigate("http://localhost:" + port + "/date"); + + LocalDate localDate = LocalDate.of(2001,12,24); + + DatePickerPw datePickerPw = new DatePickerPw(page.locator("#dp")); + + LocalDate value = datePickerPw.getValue(); + assertNull(value); + + datePickerPw.setValue(localDate); + + value = datePickerPw.getValue(); + + assertEquals(localDate, value); + + assertThat(page.locator("#dpValue")).containsText(localDate.toString()); + + LocalDate now = LocalDate.now(); + mopo.click(page.getByText("set now")); + value = datePickerPw.getValue(); + String valueInField = datePickerPw.getInputString(); + + String formattedNow = DateTimeFormatter.ofPattern("dd.MM.yyyy").format(now); + + assertEquals(formattedNow, valueInField); + assertThat(page.locator("#dpValue")).containsText(now.toString()); + + // and the same with time... + + DateTimePickerPw dateTimePickerPw = new DateTimePickerPw(page.locator("#dtp")); + + LocalDateTime localDateTime = LocalDateTime.of(2001,12,24,22,36,0,0); + dateTimePickerPw.setValue(localDateTime); + assertThat(page.locator("#dtpValue")).containsText(localDateTime.toString()); + + String dateInputValue = dateTimePickerPw.getDateInputString(); + String timeInputValue = dateTimePickerPw.getTimeInputString(); + assertEquals("24.12.2001", dateInputValue); + assertEquals("22.36.00", timeInputValue); + + System.out.println("Success!!"); + + } + + @Test + public void doStuffWithRawApi() { + // Finnish formatting set in the UI + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH.mm"); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm"); + + page.navigate("http://localhost:" + port + "/date"); + + LocalDate localDate = LocalDate.of(2001,12,24); + + String formatted = localDate.format(dateFormatter); + + Locator dateInput = page.locator("#dp input"); + + dateInput.fill(formatted); + dateInput.press("Enter"); + + assertThat(page.locator("#dpValue")).containsText(localDate.toString()); + + LocalDate now = LocalDate.now(); + mopo.click(page.getByText("set now")); + String valueInField = dateInput.inputValue(); + String formattedNow = dateFormatter.format(now); + + assertEquals(formattedNow, valueInField); + assertThat(page.locator("#dpValue")).containsText(now.toString()); + + + // and the same with time... + + LocalDateTime localDateTime = LocalDateTime.of(2001,12,24,22,36,0,0); + String formattedDateTime = localDateTime.format(dateTimeFormatter); + + Locator dtpDateInput = page.locator("#dtp vaadin-date-picker input"); + Locator dtpTimeInput = page.locator("#dtp vaadin-time-picker input"); + dtpTimeInput.clear(); + dtpTimeInput.fill(timeFormatter.format(localDateTime)); + dtpDateInput.clear(); + dtpDateInput.fill(dateFormatter.format(localDateTime)); + dtpDateInput.press("Enter"); + + assertThat(page.locator("#dtpValue")).containsText(localDateTime.toString()); + + System.out.println("Success!!"); + } + +} diff --git a/src/test/java/firitin/pw/GridPlaywrightIT.java b/src/test/java/firitin/pw/GridPlaywrightIT.java index f02623e..1205255 100644 --- a/src/test/java/firitin/pw/GridPlaywrightIT.java +++ b/src/test/java/firitin/pw/GridPlaywrightIT.java @@ -53,7 +53,7 @@ public void doRandomStuffAndChangeFirstRow() throws InterruptedException { page.navigate("http://localhost:" + port + "/grid"); GridPw grid = new GridPw(page); - String originalFirstName = grid.getTableRow(0).getCell(0).textContent(); + String originalFirstName = grid.getRow(0).getCell(0).textContent(); // Some warmup with simple GridPo API assertEquals(0, grid.getFirstVisibleRowIndex()); @@ -62,7 +62,7 @@ public void doRandomStuffAndChangeFirstRow() throws InterruptedException { grid.scrollToIndex(0); // Select the first row for editing - grid.getTableRow(0).select(); + grid.getRow(0).select(); // Check the form is visible and contains the first row data assertThat(page.getByLabel("First name", new Page.GetByLabelOptions().setExact(true))) @@ -80,7 +80,7 @@ public void doRandomStuffAndChangeFirstRow() throws InterruptedException { int renderedRowCount = grid.getRenderedRowCount(); assertEquals(1, renderedRowCount); - grid.getTableRow(0).select(); + grid.getRow(0).select(); String newFirstName = originalFirstName+"_changed0"; if(originalFirstName.contains("_changed")) { @@ -99,8 +99,8 @@ public void doRandomStuffAndChangeFirstRow() throws InterruptedException { // Get the first cell of the first row in Grid and check text // TODO add API to get cell by column header text - assertThat(grid.getTableRow(0).getCell(0)).hasText(newFirstName); - assertThat(grid.getTableRow(0).getCell("First Name")).hasText(newFirstName); + assertThat(grid.getRow(0).getCell(0)).hasText(newFirstName); + assertThat(grid.getRow(0).getCell("First Name")).hasText(newFirstName); // An alternative way to verify without GridPo assertThat(page.locator("vaadin-grid-cell-content").and(page.getByText(newFirstName))).isVisible(); @@ -130,23 +130,23 @@ public void scrollingAndAssertingContent() { System.out.println("Showing rows: %s-%s".formatted(grid.getFirstVisibleRowIndex(), grid.getLastVisibleRowIndex())); String cellContent; - cellContent = grid.getTableRow(0).getCell(0).textContent(); + cellContent = grid.getRow(0).getCell(0).textContent(); assertEquals("First0", cellContent); - cellContent = grid.getTableRow(0).getCell("First Name").textContent(); + cellContent = grid.getRow(0).getCell("First Name").textContent(); assertEquals("First0", cellContent); - cellContent = grid.getTableRow(0).getCell(1).textContent(); + cellContent = grid.getRow(0).getCell(1).textContent(); assertEquals("Lastname0", cellContent); - cellContent = grid.getTableRow(0).getCell("Last Name").textContent(); + cellContent = grid.getRow(0).getCell("Last Name").textContent(); assertEquals("Lastname0", cellContent); grid.scrollToIndex(3); System.out.println("Showing rows: %s-%s".formatted(grid.getFirstVisibleRowIndex(), grid.getLastVisibleRowIndex())); - cellContent = grid.getTableRow(0).getCell(0).textContent(); + cellContent = grid.getRow(0).getCell(0).textContent(); assertEquals("First0", cellContent); - cellContent = grid.getTableRow(0).getCell("First Name").textContent(); + cellContent = grid.getRow(0).getCell("First Name").textContent(); assertEquals("First0", cellContent); grid.scrollToIndex(100); @@ -155,12 +155,12 @@ public void scrollingAndAssertingContent() { // this should now automatically scroll row index 0 to be visible - cellContent = grid.getTableRow(0).getCell(0).textContent(); + cellContent = grid.getRow(0).getCell(0).textContent(); assertEquals("First0", cellContent); - cellContent = grid.getTableRow(0).getCell("First Name").textContent(); + cellContent = grid.getRow(0).getCell("First Name").textContent(); assertEquals("First0", cellContent); System.out.println("Showing rows: %s-%s".formatted(grid.getFirstVisibleRowIndex(), grid.getLastVisibleRowIndex())); - cellContent = grid.getTableRow(101).getCell(1).textContent(); + cellContent = grid.getRow(101).getCell(1).textContent(); assertEquals("Lastname101", cellContent); System.out.println("Showing rows: %s-%s".formatted(grid.getFirstVisibleRowIndex(), grid.getLastVisibleRowIndex())); } @@ -181,7 +181,7 @@ public void driveInForSavingTheForm() throws InterruptedException { form.getByText("Save").click(); // Note, implicit checks that contact-form dissappears }); - assertThat(grid.getTableRow(rowToEdit).getCell(0)).hasText(newName); + assertThat(grid.getRow(rowToEdit).getCell(0)).hasText(newName); } @Test @@ -196,7 +196,7 @@ public void mopoClickForSavingTheForm() throws InterruptedException { Locator form = page.locator(".contact-form"); form.getByLabel("First name").fill(newName); mopo.click(form.getByText("Save")); - assertThat(grid.getTableRow(rowToEdit).getCell(0)).hasText(newName); + assertThat(grid.getRow(rowToEdit).getCell(0)).hasText(newName); } } diff --git a/src/test/java/firitin/ui/DateView.java b/src/test/java/firitin/ui/DateView.java new file mode 100644 index 0000000..d75f9ab --- /dev/null +++ b/src/test/java/firitin/ui/DateView.java @@ -0,0 +1,50 @@ +package firitin.ui; + +import com.vaadin.flow.component.UI; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.datepicker.DatePicker; +import com.vaadin.flow.component.datetimepicker.DateTimePicker; +import com.vaadin.flow.component.html.Paragraph; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.router.Route; + +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Locale; + +@Route +public class DateView extends VerticalLayout { + + public DateView() { + + UI.getCurrent().setLocale(Locale.forLanguageTag("fi")); + + DatePicker datePicker = new DatePicker(); + datePicker.setId("dp"); + + Paragraph dpValue = new Paragraph(); + dpValue.setId("dpValue"); + datePicker.addValueChangeListener(e -> { + dpValue.setText(e.getValue().toString()); + }); + add(datePicker, dpValue); + + DateTimePicker dateTimePicker = new DateTimePicker(); + dateTimePicker.setStep(Duration.of(1, ChronoUnit.SECONDS)); + dateTimePicker.setId("dtp"); + Paragraph dtpValue = new Paragraph(); + dtpValue.setId("dtpValue"); + add(dateTimePicker, dtpValue); + + dateTimePicker.addValueChangeListener(e -> dtpValue.setText(e.getValue().toString())); + + add(new Button("set now", e-> { + datePicker.setValue(LocalDate.now()); + dateTimePicker.setValue(LocalDateTime.now()); + })); + + } + +}