From eddc26904ab3bf3f7becb1d4f90428865735085d Mon Sep 17 00:00:00 2001 From: Guillermo Alvarez Date: Wed, 15 Oct 2014 15:33:18 +0300 Subject: Add missing tests (#12976) Adapted TB2 tests included in changeset number [26188] of Vaadin 6.8 SVN Change-Id: Ib935524538e06bd51acc01068df6ad86beba05fb --- .../components/table/UpdateTableWhenUnfocused.java | 67 ++++++++++++++++++++++ .../table/UpdateTableWhenUnfocusedTest.java | 53 +++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java create mode 100644 uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java diff --git a/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java new file mode 100644 index 0000000000..231375c2ea --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java @@ -0,0 +1,67 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.Table; + +public class UpdateTableWhenUnfocused extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final Table table = createTable(); + + TabSheet tabSheet = new TabSheet(); + tabSheet.addTab(table, "tab1"); + tabSheet.setHeight("5000px"); + tabSheet.setWidth("100%"); + addComponent(tabSheet); + + final Button button = new Button("Refresh table"); + button.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + button.focus(); + table.refreshRowCache(); + } + }); + addComponent(button); + + } + + private Table createTable() { + Table table = new Table("Table"); + table.setImmediate(true); + table.setMultiSelect(true); + table.setSizeFull(); + table.setSelectable(true); + + Container ds = new IndexedContainer(); + ds.addContainerProperty("column", Integer.class, null); + for (int i = 0; i < 500; i++) { + Item item = ds.addItem(i); + item.getItemProperty("column").setValue(i); + } + table.setContainerDataSource(ds); + + return table; + } + + @Override + protected String getTestDescription() { + return "Clicking the button after selecting a row in the table should not cause the window to scroll."; + } + + @Override + protected Integer getTicketNumber() { + return 12976; + } + +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java new file mode 100644 index 0000000000..fcd73f541d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java @@ -0,0 +1,53 @@ +/* + * 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.table; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; + +import org.junit.Test; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UpdateTableWhenUnfocusedTest extends MultiBrowserTest { + + @Test + public void testWindowIsNotScrolled() throws IOException { + openTestURL(); + + TestBenchElement cell = $(TableElement.class).first().getCell(3, 0); + cell.click(); + + TestBenchElement button = $(ButtonElement.class).first(); + button.focus(); + + int buttonLocation = button.getLocation().getY(); + + button.click(); + + int newButtonLocation = button.getLocation().getY(); + + assertThat( + "Button location has changed after table refresh, window has scrolled and it shouldn't have", + newButtonLocation, is(buttonLocation)); + + } +} -- cgit v1.2.3