Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken method signature of Grid.addColumn (#8180)
Fixes #8129
- Loading branch information
Showing
4 changed files
with
92 additions
and
2 deletions.
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
22 changes: 22 additions & 0 deletions
22
uitest/src/main/java/com/vaadin/tests/components/grid/GridAddColumn.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
package com.vaadin.tests.components.grid; | |||
|
|||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.renderers.NumberRenderer; | |||
|
|||
public class GridAddColumn extends AbstractTestUI { | |||
|
|||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Grid<String> grid = new Grid<>(); | |||
grid.addColumn(ValueProvider.identity()); | |||
grid.addColumn(String::length, new NumberRenderer()); | |||
grid.addColumn(String::length); | |||
grid.addColumn(string -> -string.length()); | |||
grid.addColumn(string -> new Object()); | |||
grid.setItems("a", "aa", "aaa"); | |||
addComponent(grid); | |||
} | |||
} |
68 changes: 68 additions & 0 deletions
68
uitest/src/test/java/com/vaadin/tests/components/grid/GridAddColumnTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
package com.vaadin.tests.components.grid; | |||
|
|||
import org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Test; | |||
|
|||
import com.vaadin.testbench.elements.GridElement; | |||
import com.vaadin.tests.tb3.SingleBrowserTest; | |||
|
|||
public class GridAddColumnTest extends SingleBrowserTest { | |||
|
|||
GridElement grid; | |||
|
|||
@Before | |||
public void init() { | |||
openTestURL(); | |||
grid = $(GridElement.class).first(); | |||
} | |||
|
|||
@Test | |||
public void columns_rendered_correctly() { | |||
assertCellEquals(0, 0, "a"); | |||
assertCellEquals(1, 0, "aa"); | |||
assertCellEquals(2, 0, "aaa"); | |||
|
|||
assertCellEquals(0, 1, "1"); | |||
assertCellEquals(1, 1, "2"); | |||
assertCellEquals(2, 1, "3"); | |||
|
|||
assertCellEquals(0, 2, "1"); | |||
assertCellEquals(1, 2, "2"); | |||
assertCellEquals(2, 2, "3"); | |||
|
|||
assertCellEquals(0, 3, "-1"); | |||
assertCellEquals(1, 3, "-2"); | |||
assertCellEquals(2, 3, "-3"); | |||
|
|||
assertCellStartsWith(0, 4, "java.lang.Object@"); | |||
assertCellStartsWith(1, 4, "java.lang.Object@"); | |||
assertCellStartsWith(2, 4, "java.lang.Object@"); | |||
} | |||
|
|||
@Test | |||
@Ignore // TODO re-enable once #8128 is resolved | |||
public void sort_column_with_automatic_conversion() { | |||
grid.getHeaderCell(0, 2).click(); | |||
assertCellEquals(0, 0, "a"); | |||
assertCellEquals(1, 0, "aa"); | |||
assertCellEquals(2, 0, "aaa"); | |||
|
|||
grid.getHeaderCell(0, 3).click(); | |||
assertCellEquals(0, 0, "aaa"); | |||
assertCellEquals(1, 0, "aa"); | |||
assertCellEquals(2, 0, "a"); | |||
} | |||
|
|||
private void assertCellEquals(int rowIndex, int colIndex, String content) { | |||
Assert.assertEquals("Cell text should equal", content, | |||
grid.getCell(rowIndex, colIndex).getText()); | |||
} | |||
|
|||
private void assertCellStartsWith(int rowIndex, int colIndex, | |||
String startsWith) { | |||
Assert.assertTrue("Cell text should start with", grid | |||
.getCell(rowIndex, colIndex).getText().startsWith(startsWith)); | |||
} | |||
} |