From e3fe530dcefbdb7fa5ef7492302d3c1a58443501 Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Wed, 10 Sep 2014 16:14:27 +0300 Subject: [PATCH] Tests Escalator's column spans (#13334) Change-Id: I3378f6b9bed4ee917c2244904ad07b5d38711ca2 --- .../EscalatorBasicClientFeaturesTest.java | 5 + .../basicfeatures/EscalatorColspanTest.java | 91 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java index 4593e40155..c7fb66fa0d 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -45,6 +45,11 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest protected static final String CLEAR_COLUMN_ROW = "Clear (columns, then rows)"; protected static final String CLEAR_ROW_COLUMN = "Clear (rows, then columns)"; + protected static final String FEATURES = "Features"; + protected static final String COLUMN_SPANNING = "Column spanning"; + protected static final String COLSPAN_NORMAL = "Apply normal colspan"; + protected static final String COLSPAN_NONE = "Apply no colspan"; + @Override protected Class getUIClass() { return EscalatorBasicClientFeatures.class; diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java new file mode 100644 index 0000000000..8cbba35faa --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java @@ -0,0 +1,91 @@ +/* + * 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 org.junit.Test; +import org.openqa.selenium.WebElement; + +public class EscalatorColspanTest extends EscalatorBasicClientFeaturesTest { + private static final int NO_COLSPAN = 1; + + @Test + public void testNoColspan() { + openTestURL(); + populate(); + + assertEquals(NO_COLSPAN, getColSpan(getHeaderCell(0, 0))); + assertEquals(NO_COLSPAN, getColSpan(getBodyCell(0, 0))); + assertEquals(NO_COLSPAN, getColSpan(getFooterCell(0, 0))); + } + + @Test + public void testColspan() { + openTestURL(); + populate(); + + int singleCellWidth = getWidth(getBodyCell(0, 0)); + int doubleCellWidth = singleCellWidth * 2; + + selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL); + + WebElement bodyCell = getBodyCell(0, 0); + assertEquals(2, getColSpan(bodyCell)); + assertEquals(doubleCellWidth, getWidth(bodyCell)); + } + + @Test + public void testColspanToggle() { + openTestURL(); + populate(); + + int singleCellWidth = getWidth(getBodyCell(0, 0)); + + selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL); + selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NONE); + + WebElement bodyCell = getBodyCell(0, 0); + assertEquals(NO_COLSPAN, getColSpan(bodyCell)); + assertEquals(singleCellWidth, getWidth(bodyCell)); + } + + private static int getWidth(WebElement element) { + String widthString = element.getCssValue("width"); // e.g. 100px + if ("0".equals(widthString)) { + return 0; + } else if (widthString.endsWith("px")) { + return Integer.parseInt(widthString.substring(0, + widthString.length() - 2)); + } else { + throw new IllegalStateException("Element width expressed " + + "in an unsupported format: " + widthString); + } + } + + private static int getColSpan(WebElement cell) { + String attribute = cell.getAttribute("colspan"); + if (attribute == null) { + return NO_COLSPAN; + } else { + return Integer.parseInt(attribute); + } + } + + private void populate() { + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + } +} -- 2.39.5