aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2014-08-06 14:38:11 +0300
committerVaadin Code Review <review@vaadin.com>2014-08-11 11:03:34 +0000
commit2ae0ff76032d5160c9bc9a7549a1c05c1434d800 (patch)
tree4d160731bd26d6f40ef423c15381ad90e3ef1866
parentf72de364596683e83405fe1b1ded0374c3a1e96b (diff)
downloadvaadin-framework-2ae0ff76032d5160c9bc9a7549a1c05c1434d800.tar.gz
vaadin-framework-2ae0ff76032d5160c9bc9a7549a1c05c1434d800.zip
Ensure primary stylenames are correct #13334
Change-Id: If8c220d70a1537006a042be25b36bf880209268d
-rw-r--r--client/src/com/vaadin/client/ui/grid/Grid.java6
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridElement.java81
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java8
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java3
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStructureTest.java51
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStylingTest.java118
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java28
7 files changed, 254 insertions, 41 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java
index d5582e0202..395d510ec4 100644
--- a/client/src/com/vaadin/client/ui/grid/Grid.java
+++ b/client/src/com/vaadin/client/ui/grid/Grid.java
@@ -1217,6 +1217,12 @@ public class Grid<T> extends Composite implements
cellActiveStyleName = getStylePrimaryName() + "-cell-active";
headerFooterActiveStyleName = getStylePrimaryName() + "-header-active";
rowActiveStyleName = getStylePrimaryName() + "-row-active";
+
+ if (isAttached()) {
+ refreshHeader();
+ refreshBody();
+ refreshFooter();
+ }
}
/**
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridElement.java b/uitest/src/com/vaadin/tests/components/grid/GridElement.java
index 3b28c4eaa2..bd8cad45c6 100644
--- a/uitest/src/com/vaadin/tests/components/grid/GridElement.java
+++ b/uitest/src/com/vaadin/tests/components/grid/GridElement.java
@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebElement;
import com.vaadin.testbench.By;
import com.vaadin.testbench.TestBenchElement;
@@ -186,6 +187,85 @@ public class GridElement extends AbstractComponentElement {
}
/**
+ * Get a header row by index
+ *
+ * @param rowIndex
+ * Row index
+ * @return The th element of the row
+ */
+ public WebElement getHeaderRow(int rowIndex) {
+ return getSubPart("#header[" + rowIndex + "]");
+ }
+
+ /**
+ * Get a footer row by index
+ *
+ * @param rowIndex
+ * Row index
+ * @return The tr element of the row
+ */
+ public WebElement getFooterRow(int rowIndex) {
+ return getSubPart("#footer[" + rowIndex + "]");
+ }
+
+ /**
+ * Get the vertical scroll element
+ *
+ * @return The element representing the vertical scrollbar
+ */
+ public WebElement getVerticalScroller() {
+ List<WebElement> rootElements = findElements(By.xpath("./div"));
+ return rootElements.get(0);
+ }
+
+ /**
+ * Get the horizontal scroll element
+ *
+ * @return The element representing the horizontal scrollbar
+ */
+ public WebElement getHorizontalScroller() {
+ List<WebElement> rootElements = findElements(By.xpath("./div"));
+ return rootElements.get(1);
+ }
+
+ /**
+ * Get the header element
+ *
+ * @return The thead element
+ */
+ public WebElement getHeader() {
+ return getSubPart("#header");
+ }
+
+ /**
+ * Get the body element
+ *
+ * @return the tbody element
+ */
+ public WebElement getBody() {
+ return getSubPart("#cell");
+ }
+
+ /**
+ * Get the footer element
+ *
+ * @return the tfoot element
+ */
+ public WebElement getFooter() {
+ return getSubPart("#footer");
+ }
+
+ /**
+ * Get the element wrapping the table element
+ *
+ * @return The element that wraps the table element
+ */
+ public WebElement getTableWrapper() {
+ List<WebElement> rootElements = findElements(By.xpath("./div"));
+ return rootElements.get(2);
+ }
+
+ /**
* Helper function to get Grid subparts wrapped correctly
*
* @param subPartSelector
@@ -195,4 +275,5 @@ public class GridElement extends AbstractComponentElement {
private TestBenchElement getSubPart(String subPartSelector) {
return (TestBenchElement) findElement(By.vaadin(subPartSelector));
}
+
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java
index 559457ea1c..a8a2d4f12e 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java
@@ -20,8 +20,6 @@ import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
-import com.vaadin.testbench.TestBenchElement;
-import com.vaadin.tests.components.grid.GridElement;
import com.vaadin.tests.widgetset.server.grid.GridBasicClientFeatures;
/**
@@ -38,12 +36,6 @@ public abstract class GridBasicClientFeaturesTest extends GridBasicFeaturesTest
}
@Override
- protected GridElement getGridElement() {
- return ((TestBenchElement) findElement(By.className("v-grid")))
- .wrap(GridElement.class);
- }
-
- @Override
protected void selectMenu(String menuCaption) {
WebElement menuElement = getMenuElement(menuCaption);
Dimension size = menuElement.getSize();
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
index 94d9766f78..6ef0ab5006 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
@@ -65,7 +65,8 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest {
}
protected GridElement getGridElement() {
- return $(GridElement.class).id("testComponent");
+ return ((TestBenchElement) findElement(By.id("testComponent")))
+ .wrap(GridElement.class);
}
protected void scrollGridVerticallyTo(double px) {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStructureTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStructureTest.java
index d52f512b4f..9adc4fa8a4 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStructureTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStructureTest.java
@@ -78,7 +78,7 @@ public class GridStructureTest extends GridBasicFeaturesTest {
sleep(1000);
// Check that row is loaded
- assertThat(getBodyCellByRowAndColumn(11, 0).getText(), not("..."));
+ assertThat(getGridElement().getCell(11, 0).getText(), not("..."));
}
@Test
@@ -88,10 +88,10 @@ public class GridStructureTest extends GridBasicFeaturesTest {
// Freeze column 2
selectMenuPath("Component", "Columns", "Column 2", "Freeze");
- WebElement cell = getBodyCellByRowAndColumn(0, 0);
+ WebElement cell = getGridElement().getCell(0, 0);
assertTrue(cell.getAttribute("class").contains("frozen"));
- cell = getBodyCellByRowAndColumn(0, 1);
+ cell = getGridElement().getCell(0, 1);
assertTrue(cell.getAttribute("class").contains("frozen"));
}
@@ -99,13 +99,13 @@ public class GridStructureTest extends GridBasicFeaturesTest {
public void testInitialColumnWidths() throws Exception {
openTestURL();
- WebElement cell = getBodyCellByRowAndColumn(0, 0);
+ WebElement cell = getGridElement().getCell(0, 0);
assertEquals(100, cell.getSize().getWidth());
- cell = getBodyCellByRowAndColumn(0, 1);
+ cell = getGridElement().getCell(0, 1);
assertEquals(150, cell.getSize().getWidth());
- cell = getBodyCellByRowAndColumn(0, 2);
+ cell = getGridElement().getCell(0, 2);
assertEquals(200, cell.getSize().getWidth());
}
@@ -114,27 +114,27 @@ public class GridStructureTest extends GridBasicFeaturesTest {
openTestURL();
// Default column width is 100px
- WebElement cell = getBodyCellByRowAndColumn(0, 0);
+ WebElement cell = getGridElement().getCell(0, 0);
assertEquals(100, cell.getSize().getWidth());
// Set first column to be 200px wide
selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
"200px");
- cell = getBodyCellByRowAndColumn(0, 0);
+ cell = getGridElement().getCell(0, 0);
assertEquals(200, cell.getSize().getWidth());
// Set second column to be 150px wide
selectMenuPath("Component", "Columns", "Column 1", "Column 1 Width",
"150px");
- cell = getBodyCellByRowAndColumn(0, 1);
+ cell = getGridElement().getCell(0, 1);
assertEquals(150, cell.getSize().getWidth());
// Set first column to be auto sized (defaults to 100px currently)
selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
"Auto");
- cell = getBodyCellByRowAndColumn(0, 0);
+ cell = getGridElement().getCell(0, 0);
assertEquals(100, cell.getSize().getWidth());
}
@@ -184,17 +184,17 @@ public class GridStructureTest extends GridBasicFeaturesTest {
openTestURL();
assertEquals("Unexpected cell initial state", "(0, 0)",
- getBodyCellByRowAndColumn(0, 0).getText());
+ getGridElement().getCell(0, 0).getText());
selectMenuPath("Component", "Body rows",
"Modify first row (getItemProperty)");
assertEquals("(First) modification with getItemProperty failed",
- "modified: 0", getBodyCellByRowAndColumn(0, 0).getText());
+ "modified: 0", getGridElement().getCell(0, 0).getText());
selectMenuPath("Component", "Body rows",
"Modify first row (getContainerProperty)");
assertEquals("(Second) modification with getItemProperty failed",
- "modified: Column 0", getBodyCellByRowAndColumn(0, 0).getText());
+ "modified: Column 0", getGridElement().getCell(0, 0).getText());
}
@Test
@@ -210,32 +210,19 @@ public class GridStructureTest extends GridBasicFeaturesTest {
private void assertPrimaryStylename(String stylename) {
assertTrue(getGridElement().getAttribute("class").contains(stylename));
- String tableWrapperStyleName = getTableWrapper().getAttribute("class");
+ String tableWrapperStyleName = getGridElement().getTableWrapper()
+ .getAttribute("class");
assertTrue(tableWrapperStyleName.contains(stylename + "-tablewrapper"));
- String hscrollStyleName = getHorizontalScroller().getAttribute("class");
+ String hscrollStyleName = getGridElement().getHorizontalScroller()
+ .getAttribute("class");
assertTrue(hscrollStyleName.contains(stylename + "-scroller"));
assertTrue(hscrollStyleName
.contains(stylename + "-scroller-horizontal"));
- String vscrollStyleName = getVerticalScroller().getAttribute("class");
+ String vscrollStyleName = getGridElement().getVerticalScroller()
+ .getAttribute("class");
assertTrue(vscrollStyleName.contains(stylename + "-scroller"));
assertTrue(vscrollStyleName.contains(stylename + "-scroller-vertical"));
}
-
- private WebElement getBodyCellByRowAndColumn(int row, int column) {
- return getGridElement().getCell(row, column);
- }
-
- private WebElement getVerticalScroller() {
- return getGridElement().findElement(By.xpath("./div[1]"));
- }
-
- private WebElement getHorizontalScroller() {
- return getGridElement().findElement(By.xpath("./div[2]"));
- }
-
- private WebElement getTableWrapper() {
- return getGridElement().findElement(By.xpath("./div[3]"));
- }
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStylingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStylingTest.java
new file mode 100644
index 0000000000..e6c37ebf9d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridStylingTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2000-2014 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.basicfeatures;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+
+public class GridStylingTest extends GridStaticSectionTest {
+
+ @Test
+ public void testGridPrimaryStyle() throws Exception {
+ openTestURL();
+
+ validateStylenames("v-grid");
+ }
+
+ @Test
+ public void testChangingPrimaryStyleName() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "State", "Primary Stylename",
+ "v-custom-style");
+
+ validateStylenames("v-custom-style");
+ }
+
+ private void validateStylenames(String stylename) {
+
+ String classNames = getGridElement().getAttribute("class");
+ assertEquals(stylename, classNames);
+
+ classNames = getGridElement().getVerticalScroller().getAttribute(
+ "class");
+ assertTrue(classNames.contains(stylename + "-scroller"));
+ assertTrue(classNames.contains(stylename + "-scroller-vertical"));
+
+ classNames = getGridElement().getHorizontalScroller().getAttribute(
+ "class");
+ assertTrue(classNames.contains(stylename + "-scroller"));
+ assertTrue(classNames.contains(stylename + "-scroller-horizontal"));
+
+ classNames = getGridElement().getTableWrapper().getAttribute("class");
+ assertEquals(stylename + "-tablewrapper", classNames);
+
+ classNames = getGridElement().getHeader().getAttribute("class");
+ assertEquals(stylename + "-header", classNames);
+
+ for (int row = 0; row < getGridElement().getHeaderCount(); row++) {
+ classNames = getGridElement().getHeaderRow(row).getAttribute(
+ "class");
+ assertEquals(stylename + "-row", classNames);
+
+ for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
+ classNames = getGridElement().getHeaderCell(row, col)
+ .getAttribute("class");
+ assertTrue(classNames.contains(stylename + "-cell"));
+
+ if (row == 0 && col == 0) {
+ assertTrue(classNames,
+ classNames.contains(stylename + "-header-active"));
+ }
+ }
+ }
+
+ classNames = getGridElement().getBody().getAttribute("class");
+ assertEquals(stylename + "-body", classNames);
+
+ int rowsInBody = getGridElement().getBody()
+ .findElements(By.tagName("tr")).size();
+ for (int row = 0; row < rowsInBody; row++) {
+ classNames = getGridElement().getRow(row).getAttribute("class");
+ assertTrue(classNames.contains(stylename + "-row"));
+ assertTrue(classNames.contains(stylename + "-row-has-data"));
+
+ for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
+ classNames = getGridElement().getCell(row, col).getAttribute(
+ "class");
+ assertTrue(classNames.contains(stylename + "-cell"));
+
+ if (row == 0 && col == 0) {
+ assertTrue(classNames.contains(stylename + "-cell-active"));
+ }
+ }
+ }
+
+ classNames = getGridElement().getFooter().getAttribute("class");
+ assertEquals(stylename + "-footer", classNames);
+
+ for (int row = 0; row < getGridElement().getFooterCount(); row++) {
+ classNames = getGridElement().getFooterRow(row).getAttribute(
+ "class");
+ assertEquals(stylename + "-row", classNames);
+
+ for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
+ classNames = getGridElement().getFooterCell(row, col)
+ .getAttribute("class");
+ assertTrue(classNames.contains(stylename + "-cell"));
+ }
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java
index 50f60f9847..6eac275a9a 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeatures.java
@@ -130,6 +130,7 @@ public class GridBasicClientFeatures extends
ds = new ListDataSource<List<Data>>(data);
grid = getTestedWidget();
+ grid.getElement().setId("testComponent");
grid.setDataSource(ds);
grid.setSelectionMode(SelectionMode.NONE);
@@ -240,6 +241,8 @@ public class GridBasicClientFeatures extends
private void createStateMenu() {
String[] selectionModePath = { "Component", "State", "Selection mode" };
+ String[] primaryStyleNamePath = { "Component", "State",
+ "Primary Stylename" };
addMenuCommand("multi", new ScheduledCommand() {
@Override
@@ -261,6 +264,31 @@ public class GridBasicClientFeatures extends
grid.setSelectionMode(SelectionMode.NONE);
}
}, selectionModePath);
+
+ addMenuCommand("v-grid", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setStylePrimaryName("v-grid");
+
+ }
+ }, primaryStyleNamePath);
+
+ addMenuCommand("v-escalator", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setStylePrimaryName("v-escalator");
+
+ }
+ }, primaryStyleNamePath);
+
+ addMenuCommand("v-custom-style", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setStylePrimaryName("v-custom-style");
+
+ }
+ }, primaryStyleNamePath);
+
}
private void createColumnsMenu() {