Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Big Decimal Field
- Button
- Card
- Checkbox
- Date Picker
- Date Time Picker
Expand All @@ -18,6 +19,7 @@
- Progress bar
- Radio Button
- Select
- Split Layout
- Tabs
- TextArea
- TextField
Expand All @@ -27,7 +29,6 @@

- App Layout
- Avatar
- Card
- Combo Box
- Confirm Dialog
- Context Menu
Expand All @@ -38,7 +39,6 @@
- Message List
- Multi-Select Combobox
- Side navigation
- Split Layout
- Upload
- Virtual List

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.vaadin.addons.dramafinder.element;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;
import org.vaadin.addons.dramafinder.element.shared.HasLabelElement;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

/**
* PlaywrightElement for {@code <vaadin-side-nav>}.
*/
@PlaywrightElement(SideNavigationElement.FIELD_TAG_NAME)
public class SideNavigationElement extends VaadinElement implements HasLabelElement {

public static final String FIELD_TAG_NAME = "vaadin-side-nav";

public SideNavigationElement(Locator locator) {
super(locator);
}

@Override
public Locator getLabelLocator() {
return getLocator().locator("> [slot='label']");
}

/**
* Checks if the side nav is collapsed.
*/
public boolean isCollapsed() {
return getLocator().getAttribute("collapsed") != null;
}

/**
* Asserts that the side nav is collapsed.
*/
public void assertCollapsed() {
assertThat(getLocator()).hasAttribute("collapsed", "");
}

/**
* Asserts that the side nav is expanded.
*/
public void assertExpanded() {
assertThat(getLocator()).not().hasAttribute("collapsed", "");
}

/**
* Asserts that the side nav is collapsible.
*/
public void assertCollapsible() {
assertThat(getLocator()).hasAttribute("collapsible", "");
}

/**
* Asserts that the side nav is not collapsible.
*/
public void assertNotCollapsible() {
assertThat(getLocator()).not().hasAttribute("collapsible", "");
}

/**
* Gets a SideNavigationItemElement by its label text.
* This searches for a direct or nested vaadin-side-nav-item with the given
* text.
* Note: This strictly searches for the item that contains the text.
* Use care if multiple items have the same text.
* Your navigation item has to be visible, you'll need to open manually the parent.
*
* @param label The label of the item.
* @return The SideNavigationItemElement.
*/
public SideNavigationItemElement getItem(String label) {
// Using locator with hasText might be too broad if parent contains child text.
// But vaadin-side-nav-item encapsulates its content.
// Let's try to match exact text or contains.
// A common strategy is to use the label content.

// We construct a locator that finds a vaadin-side-nav-item that has this text.
// Since text is inside the item's shadow or light dom slots.

return new SideNavigationItemElement(
getLocator().locator(SideNavigationItemElement.FIELD_TAG_NAME)
.filter(new Locator.FilterOptions().setHasText(label)).first());
}

/**
* Clicks an item by its label.
*
* @param label The label of the item to click.
*/
public void clickItem(String label) {
getItem(label).click();
}

/**
* Get the {@code SideNavigationElement} by its label.
*
* @param page the Playwright page
* @param label the accessible label of the side navigation
* @return the matching {@code SideNavigationElement}
*/
public static SideNavigationElement getByLabel(Page page, String label) {
return new SideNavigationElement(
page.getByRole(AriaRole.NAVIGATION,
new Page.GetByRoleOptions().setName(label)
).and(page.locator(FIELD_TAG_NAME)).first());
}

/**
* Toggles the expansion state of the item.
*/
public void toggle() {
getLocator().locator("[slot='label']").first().click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.vaadin.addons.dramafinder.element;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.options.AriaRole;
import org.vaadin.addons.dramafinder.element.shared.HasEnabledElement;
import org.vaadin.addons.dramafinder.element.shared.HasLabelElement;
import org.vaadin.addons.dramafinder.element.shared.HasPrefixElement;
import org.vaadin.addons.dramafinder.element.shared.HasSuffixElement;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

/**
* PlaywrightElement for {@code <vaadin-side-nav-item>}.
*/
@PlaywrightElement(SideNavigationItemElement.FIELD_TAG_NAME)
public class SideNavigationItemElement extends VaadinElement implements HasEnabledElement, HasPrefixElement, HasSuffixElement, HasLabelElement {

public static final String FIELD_TAG_NAME = "vaadin-side-nav-item";

public SideNavigationItemElement(Locator locator) {
super(locator);
}

/**
* Checks if the item is expanded.
*/
public boolean isExpanded() {
return getLocator().getAttribute("expanded") != null;
}

/**
* Asserts that the item is expanded.
*/
public void assertExpanded() {
assertThat(getLocator()).hasAttribute("expanded", "");
}

/**
* Asserts that the item is collapsed.
*/
public void assertCollapsed() {
assertThat(getLocator()).not().hasAttribute("expanded", "");
}

/**
* Asserts that the item is enabled.
*/
@Override
public void assertEnabled() {
assertThat(getLocator()).not().hasAttribute("disabled", "");
}

/**
* Asserts that the item is disabled.
*/
@Override
public void assertDisabled() {
assertThat(getLocator()).hasAttribute("disabled", "");
}

/**
* Asserts that the item is current.
*/
public void assertCurrent() {
assertThat(getLocator()).hasAttribute("current", "");
}

/**
* Asserts that the item is not current.
*/
public void assertNotCurrent() {
assertThat(getLocator()).not().hasAttribute("current", "");
}


/**
* Toggles the expansion state of the item.
* This relies on the toggle button inside the item.
*/
public void toggle() {
getLocator().locator("button[part='toggle-button']").first().click();
}

@Override
public Locator getLabelLocator() {
return getLocator();
}

public void navigate() {
getLocator().getByRole(AriaRole.LINK).first().click();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vaadin.addons.dramafinder.element.shared;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.assertions.LocatorAssertions;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

Expand All @@ -9,20 +10,26 @@
*/
public interface HasLabelElement extends HasLocatorElement {

/** Locator for the visible label element. */
/**
* Locator for the visible label element.
*/
default Locator getLabelLocator() {
return getLocator().locator("label").first();
}

/** Get the label text. */
/**
* Get the label text.
*/
default String getLabel() {
return getLabelLocator().textContent();
}

/** Assert that the label text matches, or is hidden when null. */
/**
* Assert that the label text matches, or is hidden when null.
*/
default void assertLabel(String label) {
if (label != null) {
assertThat(getLabelLocator()).hasText(label);
assertThat(getLabelLocator()).hasText(label, new LocatorAssertions.HasTextOptions().setUseInnerText(true));
} else {
assertThat(getLabelLocator()).isHidden();
}
Expand Down
Loading
Loading