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.tests.components.grid.basicfeatures.escalator;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
25 import org.junit.Test;
26 import org.openqa.selenium.WebElement;
28 import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest;
30 public class EscalatorColumnFreezingTest
31 extends EscalatorBasicClientFeaturesTest {
33 private final static Pattern TRANSFORM_PATTERN = Pattern.compile(// @formatter:off
34 // any start of the string
37 // non-capturing group for "webkitTransform: " or "transform: "
38 + "(?:webkitT|t)ransform: "
40 // non-capturing group for "translate" or "translate3d"
43 // capturing the digits in e.g "(100px,"
46 // any end of the string
47 + ".*", Pattern.CASE_INSENSITIVE);
51 private final static Pattern LEFT_PATTERN = Pattern
52 .compile(".*left: (\\d+)px.*", Pattern.CASE_INSENSITIVE);
54 private static final int NO_FREEZE = -1;
57 public void testNoFreeze() {
61 WebElement bodyCell = getBodyCell(0, 0);
62 assertFalse(isFrozen(bodyCell));
63 assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell));
67 public void testOneFreeze() {
71 selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN);
73 scrollHorizontallyTo(scrollPx);
75 WebElement bodyCell = getBodyCell(0, 0);
76 assertTrue(isFrozen(bodyCell));
77 assertEquals(scrollPx, getFrozenScrollCompensation(bodyCell));
81 public void testFreezeToggle() {
85 selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN);
86 scrollHorizontallyTo(100);
87 selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_0_COLUMNS);
89 WebElement bodyCell = getBodyCell(0, 0);
90 assertFalse(isFrozen(bodyCell));
91 assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell));
94 private static boolean isFrozen(WebElement cell) {
95 return cell.getAttribute("class").contains("frozen");
98 private static int getFrozenScrollCompensation(WebElement cell) {
99 String styleAttribute = cell.getAttribute("style");
100 Matcher transformMatcher = TRANSFORM_PATTERN.matcher(styleAttribute);
101 Matcher leftMatcher = LEFT_PATTERN.matcher(styleAttribute);
103 if (transformMatcher.find()) {
104 return Integer.parseInt(transformMatcher.group(1));
105 } else if (leftMatcher.find()) {
106 return Integer.parseInt(leftMatcher.group(1));