Skip to content

Commit f2b033d

Browse files
flangpaodb
authored andcommitted
test: add grid radio selection column tests
1 parent 4182d10 commit f2b033d

File tree

7 files changed

+173
-5
lines changed

7 files changed

+173
-5
lines changed

pom.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717
<drivers.dir>${project.basedir}/drivers</drivers.dir>
1818
<jetty.version>9.4.36.v20210114</jetty.version>
19+
<webdrivermanager.version>3.8.1</webdrivermanager.version>
20+
<driver-binary-downloader-maven-plugin.version>1.0.17</driver-binary-downloader-maven-plugin.version>
1921
</properties>
2022

2123
<organization>
@@ -158,7 +160,7 @@
158160
<dependency>
159161
<groupId>io.github.bonigarcia</groupId>
160162
<artifactId>webdrivermanager</artifactId>
161-
<version>3.8.1</version>
163+
<version>${webdrivermanager.version}</version>
162164
<scope>test</scope>
163165
<exclusions>
164166
<exclusion>
@@ -330,7 +332,7 @@
330332
<configuration>
331333
<quiet>true</quiet>
332334
<doclint>none</doclint>
333-
<additionalparam>-Xdoclint:none</additionalparam>
335+
<additionalparam>-Xdoclint:none</additionalparam>
334336
</configuration>
335337
</plugin>
336338
<plugin>
@@ -414,9 +416,8 @@
414416

415417
<plugin>
416418
<groupId>com.lazerycode.selenium</groupId>
417-
<artifactId>driver-binary-downloader-maven-plugin
418-
</artifactId>
419-
<version>1.0.17</version>
419+
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
420+
<version>${driver-binary-downloader-maven-plugin.version}</version>
420421
<configuration>
421422
<onlyGetDriversForHostOperatingSystem>
422423
true
@@ -563,7 +564,18 @@
563564
<vaadin.version>24.2.6</vaadin.version>
564565
<jetty.version>11.0.12</jetty.version>
565566
<frontend.hotdeploy>true</frontend.hotdeploy>
567+
<webdrivermanager.version>5.6.3</webdrivermanager.version>
568+
<driver-binary-downloader-maven-plugin.version>1.0.18</driver-binary-downloader-maven-plugin.version>
566569
</properties>
570+
571+
<dependencies>
572+
<dependency>
573+
<groupId>org.seleniumhq.selenium</groupId>
574+
<artifactId>selenium-java</artifactId>
575+
<version>4.17.0</version>
576+
<scope>test</scope>
577+
</dependency>
578+
</dependencies>
567579
</profile>
568580

569581
</profiles>

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/GridHelperElement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public TestBenchElement getSelectionCheckbox(int rowIndex) {
8585
return (TestBenchElement) elements.stream().findFirst().orElse(null);
8686
}
8787

88+
public TestBenchElement getSelectionRadioButton(int rowIndex) {
89+
// assumes that Grid is in single-selection mode
90+
TestBenchElement cell = getSlottedCell(getRow(rowIndex));
91+
List<WebElement> elements = cell.findElements(By.tagName("vaadin-radio-button"));
92+
return (TestBenchElement) elements.stream().findFirst().orElse(null);
93+
}
94+
95+
8896
private TestBenchElement getSlottedCell(WebElement e) {
8997
String slot = e.findElement(By.tagName("slot")).getAttribute("name");
9098
return findElement(By.cssSelector(String.format("[slot='%s']", slot)));
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*-
2+
* #%L
3+
* Grid Helpers Add-on
4+
* %%
5+
* Copyright (C) 2022 - 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package com.flowingcode.vaadin.addons.gridhelpers.it;
22+
23+
import static java.time.temporal.ChronoUnit.SECONDS;
24+
import static org.hamcrest.MatcherAssert.assertThat;
25+
import static org.hamcrest.Matchers.contains;
26+
import static org.hamcrest.Matchers.empty;
27+
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.Assert.assertNull;
30+
import static org.junit.Assert.assertTrue;
31+
import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport;
32+
import com.vaadin.flow.component.grid.testbench.GridElement;
33+
import com.vaadin.testbench.TestBenchElement;
34+
import java.time.Duration;
35+
import org.junit.Test;
36+
import org.openqa.selenium.By;
37+
import org.openqa.selenium.support.ui.ExpectedConditions;
38+
import org.openqa.selenium.support.ui.WebDriverWait;
39+
40+
public class GridRadioSelectionColumnIT extends AbstractViewTest implements HasRpcSupport {
41+
42+
IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class);
43+
GridHelperElement grid;
44+
45+
public GridRadioSelectionColumnIT() {
46+
super("it");
47+
}
48+
49+
@Override
50+
public void setup() throws Exception {
51+
super.setup();
52+
grid = new GridHelperElement($(GridElement.class).waitForFirst());
53+
}
54+
55+
@Test
56+
public void testRadioSelectionColumnShown() {
57+
// assert that the first column is not the one with radio button
58+
assertNull("the first column has radio buttons", grid.getSelectionRadioButton(0));
59+
60+
$server.showRadioSelectionColumn();
61+
62+
waitUntil(ExpectedConditions
63+
.presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column")));
64+
65+
// assert that the first column is the one with radio buttons
66+
assertNotNull("the first column has not any radio buttons", grid.getSelectionRadioButton(0));
67+
}
68+
69+
@Test
70+
public void testShouldSelectRowOnClick() {
71+
$server.showRadioSelectionColumn();
72+
73+
waitUntil(ExpectedConditions
74+
.presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column")));
75+
76+
assertThat($server.getSelectedRows(), empty());
77+
78+
grid.getCell(0, 1).click();
79+
assertThat($server.getSelectedRows(), contains(0));
80+
81+
grid.getCell(4, 1).click();
82+
assertThat($server.getSelectedRows(), contains(4));
83+
}
84+
85+
@Test
86+
public void testShouldSelectRowOnRadioButtonClick() {
87+
$server.showRadioSelectionColumn();
88+
89+
waitUntil(ExpectedConditions
90+
.presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column")));
91+
92+
93+
assertThat($server.getSelectedRows(), empty());
94+
95+
TestBenchElement radioButton = grid.getSelectionRadioButton(0);
96+
radioButton.click();
97+
assertThat($server.getSelectedRows(), contains(0));
98+
99+
100+
radioButton = grid.getSelectionRadioButton(4);
101+
radioButton.click();
102+
assertThat($server.getSelectedRows(), contains(4));
103+
}
104+
105+
@Test
106+
public void testRadioSelectionColumnFrozen() {
107+
$server.showRadioSelectionColumn();
108+
109+
waitUntil(ExpectedConditions
110+
.presenceOfElementLocated(By.tagName("grid-flow-radio-selection-column")));
111+
112+
TestBenchElement selectionColElement = grid.$("grid-flow-radio-selection-column").first();
113+
114+
String frozen = "return arguments[0].frozen";
115+
116+
117+
new WebDriverWait(getDriver(), Duration.of(2, SECONDS))
118+
.until(ExpectedConditions.attributeContains(selectionColElement, "frozen", "false"));
119+
120+
// assert that the selection column is not frozen by default
121+
assertFalse("Selection column is frozen", (Boolean) executeScript(frozen, selectionColElement));
122+
123+
// make selection column frozen
124+
selectionColElement.setProperty("frozen", true);
125+
126+
new WebDriverWait(getDriver(), Duration.of(2, SECONDS))
127+
.until(ExpectedConditions.attributeContains(selectionColElement, "frozen", "true"));
128+
129+
// assert that the selection column is now frozen
130+
assertTrue("Selection column is not frozen",
131+
(Boolean) executeScript(frozen, selectionColElement));
132+
}
133+
134+
}

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/IntegrationView.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.flowingcode.vaadin.addons.gridhelpers.it;
2121

2222
import com.flowingcode.vaadin.addons.gridhelpers.GridHelper;
23+
import com.flowingcode.vaadin.addons.gridhelpers.GridRadioSelectionColumn;
2324
import com.flowingcode.vaadin.addons.gridhelpers.Person;
2425
import com.flowingcode.vaadin.addons.gridhelpers.TestData;
2526
import com.flowingcode.vaadin.testbench.rpc.JsonArrayList;
@@ -178,4 +179,9 @@ public void setHeaderVisible(boolean visible) {
178179
public void setFooterVisible(boolean visible) {
179180
grid.setFooterVisible(visible);
180181
}
182+
183+
@Override
184+
public void showRadioSelectionColumn() {
185+
grid.showRadioSelectionColumn();
186+
}
181187
}

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/it/IntegrationViewCallables.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ public interface IntegrationViewCallables extends RmiCallable {
5959

6060
void setFooterVisible(boolean visible);
6161

62+
void showRadioSelectionColumn();
6263
}

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/GridHelperTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertFalse;
24+
import static org.junit.Assert.assertNotNull;
2425
import static org.junit.Assert.assertNull;
2526
import static org.junit.Assert.assertTrue;
2627
import com.flowingcode.vaadin.addons.gridhelpers.GridHelper;
@@ -190,4 +191,9 @@ public void testMenuToggleColumn() {
190191
assertTrue(GridHelper.isMenuToggleColumn(toggleColumn));
191192
}
192193

194+
@Test
195+
public void testShowRadioSelectionColumn() {
196+
assertNotNull(grid.showRadioSelectionColumn());
197+
}
198+
193199
}

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/SerializationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public void testSerialization() throws ClassNotFoundException, IOException {
4848
try {
4949
Grid<?> grid = new Grid<>();
5050
GridHelper.setColumnToggleVisible(grid, false);
51+
GridHelper.showRadioSelectionColumn(grid);
5152
testSerializationOf(grid);
5253
} catch (Exception e) {
5354
Assert.fail("Problem while testing serialization: " + e.getMessage());

0 commit comments

Comments
 (0)