Skip to content

Commit 008113d

Browse files
mvysnyTatuLundsissbruecker
authored
feat: Implement TabSheetElement.getTabLabels() (#8108)
* #2022 Implement TabSheetElement.getTabCaptions() * #2022 fix formatting * TabsElement: rename getTabCaptions() to getTabLabels() * fix formatting * minor * remove HasLabel interface * clarify JavaDoc --------- Co-authored-by: Tatu Lund <[email protected]> Co-authored-by: Sascha Ißbrücker <[email protected]>
1 parent bd2e9c4 commit 008113d

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

vaadin-tabs-flow-parent/vaadin-tabs-flow-integration-tests/src/test/java/com/vaadin/flow/component/tabs/tests/TabSheetIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,10 @@ public void unselect_shouldThrowOnGetContent() {
9393
Assert.assertThrows(NoSuchElementException.class,
9494
() -> tabSheet.getContent());
9595
}
96+
97+
@Test
98+
public void getTabLabels_shouldReturnTwoTabs() {
99+
Assert.assertArrayEquals(new String[] { "Tab one", "Tab two" },
100+
tabSheet.getTabLabels().toArray());
101+
}
96102
}

vaadin-tabs-flow-parent/vaadin-tabs-testbench/src/main/java/com/vaadin/flow/component/tabs/testbench/TabElement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ public boolean isEnabled() {
2929
return !getPropertyBoolean("disabled");
3030
}
3131

32+
/**
33+
* Gets the label of the tab.
34+
*
35+
* @return the label of the tab
36+
*/
37+
public String getLabel() {
38+
return getText();
39+
}
3240
}

vaadin-tabs-flow-parent/vaadin-tabs-testbench/src/main/java/com/vaadin/flow/component/tabs/testbench/TabSheetElement.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.vaadin.flow.component.tabs.testbench;
1717

18+
import java.util.List;
19+
1820
import org.openqa.selenium.By;
1921
import org.openqa.selenium.NoSuchElementException;
2022

@@ -101,4 +103,12 @@ public TabsElement getTabs() {
101103
return $(TabsElement.class).first();
102104
}
103105

106+
/**
107+
* Returns the labels of all tab elements, in the order they appear.
108+
*
109+
* @return a list of tab labels, one for every tab. Not null, may be empty.
110+
*/
111+
public List<String> getTabLabels() {
112+
return getTabs().getTabLabels();
113+
}
104114
}

vaadin-tabs-flow-parent/vaadin-tabs-testbench/src/main/java/com/vaadin/flow/component/tabs/testbench/TabsElement.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,33 @@ public TabElement getTabElement(String text) throws NoSuchElementException {
8585
* or -1 if no match was found
8686
*/
8787
public int getTab(String text) {
88-
List<TestBenchElement> children = getPropertyElements("children");
88+
List<TabElement> children = getTabs();
8989
for (int i = 0; i < children.size(); i++) {
90-
String tabText = children.get(i).wrap(TabElement.class).getText();
91-
if (text.equals(tabText)) {
90+
String tabLabel = children.get(i).getLabel();
91+
if (text.equals(tabLabel)) {
9292
return i;
9393
}
9494
}
9595
return -1;
9696
}
9797

98+
/**
99+
* Returns the child tabs.
100+
*
101+
* @return the list of child tab elements. Not null, may be empty.
102+
*/
103+
public List<TabElement> getTabs() {
104+
List<TestBenchElement> children = getChildren();
105+
return children.stream().map(it -> it.wrap(TabElement.class)).toList();
106+
}
107+
108+
/**
109+
* Returns the labels of all tab elements, in the order they appear.
110+
*
111+
* @return a list of tab labels, one for every tab. Not null, may be empty.
112+
*/
113+
public List<String> getTabLabels() {
114+
final List<TabElement> tabElements = getTabs();
115+
return tabElements.stream().map(TabElement::getLabel).toList();
116+
}
98117
}

0 commit comments

Comments
 (0)