diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardPage.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardPage.java index b1ce7d0e624..433a6d0a843 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardPage.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardPage.java @@ -116,36 +116,6 @@ public DashboardPage() { .ifPresent(dashboard::remove)); removeFirstSection.setId("remove-first-section"); - NativeButton addWidgetToFirstSection = new NativeButton( - "Add widget to first section"); - addWidgetToFirstSection.addClickListener( - click -> getFirstSection(dashboard).ifPresent(section -> { - DashboardWidget newWidget = new DashboardWidget(); - newWidget.setTitle("New widget"); - section.add(newWidget); - })); - addWidgetToFirstSection.setId("add-widget-to-first-section"); - - NativeButton removeFirstWidgetFromFirstSection = new NativeButton( - "Remove first widget from first section"); - removeFirstWidgetFromFirstSection.addClickListener( - click -> getFirstSection(dashboard).ifPresent(section -> { - List currentWidgets = section.getWidgets(); - if (currentWidgets.isEmpty()) { - return; - } - section.remove(currentWidgets.get(0)); - })); - removeFirstWidgetFromFirstSection - .setId("remove-first-widget-from-first-section"); - - NativeButton removeAllFromFirstSection = new NativeButton( - "Remove all from first section"); - removeAllFromFirstSection - .addClickListener(click -> getFirstSection(dashboard) - .ifPresent(DashboardSection::removeAll)); - removeAllFromFirstSection.setId("remove-all-from-first-section"); - NativeButton setMaximumColumnCount1 = new NativeButton( "Set maximum column count 1"); setMaximumColumnCount1 @@ -158,24 +128,9 @@ public DashboardPage() { click -> dashboard.setMaximumColumnCount(null)); setMaximumColumnCountNull.setId("set-maximum-column-count-null"); - NativeButton increaseAllColspansBy1 = new NativeButton( - "Increase all colspans by 1"); - increaseAllColspansBy1.addClickListener(click -> dashboard.getWidgets() - .forEach(widget -> widget.setColspan(widget.getColspan() + 1))); - increaseAllColspansBy1.setId("increase-all-colspans-by-1"); - - NativeButton decreaseAllColspansBy1 = new NativeButton( - "Decrease all colspans by 1"); - decreaseAllColspansBy1.addClickListener(click -> dashboard.getWidgets() - .forEach(widget -> widget.setColspan(widget.getColspan() - 1))); - decreaseAllColspansBy1.setId("decrease-all-colspans-by-1"); - add(addMultipleWidgets, removeFirstAndLastWidgets, removeAll, addSectionWithMultipleWidgets, removeFirstSection, - addWidgetToFirstSection, removeFirstWidgetFromFirstSection, - removeAllFromFirstSection, setMaximumColumnCount1, - setMaximumColumnCountNull, increaseAllColspansBy1, - decreaseAllColspansBy1, dashboard); + setMaximumColumnCount1, setMaximumColumnCountNull, dashboard); } private static Optional getFirstSection( diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardSectionPage.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardSectionPage.java new file mode 100644 index 00000000000..79f882d0b68 --- /dev/null +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardSectionPage.java @@ -0,0 +1,89 @@ +/** + * Copyright 2000-2024 Vaadin Ltd. + * + * This program is available under Vaadin Commercial License and Service Terms. + * + * See {@literal } for the full + * license. + */ +package com.vaadin.flow.component.dashboard.tests; + +import java.util.List; +import java.util.Optional; + +import com.vaadin.flow.component.dashboard.Dashboard; +import com.vaadin.flow.component.dashboard.DashboardSection; +import com.vaadin.flow.component.dashboard.DashboardWidget; +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.NativeButton; +import com.vaadin.flow.router.Route; + +/** + * @author Vaadin Ltd + */ +@Route("vaadin-dashboard-section") +public class DashboardSectionPage extends Div { + + public DashboardSectionPage() { + Dashboard dashboard = new Dashboard(); + + DashboardWidget widget1InSection1 = new DashboardWidget(); + widget1InSection1.setTitle("Widget 1 in Section 1"); + widget1InSection1.setId("widget-1-in-section-1"); + + DashboardWidget widget2InSection1 = new DashboardWidget(); + widget2InSection1.setTitle("Widget 2 in Section 1"); + widget2InSection1.setId("widget-2-in-section-1"); + + DashboardWidget widget1InSection2 = new DashboardWidget(); + widget1InSection2.setTitle("Widget 1 in Section 2"); + widget1InSection2.setId("widget-1-in-section-2"); + + DashboardSection section1 = new DashboardSection("Section 1"); + section1.add(widget1InSection1, widget2InSection1); + dashboard.addSection(section1); + + DashboardSection section2 = dashboard.addSection("Section 2"); + section2.add(widget1InSection2); + + NativeButton addWidgetToFirstSection = new NativeButton( + "Add widget to first section"); + addWidgetToFirstSection.addClickListener( + click -> getFirstSection(dashboard).ifPresent(section -> { + DashboardWidget newWidget = new DashboardWidget(); + newWidget.setTitle("New widget"); + section.add(newWidget); + })); + addWidgetToFirstSection.setId("add-widget-to-first-section"); + + NativeButton removeFirstWidgetFromFirstSection = new NativeButton( + "Remove first widget from first section"); + removeFirstWidgetFromFirstSection.addClickListener( + click -> getFirstSection(dashboard).ifPresent(section -> { + List currentWidgets = section.getWidgets(); + if (currentWidgets.isEmpty()) { + return; + } + section.remove(currentWidgets.get(0)); + })); + removeFirstWidgetFromFirstSection + .setId("remove-first-widget-from-first-section"); + + NativeButton removeAllFromFirstSection = new NativeButton( + "Remove all from first section"); + removeAllFromFirstSection + .addClickListener(click -> getFirstSection(dashboard) + .ifPresent(DashboardSection::removeAll)); + removeAllFromFirstSection.setId("remove-all-from-first-section"); + + add(addWidgetToFirstSection, removeFirstWidgetFromFirstSection, + removeAllFromFirstSection, dashboard); + } + + private static Optional getFirstSection( + Dashboard dashboard) { + return dashboard.getChildren() + .filter(DashboardSection.class::isInstance) + .map(DashboardSection.class::cast).findFirst(); + } +} diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java index 38f107b52ff..007b3095fca 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/main/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetPage.java @@ -8,8 +8,13 @@ */ package com.vaadin.flow.component.dashboard.tests; +import java.util.List; + +import com.vaadin.flow.component.dashboard.Dashboard; import com.vaadin.flow.component.dashboard.DashboardWidget; import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.NativeButton; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.router.Route; /** @@ -19,8 +24,54 @@ public class DashboardWidgetPage extends Div { public DashboardWidgetPage() { - DashboardWidget widget = new DashboardWidget(); - widget.setTitle("Widget"); - add(widget); + Dashboard dashboard = new Dashboard(); + + DashboardWidget widget1 = new DashboardWidget(); + widget1.setTitle("Widget 1"); + widget1.setContent(new Div("Some content")); + widget1.setId("widget-1"); + + DashboardWidget widget2 = new DashboardWidget(); + widget2.setTitle("Widget 2"); + widget2.setId("widget-2"); + + dashboard.add(widget1, widget2); + + NativeButton increaseAllColspansBy1 = new NativeButton( + "Increase all colspans by 1"); + increaseAllColspansBy1.addClickListener(click -> dashboard.getWidgets() + .forEach(widget -> widget.setColspan(widget.getColspan() + 1))); + increaseAllColspansBy1.setId("increase-all-colspans-by-1"); + + NativeButton decreaseAllColspansBy1 = new NativeButton( + "Decrease all colspans by 1"); + decreaseAllColspansBy1.addClickListener(click -> dashboard.getWidgets() + .forEach(widget -> widget.setColspan(widget.getColspan() - 1))); + decreaseAllColspansBy1.setId("decrease-all-colspans-by-1"); + + NativeButton updateContentOfTheFirstWidget = new NativeButton( + "Update content of the first widget"); + updateContentOfTheFirstWidget.addClickListener(click -> { + List widgets = dashboard.getWidgets(); + if (!widgets.isEmpty()) { + widgets.get(0).setContent(new Span("Updated content")); + } + }); + updateContentOfTheFirstWidget + .setId("update-content-of-the-first-widget"); + + NativeButton removeContentOfTheFirstWidget = new NativeButton( + "Remove content of the first widget"); + removeContentOfTheFirstWidget.addClickListener(click -> { + List widgets = dashboard.getWidgets(); + if (!widgets.isEmpty()) { + widgets.get(0).setContent(null); + } + }); + removeContentOfTheFirstWidget + .setId("remove-content-of-the-first-widget"); + + add(updateContentOfTheFirstWidget, removeContentOfTheFirstWidget, + increaseAllColspansBy1, decreaseAllColspansBy1, dashboard); } } diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardIT.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardIT.java index bf9be05de7d..cbea894bb70 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardIT.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardIT.java @@ -100,34 +100,6 @@ public void removeFirstSection_sectionIsRemoved() { assertSectionWidgetsByTitle(firstSection, "Widget 1 in Section 2"); } - @Test - public void addWidgetToFirstSection_widgetsAreAdded() { - clickElementWithJs("add-widget-to-first-section"); - List sections = dashboardElement.getSections(); - DashboardSectionElement firstSection = sections.get(0); - Assert.assertEquals("Section 1", firstSection.getTitle()); - assertSectionWidgetsByTitle(firstSection, "Widget 1 in Section 1", - "Widget 2 in Section 1", "New widget"); - } - - @Test - public void removeFirstWidgetFromFirstSection_widgetIsRemoved() { - clickElementWithJs("remove-first-widget-from-first-section"); - List sections = dashboardElement.getSections(); - DashboardSectionElement firstSection = sections.get(0); - Assert.assertEquals("Section 1", firstSection.getTitle()); - assertSectionWidgetsByTitle(firstSection, "Widget 2 in Section 1"); - } - - @Test - public void removeAllFromFirstSection_widgetsAreRemoved() { - clickElementWithJs("remove-all-from-first-section"); - List sections = dashboardElement.getSections(); - DashboardSectionElement firstSection = sections.get(0); - Assert.assertEquals("Section 1", firstSection.getTitle()); - assertSectionWidgetsByTitle(firstSection); - } - @Test public void changeMaximumColumnCountTo1_widgetsShouldBeOnTheSameColumn() { List widgets = dashboardElement.getWidgets(); @@ -155,24 +127,6 @@ public void changeMaximumColumnCountToNull_widgetsShouldBeOnTheSameRow() { Assert.assertEquals(yOfWidget1, widgets.get(1).getLocation().getY()); } - @Test - public void defaultWidgetColspanIsCorrect() { - List widgets = dashboardElement.getWidgets(); - widgets.forEach(widget -> Assert.assertEquals(Integer.valueOf(1), - widget.getColspan())); - } - - @Test - public void updateColspans_colspansForAllWidgetsUpdated() { - clickElementWithJs("increase-all-colspans-by-1"); - List widgets = dashboardElement.getWidgets(); - widgets.forEach(widget -> Assert.assertEquals(Integer.valueOf(2), - widget.getColspan())); - clickElementWithJs("decrease-all-colspans-by-1"); - widgets.forEach(widget -> Assert.assertEquals(Integer.valueOf(1), - widget.getColspan())); - } - private void assertDashboardWidgetsByTitle(String... expectedWidgetTitles) { assertWidgetsByTitle(dashboardElement.getWidgets(), expectedWidgetTitles); diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardSectionIT.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardSectionIT.java new file mode 100644 index 00000000000..31e275b8561 --- /dev/null +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardSectionIT.java @@ -0,0 +1,78 @@ +/** + * Copyright 2000-2024 Vaadin Ltd. + * + * This program is available under Vaadin Commercial License and Service Terms. + * + * See {@literal } for the full + * license. + */ +package com.vaadin.flow.component.dashboard.tests; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.flow.component.dashboard.testbench.DashboardElement; +import com.vaadin.flow.component.dashboard.testbench.DashboardSectionElement; +import com.vaadin.flow.component.dashboard.testbench.DashboardWidgetElement; +import com.vaadin.flow.testutil.TestPath; +import com.vaadin.tests.AbstractComponentIT; + +/** + * @author Vaadin Ltd + */ +@TestPath("vaadin-dashboard-section") +public class DashboardSectionIT extends AbstractComponentIT { + + private DashboardElement dashboardElement; + + @Before + public void init() { + open(); + dashboardElement = $(DashboardElement.class).waitForFirst(); + } + + @Test + public void addWidgetToFirstSection_widgetsAreAdded() { + clickElementWithJs("add-widget-to-first-section"); + List sections = dashboardElement.getSections(); + DashboardSectionElement firstSection = sections.get(0); + Assert.assertEquals("Section 1", firstSection.getTitle()); + assertSectionWidgetsByTitle(firstSection, "Widget 1 in Section 1", + "Widget 2 in Section 1", "New widget"); + } + + @Test + public void removeFirstWidgetFromFirstSection_widgetIsRemoved() { + clickElementWithJs("remove-first-widget-from-first-section"); + List sections = dashboardElement.getSections(); + DashboardSectionElement firstSection = sections.get(0); + Assert.assertEquals("Section 1", firstSection.getTitle()); + assertSectionWidgetsByTitle(firstSection, "Widget 2 in Section 1"); + } + + @Test + public void removeAllFromFirstSection_widgetsAreRemoved() { + clickElementWithJs("remove-all-from-first-section"); + List sections = dashboardElement.getSections(); + DashboardSectionElement firstSection = sections.get(0); + Assert.assertEquals("Section 1", firstSection.getTitle()); + assertSectionWidgetsByTitle(firstSection); + } + + private static void assertSectionWidgetsByTitle( + DashboardSectionElement section, String... expectedWidgetTitles) { + assertWidgetsByTitle(section.getWidgets(), expectedWidgetTitles); + } + + private static void assertWidgetsByTitle( + List actualWidgets, + String... expectedWidgetTitles) { + List widgetTitles = actualWidgets.stream() + .map(DashboardWidgetElement::getTitle).toList(); + Assert.assertEquals(Arrays.asList(expectedWidgetTitles), widgetTitles); + } +} diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java index d48f1dac051..ae26118af9e 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow-integration-tests/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetIT.java @@ -8,10 +8,13 @@ */ package com.vaadin.flow.component.dashboard.tests; +import java.util.List; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.vaadin.flow.component.dashboard.testbench.DashboardElement; import com.vaadin.flow.component.dashboard.testbench.DashboardWidgetElement; import com.vaadin.flow.testutil.TestPath; import com.vaadin.tests.AbstractComponentIT; @@ -22,16 +25,65 @@ @TestPath("vaadin-dashboard-widget") public class DashboardWidgetIT extends AbstractComponentIT { - private DashboardWidgetElement widget; + private DashboardElement dashboardElement; @Before public void init() { open(); - widget = $(DashboardWidgetElement.class).waitForFirst(); + dashboardElement = $(DashboardElement.class).waitForFirst(); } @Test public void titleIsSetCorrectly() { - Assert.assertEquals("Widget", widget.getTitle()); + Assert.assertEquals("Widget 1", + dashboardElement.getWidgets().get(0).getTitle()); + } + + @Test + public void defaultWidgetColspanIsCorrect() { + List widgets = dashboardElement.getWidgets(); + widgets.forEach(widget -> Assert.assertEquals(Integer.valueOf(1), + widget.getColspan())); + } + + @Test + public void updateColspans_colspansForAllWidgetsUpdated() { + clickElementWithJs("increase-all-colspans-by-1"); + List widgets = dashboardElement.getWidgets(); + widgets.forEach(widget -> Assert.assertEquals(Integer.valueOf(2), + widget.getColspan())); + clickElementWithJs("decrease-all-colspans-by-1"); + widgets.forEach(widget -> Assert.assertEquals(Integer.valueOf(1), + widget.getColspan())); + } + + @Test + public void widgetWithInitialContent_contentIsCorrectlySet() { + DashboardWidgetElement firstWidget = dashboardElement.getWidgets() + .get(0); + Assert.assertNotNull(firstWidget.getContent()); + Assert.assertTrue( + firstWidget.getContent().getText().contains("Some content")); + } + + @Test + public void updateWidgetContent_contentIsCorrectlyUpdated() { + clickElementWithJs("update-content-of-the-first-widget"); + DashboardWidgetElement firstWidget = dashboardElement.getWidgets() + .get(0); + Assert.assertNotNull(firstWidget.getContent()); + Assert.assertFalse( + firstWidget.getContent().getText().contains("Some content")); + Assert.assertTrue( + firstWidget.getContent().getText().contains("Updated content")); + } + + @Test + public void removeWidgetContent_contentIsCorrectlyRemoved() { + clickElementWithJs("remove-content-of-the-first-widget"); + DashboardWidgetElement firstWidget = dashboardElement.getWidgets() + .get(0); + Assert.assertFalse(firstWidget.getText().contains("Some content")); + Assert.assertNull(firstWidget.getContent()); } } diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java index 8c85a840ed4..8fabe496413 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java @@ -71,6 +71,38 @@ public void setColspan(int colspan) { notifyParentDashboardOrSection(); } + /** + * Returns the content of the widget. Returns {@code null} if the widget has + * no content. + * + * @return the content of the widget + */ + public Component getContent() { + return getChildren().filter( + component -> !component.getElement().hasAttribute("slot")) + .findAny().orElse(null); + } + + /** + * Sets the content to the widget. Set {@code null} to remove the current + * content. + * + * @param content + * the content to set + */ + public void setContent(Component content) { + Component initialContent = getContent(); + if (initialContent == content) { + return; + } + if (initialContent != null) { + getElement().removeChild(initialContent.getElement()); + } + if (content != null) { + getElement().appendChild(content.getElement()); + } + } + private void notifyParentDashboardOrSection() { getParent().ifPresent(parent -> { if (parent instanceof Dashboard dashboard) { diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetTest.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetTest.java index 94d3e8c92f6..e9fd5e56f99 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetTest.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/test/java/com/vaadin/flow/component/dashboard/tests/DashboardWidgetTest.java @@ -17,6 +17,7 @@ import com.vaadin.flow.component.UI; import com.vaadin.flow.component.dashboard.DashboardWidget; import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.server.VaadinSession; public class DashboardWidgetTest { @@ -106,6 +107,46 @@ public void setInvalidColspan_throwsIllegalArgumentException() { () -> widget.setColspan(0)); } + @Test + public void defaultContentIsNull() { + DashboardWidget widget = new DashboardWidget(); + Assert.assertNull(widget.getContent()); + } + + @Test + public void setContentToEmptyWidget_correctContentIsSet() { + Div content = new Div(); + DashboardWidget widget = new DashboardWidget(); + widget.setContent(content); + Assert.assertEquals(content, widget.getContent()); + } + + @Test + public void setAnotherContentToNonEmptyWidget_correctContentIsSet() { + DashboardWidget widget = new DashboardWidget(); + widget.setContent(new Div()); + Span newContent = new Span(); + widget.setContent(newContent); + Assert.assertEquals(newContent, widget.getContent()); + } + + @Test + public void setTheSameContentToNonEmptyWidget_correctContentIsSet() { + Div content = new Div(); + DashboardWidget widget = new DashboardWidget(); + widget.setContent(content); + widget.setContent(content); + Assert.assertEquals(content, widget.getContent()); + } + + @Test + public void setNullContentToNonEmptyWidget_contentIsRemoved() { + DashboardWidget widget = new DashboardWidget(); + widget.setContent(new Div()); + widget.setContent(null); + Assert.assertNull(widget.getContent()); + } + private void fakeClientCommunication() { ui.getInternals().getStateTree().runExecutionsBeforeClientResponse(); ui.getInternals().getStateTree().collectChanges(ignore -> { diff --git a/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java b/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java index d00bd52cca5..c78df04b6c6 100644 --- a/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java +++ b/vaadin-dashboard-flow-parent/vaadin-dashboard-testbench/src/main/java/com/vaadin/flow/component/dashboard/testbench/DashboardWidgetElement.java @@ -37,6 +37,18 @@ public Integer getColspan() { return colspanStr.isEmpty() ? null : Integer.valueOf(colspanStr); } + /** + * Returns the content of the widget. + * + * @return the content element set to the widget + */ + public TestBenchElement getContent() { + Object content = executeScript( + "return Array.from(arguments[0].children).filter(child => !child.slot)[0]", + this); + return content == null ? null : (TestBenchElement) content; + } + private String getComputedCssValue(String propertyName) { return (String) executeScript( "return getComputedStyle(arguments[0]).getPropertyValue(arguments[1]);",