|
| 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 | +} |
0 commit comments