diff --git a/skills/vaadin-playwright-test/api-reference.md b/skills/vaadin-playwright-test/api-reference.md index c6709a8..299e8de 100644 --- a/skills/vaadin-playwright-test/api-reference.md +++ b/skills/vaadin-playwright-test/api-reference.md @@ -1,7 +1,7 @@ # DramaFinder API Reference > **Auto-generated from source — do not edit by hand.** Regenerate with `jbang tools/generate-api-reference.java`. -> DramaFinder 1.1.3-SNAPSHOT — 42 element wrappers. +> DramaFinder 1.1.6-SNAPSHOT — 42 element wrappers. Complete public API of every DramaFinder element wrapper. Each element lists the shared mixin interfaces it implements; those interfaces' methods are documented once under **Shared mixins** at the end (not repeated per element). Method one-liners come from Javadoc. @@ -274,7 +274,7 @@ PlaywrightElement for . PlaywrightElement for . **Extends:** VaadinElement -**Implements:** FocusableElement, HasAriaLabelElement, HasInputFieldElement, HasPrefixElement, HasThemeElement, HasPlaceholderElement, HasEnabledElement, HasTooltipElement, HasValidationPropertiesElement, HasClearButtonElement, HasAllowedCharPatternElement +**Implements:** FocusableElement, HasAriaLabelElement, HasInputFieldElement, HasPrefixElement, HasThemeElement, HasPlaceholderElement, HasEnabledElement, HasTooltipElement, HasValidationPropertiesElement, HasClearButtonElement, HasAllowedCharPatternElement, HasReadOnlyElement **Constants:** `String FIELD_TAG_NAME = "vaadin-combo-box"`, `String FIELD_ITEM_TAG_NAME = "vaadin-combo-box-item"` @@ -298,9 +298,6 @@ PlaywrightElement for . - `boolean isOpened()` — Whether the overlay is currently open. - `void assertOpened()` — Assert that the combo box overlay is open. - `void assertClosed()` — Assert that the combo box overlay is closed. -- `boolean isReadOnly()` — Whether the combo box is read-only. -- `void assertReadOnly()` — Assert that the combo box is read-only. -- `void assertNotReadOnly()` — Assert that the combo box is not read-only. - `Locator getToggleButtonLocator()` — Locator for the toggle button part. - `void clickToggleButton()` — Click the dropdown toggle button. - `int getOverlayItemCount()` — Count visible overlay items. @@ -811,7 +808,7 @@ PlaywrightElement for . PlaywrightElement for . **Extends:** VaadinElement -**Implements:** FocusableElement, HasAriaLabelElement, HasInputFieldElement, HasThemeElement, HasPlaceholderElement, HasEnabledElement, HasTooltipElement, HasValidationPropertiesElement, HasClearButtonElement, HasAllowedCharPatternElement +**Implements:** FocusableElement, HasAriaLabelElement, HasInputFieldElement, HasThemeElement, HasPlaceholderElement, HasEnabledElement, HasTooltipElement, HasValidationPropertiesElement, HasClearButtonElement, HasAllowedCharPatternElement, HasReadOnlyElement **Constants:** `String FIELD_TAG_NAME = "vaadin-multi-select-combo-box"`, `String FIELD_ITEM_TAG_NAME = "vaadin-multi-select-combo-box-item"`, `String FIELD_CHIP_TAG_NAME = "vaadin-multi-select-combo-box-chip"` @@ -838,9 +835,6 @@ PlaywrightElement for . - `boolean isOpened()` — Whether the overlay is currently open. - `void assertOpened()` — Assert that the combo box overlay is open. - `void assertClosed()` — Assert that the combo box overlay is closed. -- `boolean isReadOnly()` — Whether the combo box is read-only. -- `void assertReadOnly()` — Assert that the combo box is read-only. -- `void assertNotReadOnly()` — Assert that the combo box is not read-only. - `Locator getToggleButtonLocator()` — Locator for the toggle button part. - `void clickToggleButton()` — Click the dropdown toggle button. - `int getOverlayItemCount()` — Count visible overlay items. @@ -1178,7 +1172,7 @@ PlaywrightElement for . PlaywrightElement for **Extends:** VaadinElement -**Implements:** HasValidationPropertiesElement, HasInputFieldElement, HasPrefixElement, HasSuffixElement, HasClearButtonElement, HasPlaceholderElement, HasAllowedCharPatternElement, HasThemeElement, FocusableElement, HasAriaLabelElement, HasEnabledElement, HasTooltipElement +**Implements:** HasValidationPropertiesElement, HasInputFieldElement, HasPrefixElement, HasSuffixElement, HasClearButtonElement, HasPlaceholderElement, HasAllowedCharPatternElement, HasThemeElement, FocusableElement, HasAriaLabelElement, HasEnabledElement, HasReadOnlyElement, HasTooltipElement **Constants:** `String FIELD_TAG_NAME = "vaadin-text-field"`, `String MAXLENGTH_ATTRIBUTE = "maxlength"`, `String PATTERN_ATTRIBUTE = "pattern"`, `String MIN_LENGTH_ATTRIBUTE = "minLength"` @@ -1478,6 +1472,23 @@ Utilities to interact with components implementing Vaadin's HasPrefix(slot="pref - `String getPrefixText()` — Text content of the prefix slot. - `void assertPrefixHasText(String text)` — Assert that the prefix slot has the expected text, or is hidden when null. +### HasReadOnlyElement + +Mixin for components that expose a read-only state through the reflected readonly attribute. + +**Extends:** HasLocatorElement + +**Constants:** `String READONLY_ATTRIBUTE = "readonly"` + +**Methods:** + +- `Locator getReadOnlyLocator()` — Locator used to check the read-only state. +- `boolean isReadOnly()` — Whether the component is read-only. +- `boolean isReadOnly(boolean readOnly)` — Whether the component's read-only state matches the expected value. +- `void assertReadOnly()` — Assert that the component is read-only. +- `void assertReadOnly(boolean readOnly)` — Assert that the component is read-only (true) or not read-only (false). +- `void assertNotReadOnly()` — Assert that the component is not read-only. + ### HasStyleElement Mixin for components exposing styling via CSS classes. diff --git a/src/main/java/org/vaadin/addons/dramafinder/element/ComboBoxElement.java b/src/main/java/org/vaadin/addons/dramafinder/element/ComboBoxElement.java index 3960358..088b2ed 100644 --- a/src/main/java/org/vaadin/addons/dramafinder/element/ComboBoxElement.java +++ b/src/main/java/org/vaadin/addons/dramafinder/element/ComboBoxElement.java @@ -11,6 +11,7 @@ import org.vaadin.addons.dramafinder.element.shared.HasInputFieldElement; import org.vaadin.addons.dramafinder.element.shared.HasPlaceholderElement; import org.vaadin.addons.dramafinder.element.shared.HasPrefixElement; +import org.vaadin.addons.dramafinder.element.shared.HasReadOnlyElement; import org.vaadin.addons.dramafinder.element.shared.HasThemeElement; import org.vaadin.addons.dramafinder.element.shared.HasTooltipElement; import org.vaadin.addons.dramafinder.element.shared.HasValidationPropertiesElement; @@ -29,7 +30,7 @@ public class ComboBoxElement extends VaadinElement implements FocusableElement, HasAriaLabelElement, HasInputFieldElement, HasPrefixElement, HasThemeElement, HasPlaceholderElement, HasEnabledElement, HasTooltipElement, HasValidationPropertiesElement, - HasClearButtonElement, HasAllowedCharPatternElement { + HasClearButtonElement, HasAllowedCharPatternElement, HasReadOnlyElement { public static final String FIELD_TAG_NAME = "vaadin-combo-box"; public static final String FIELD_ITEM_TAG_NAME = "vaadin-combo-box-item"; @@ -173,29 +174,6 @@ public void assertClosed() { assertThat(getLocator()).not().hasAttribute("opened", ""); } - /** - * Whether the combo box is read-only. - * - * @return {@code true} when read-only - */ - public boolean isReadOnly() { - return getLocator().getAttribute("readonly") != null; - } - - /** - * Assert that the combo box is read-only. - */ - public void assertReadOnly() { - assertThat(getLocator()).hasAttribute("readonly", ""); - } - - /** - * Assert that the combo box is not read-only. - */ - public void assertNotReadOnly() { - assertThat(getLocator()).not().hasAttribute("readonly", ""); - } - /** * Locator for the toggle button part. * diff --git a/src/main/java/org/vaadin/addons/dramafinder/element/MultiSelectComboBoxElement.java b/src/main/java/org/vaadin/addons/dramafinder/element/MultiSelectComboBoxElement.java index 0cc9e72..75713ee 100644 --- a/src/main/java/org/vaadin/addons/dramafinder/element/MultiSelectComboBoxElement.java +++ b/src/main/java/org/vaadin/addons/dramafinder/element/MultiSelectComboBoxElement.java @@ -16,6 +16,7 @@ import org.vaadin.addons.dramafinder.element.shared.HasEnabledElement; import org.vaadin.addons.dramafinder.element.shared.HasInputFieldElement; import org.vaadin.addons.dramafinder.element.shared.HasPlaceholderElement; +import org.vaadin.addons.dramafinder.element.shared.HasReadOnlyElement; import org.vaadin.addons.dramafinder.element.shared.HasThemeElement; import org.vaadin.addons.dramafinder.element.shared.HasTooltipElement; @@ -34,7 +35,7 @@ public class MultiSelectComboBoxElement extends VaadinElement implements FocusableElement, HasAriaLabelElement, HasInputFieldElement, HasThemeElement, HasPlaceholderElement, HasEnabledElement, HasTooltipElement, HasValidationPropertiesElement, - HasClearButtonElement, HasAllowedCharPatternElement { + HasClearButtonElement, HasAllowedCharPatternElement, HasReadOnlyElement { public static final String FIELD_TAG_NAME = "vaadin-multi-select-combo-box"; public static final String FIELD_ITEM_TAG_NAME = "vaadin-multi-select-combo-box-item"; @@ -213,31 +214,6 @@ public void assertClosed() { assertThat(getLocator()).not().hasAttribute("opened", ""); } - // ── Read-only ────────────────────────────────────────────────────── - - /** - * Whether the combo box is read-only. - * - * @return {@code true} when read-only - */ - public boolean isReadOnly() { - return getLocator().getAttribute("readonly") != null; - } - - /** - * Assert that the combo box is read-only. - */ - public void assertReadOnly() { - assertThat(getLocator()).hasAttribute("readonly", ""); - } - - /** - * Assert that the combo box is not read-only. - */ - public void assertNotReadOnly() { - assertThat(getLocator()).not().hasAttribute("readonly", ""); - } - // ── Toggle button ────────────────────────────────────────────────── /** diff --git a/src/main/java/org/vaadin/addons/dramafinder/element/TextFieldElement.java b/src/main/java/org/vaadin/addons/dramafinder/element/TextFieldElement.java index 6c57cc5..77b6d59 100644 --- a/src/main/java/org/vaadin/addons/dramafinder/element/TextFieldElement.java +++ b/src/main/java/org/vaadin/addons/dramafinder/element/TextFieldElement.java @@ -14,6 +14,7 @@ import org.vaadin.addons.dramafinder.element.shared.HasInputFieldElement; import org.vaadin.addons.dramafinder.element.shared.HasPlaceholderElement; import org.vaadin.addons.dramafinder.element.shared.HasPrefixElement; +import org.vaadin.addons.dramafinder.element.shared.HasReadOnlyElement; import org.vaadin.addons.dramafinder.element.shared.HasSuffixElement; import org.vaadin.addons.dramafinder.element.shared.HasThemeElement; import org.vaadin.addons.dramafinder.element.shared.HasTooltipElement; @@ -28,7 +29,7 @@ public class TextFieldElement extends VaadinElement implements HasValidationPropertiesElement, HasInputFieldElement, HasPrefixElement, HasSuffixElement, HasClearButtonElement, HasPlaceholderElement, HasAllowedCharPatternElement, - HasThemeElement, FocusableElement, HasAriaLabelElement, HasEnabledElement, HasTooltipElement { + HasThemeElement, FocusableElement, HasAriaLabelElement, HasEnabledElement, HasReadOnlyElement, HasTooltipElement { public static final String FIELD_TAG_NAME = "vaadin-text-field"; public static final String MAXLENGTH_ATTRIBUTE = "maxlength"; diff --git a/src/main/java/org/vaadin/addons/dramafinder/element/shared/HasReadOnlyElement.java b/src/main/java/org/vaadin/addons/dramafinder/element/shared/HasReadOnlyElement.java new file mode 100644 index 0000000..76e93bf --- /dev/null +++ b/src/main/java/org/vaadin/addons/dramafinder/element/shared/HasReadOnlyElement.java @@ -0,0 +1,49 @@ +package org.vaadin.addons.dramafinder.element.shared; + +import com.microsoft.playwright.Locator; + +import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; + +/** + * Mixin for components that expose a read-only state through the reflected + * {@code readonly} attribute. + */ +public interface HasReadOnlyElement extends HasLocatorElement { + + /** Attribute reflecting the read-only state. */ + String READONLY_ATTRIBUTE = "readonly"; + + /** Locator used to check the read-only state. Defaults to root. */ + default Locator getReadOnlyLocator() { + return getLocator(); + } + + /** Whether the component is read-only. */ + default boolean isReadOnly() { + return getReadOnlyLocator().getAttribute(READONLY_ATTRIBUTE) != null; + } + + /** Whether the component's read-only state matches the expected value. */ + default boolean isReadOnly(boolean readOnly) { + return isReadOnly() == readOnly; + } + + /** Assert that the component is read-only. */ + default void assertReadOnly() { + assertThat(getReadOnlyLocator()).hasAttribute(READONLY_ATTRIBUTE, ""); + } + + /** Assert that the component is read-only (true) or not read-only (false). */ + default void assertReadOnly(boolean readOnly) { + if (readOnly) { + assertReadOnly(); + } else { + assertNotReadOnly(); + } + } + + /** Assert that the component is not read-only. */ + default void assertNotReadOnly() { + assertThat(getReadOnlyLocator()).not().hasAttribute(READONLY_ATTRIBUTE, ""); + } +} diff --git a/src/test/java/org/vaadin/addons/dramafinder/tests/it/TextFieldViewIT.java b/src/test/java/org/vaadin/addons/dramafinder/tests/it/TextFieldViewIT.java index 2ea36c2..202ca1d 100644 --- a/src/test/java/org/vaadin/addons/dramafinder/tests/it/TextFieldViewIT.java +++ b/src/test/java/org/vaadin/addons/dramafinder/tests/it/TextFieldViewIT.java @@ -221,6 +221,20 @@ public void testEnabledDisabled() { textfield.assertEnabled(); } + @Test + public void testReadOnly() { + TextFieldElement textfield = TextFieldElement.getByLabel(page, "Read-only Field"); + textfield.assertReadOnly(); + textfield.assertReadOnly(true); + assertEquals(true, textfield.isReadOnly()); + + page.locator("#toggle-read-only-button").click(); + + textfield.assertNotReadOnly(); + textfield.assertReadOnly(false); + assertEquals(false, textfield.isReadOnly()); + } + @Test public void testLabel() { TextFieldElement textfieldWithLabel = TextFieldElement.getByLabel(page, "Textfield"); diff --git a/src/test/java/org/vaadin/addons/dramafinder/tests/testuis/TextFieldView.java b/src/test/java/org/vaadin/addons/dramafinder/tests/testuis/TextFieldView.java index ac464c3..eaab752 100755 --- a/src/test/java/org/vaadin/addons/dramafinder/tests/testuis/TextFieldView.java +++ b/src/test/java/org/vaadin/addons/dramafinder/tests/testuis/TextFieldView.java @@ -25,6 +25,17 @@ public TextFieldView() { createTextFieldWithAriaLabel(); createTextFieldWithAriaLabelledBy(); createEnabledDisabledExample(); + createReadOnlyExample(); + } + + private void createReadOnlyExample() { + TextField textfield = new TextField("Read-only Field"); + textfield.setValue("Read-only value"); + textfield.setReadOnly(true); + Button button = new Button("Toggle read-only"); + button.setId("toggle-read-only-button"); + button.addClickListener(e -> textfield.setReadOnly(!textfield.isReadOnly())); + addExample("Read-only Example", new HorizontalLayout(textfield, button)); } private void createTextFieldWithThemeExample() {