From b6fda7481f0be3a0b94dde3e7f659a0b211d3943 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 13 Jan 2015 16:35:16 +0200 Subject: Add screenshot tests for Grid sorting indicators Change-Id: I7a4b13c0b1726e49a0479d69214bd0c51c39ac7d --- .../grid/basicfeatures/GridSortingIndicators.java | 65 ++++++++++++++++++++++ .../basicfeatures/GridSortingIndicatorsTest.java | 39 +++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.java new file mode 100644 index 0000000000..6d602baf06 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.java @@ -0,0 +1,65 @@ +/* + * 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 com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.sort.Sort; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Grid; + +public class GridSortingIndicators extends AbstractTestUI { + + private static int FOO_MIN = 4; + private static int BAR_MULTIPLIER = 3; + private static int BAZ_MAX = 132; + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(createContainer()); + addComponent(grid); + grid.sort(Sort.by("foo").then("bar", SortDirection.DESCENDING) + .then("baz")); + + addComponent(new Button("Reverse sorting", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.sort(Sort.by("baz", SortDirection.DESCENDING).then("bar") + .then("foo", SortDirection.DESCENDING)); + } + })); + } + + private Container.Indexed createContainer() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty("foo", Integer.class, 0); + container.addContainerProperty("bar", Integer.class, 0); + container.addContainerProperty("baz", Integer.class, 0); + for (int i = 0; i < 10; ++i) { + Item item = container.getItem(container.addItem()); + item.getItemProperty("foo").setValue(FOO_MIN + i); + item.getItemProperty("baz").setValue(BAZ_MAX - i); + item.getItemProperty("bar").setValue(BAR_MULTIPLIER * i); + } + return container; + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java new file mode 100644 index 0000000000..6a5360f152 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java @@ -0,0 +1,39 @@ +/* + * 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 java.io.IOException; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.annotations.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridSortingIndicatorsTest extends MultiBrowserTest { + + @Test + public void testSortingIndicators() throws IOException { + openTestURL(); + compareScreen("initialSort"); + + $(ButtonElement.class).first().click(); + + compareScreen("reversedSort"); + } + +} -- cgit v1.2.3