Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduce frozen columns and height by rows to Grid
Change-Id: I5fecfabd023b39dc252e47a6aa403a79034b0f3d
- Loading branch information
Showing
6 changed files
with
333 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ests/components/grid/GridDetailsTest.java → ...erver/component/grid/GridDetailsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.vaadin.tests.server.component.grid; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.shared.ui.grid.HeightMode; | ||
import com.vaadin.ui.Grid; | ||
|
||
public class GridTest { | ||
|
||
private Grid<String> grid; | ||
|
||
@Before | ||
public void setUp() { | ||
grid = new Grid<>(); | ||
grid.addColumn("foo", String.class, Function.identity()); | ||
} | ||
|
||
@Test | ||
public void testGridHeightModeChange() { | ||
assertEquals("Initial height mode was not CSS", HeightMode.CSS, | ||
grid.getHeightMode()); | ||
grid.setHeightByRows(13.24); | ||
assertEquals("Setting height by rows did not change height mode", | ||
HeightMode.ROW, grid.getHeightMode()); | ||
grid.setHeight("100px"); | ||
assertEquals("Setting height did not change height mode.", | ||
HeightMode.CSS, grid.getHeightMode()); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testFrozenColumnCountTooBig() { | ||
grid.setFrozenColumnCount(2); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testFrozenColumnCountTooSmall() { | ||
grid.setFrozenColumnCount(-2); | ||
} | ||
|
||
@Test() | ||
public void testSetFrozenColumnCount() { | ||
for (int i = -1; i < 2; ++i) { | ||
grid.setFrozenColumnCount(i); | ||
assertEquals("Frozen column count not updated", i, | ||
grid.getFrozenColumnCount()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicStructureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2000-2016 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.tests.components.grid.basics; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import com.vaadin.testbench.TestBenchElement; | ||
|
||
public class GridBasicStructureTest extends GridBasicsTest { | ||
|
||
@Test | ||
public void testFreezingColumn() throws Exception { | ||
// Freeze column 1 | ||
selectMenuPath("Component", "State", "Frozen column count", "1"); | ||
|
||
WebElement cell = getGridElement().getCell(0, 0); | ||
assertTrue("First cell on a row should be frozen", | ||
cell.getAttribute("class").contains("frozen")); | ||
|
||
assertFalse("Second cell on a row should not be frozen", | ||
getGridElement().getCell(0, 1).getAttribute("class") | ||
.contains("frozen")); | ||
|
||
int cellX = cell.getLocation().getX(); | ||
scrollGridHorizontallyTo(100); | ||
assertEquals("First cell should not move when scrolling", cellX, | ||
cell.getLocation().getX()); | ||
} | ||
|
||
@Test | ||
public void testHeightByRows() throws Exception { | ||
int initialHeight = getGridElement().getSize().getHeight(); | ||
|
||
selectMenuPath("Component", "Size", "HeightMode Row"); | ||
selectMenuPath("Component", "Size", "Height by Rows", "2.00 rows"); | ||
|
||
TestBenchElement tableWrapper = getGridElement().getTableWrapper(); | ||
int rowHeight = getGridElement().getRow(0).getSize().getHeight(); | ||
|
||
assertTrue("Grid height was not 3 rows", Math | ||
.abs(rowHeight * 3 - tableWrapper.getSize().getHeight()) < 2); | ||
|
||
selectMenuPath("Component", "Size", "Height by Rows", "3.33 rows"); | ||
|
||
assertTrue("Grid height was not 4.33 rows", Math.abs( | ||
rowHeight * 4.33 - tableWrapper.getSize().getHeight()) < 2); | ||
|
||
selectMenuPath("Component", "Size", "HeightMode Row"); | ||
assertEquals("Grid should have returned to its original size", | ||
initialHeight, getGridElement().getSize().getHeight()); | ||
} | ||
|
||
@Test | ||
public void testHeightModeChanges() throws Exception { | ||
selectMenuPath("Component", "Size", "Height by Rows", "2.00 rows"); | ||
|
||
TestBenchElement tableWrapper = getGridElement().getTableWrapper(); | ||
int rowHeight = getGridElement().getRow(0).getSize().getHeight(); | ||
|
||
assertTrue("Grid height mode did not become ROW", Math | ||
.abs(rowHeight * 3 - tableWrapper.getSize().getHeight()) < 2); | ||
|
||
selectMenuPath("Component", "Size", "Height", "200px"); | ||
|
||
assertEquals("Grid height mode did not become CSS", 200, | ||
getGridElement().getSize().getHeight()); | ||
|
||
} | ||
} |