2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.v7.tests.components.grid.basicfeatures.client;
18 import java.util.List;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebElement;
25 import com.vaadin.v7.testbench.customelements.GridElement;
26 import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
28 public class GridSidebarContentTest extends GridBasicClientFeaturesTest {
31 public void testSidebarWithHidableColumn() {
34 Assert.assertEquals("Sidebar should not be initially present", 0,
35 countBySelector(".v-grid-sidebar-button"));
37 selectMenuPath("Component", "Columns", "Column 0", "Hidable");
39 getSidebarOpenButton().click();
41 WebElement toggle = getSidebarPopup()
42 .findElement(By.className("column-hiding-toggle"));
44 Assert.assertEquals("Column 0 should be togglable", "Header (0,0)",
47 selectMenuPath("Component", "Columns", "Column 0", "Hidable");
48 Assert.assertEquals("Sidebar should disappear without toggable column",
49 0, countBySelector(".v-grid-sidebar-button"));
54 public void testAddingCustomSidebarItem() {
56 GridElement gridElement = getGridElement();
58 selectMenuPath("Component", "Sidebar", "Add item to end");
60 gridElement.findElement(By.className("v-grid-sidebar-button")).click();
62 WebElement sidebarItem = getSidebarPopup().findElement(
63 By.cssSelector(".v-grid-sidebar-content .gwt-MenuItem"));
67 Assert.assertEquals("Sidebar should be closed after clicking item 0", 0,
68 countBySelector(".v-grid-sidebar-content"));
72 public void testProgrammaticSidebarOpen() {
75 selectMenuPath("Component", "Columns", "Column 0", "Hidable");
77 selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
79 Assert.assertEquals("Sidebar should be open", 1,
80 countBySelector(".v-grid-sidebar-content"));
84 public void testBasicSidebarOrder() {
87 // First add custom content
88 selectMenuPath("Component", "Sidebar", "Add separator to end");
89 selectMenuPath("Component", "Sidebar", "Add item to end");
91 // Then make one column togglable
92 selectMenuPath("Component", "Columns", "Column 0", "Hidable");
94 selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
96 assertSidebarMenuItems("Header (0,0)", null, "Custom menu item 0");
100 public void testSidebarOrderAbuse() {
103 selectMenuPath("Component", "Columns", "Column 0", "Hidable");
104 selectMenuPath("Component", "Columns", "Column 1", "Hidable");
106 // Inserts a menu item between the two visibility toggles
107 selectMenuPath("Component", "Sidebar", "Add item before index 1");
109 selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
111 // Total order enforcement not implemented at this point. Test can be
112 // updated when it is.
113 assertSidebarMenuItems("Header (0,0)", "Custom menu item 0",
116 selectMenuPath("Component", "Columns", "Column 2", "Hidable");
117 selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
119 // Adding a new togglable column should have restored the expected order
120 assertSidebarMenuItems("Header (0,0)", "Header (0,1)", "Header (0,2)",
121 "Custom menu item 0");
124 private void assertSidebarMenuItems(String... items) {
125 List<WebElement> menuItems = getSidebarPopup()
126 .findElements(By.cssSelector(".v-grid-sidebar-content td"));
128 Assert.assertEquals("Expected " + items.length + " menu items",
129 items.length, menuItems.size());
131 for (int i = 0; i < items.length; i++) {
132 String expectedItem = items[i];
133 if (expectedItem == null) {
134 Assert.assertEquals("Item " + i + " should be a separator",
135 "gwt-MenuItemSeparator",
136 menuItems.get(i).getAttribute("class"));
138 Assert.assertEquals("Unexpected content for item " + i,
139 expectedItem, menuItems.get(i).getText());
144 private int countBySelector(String cssSelector) {
145 return findElements(By.cssSelector(cssSelector)).size();