aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/com/vaadin')
-rw-r--r--uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRow.java167
-rw-r--r--uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRowTest.java104
2 files changed, 271 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRow.java b/uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRow.java
new file mode 100644
index 0000000000..d1d6edaa67
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRow.java
@@ -0,0 +1,167 @@
+/*
+ * 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;
+
+/**
+ *
+ * @author Vaadin Ltd
+ */
+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.ClickEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+/*
+ * 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.
+ */
+
+/**
+ *
+ * @author Vaadin Ltd
+ */
+@SuppressWarnings("serial")
+public class TableScrollAfterAddRow extends AbstractTestUI {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.UI#init(com.vaadin.server.VaadinRequest)
+ */
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ final int totalRows = 100;
+
+ final VerticalLayout layout = new VerticalLayout();
+
+ final IndexedContainer datasource = new IndexedContainer();
+
+ datasource.addContainerProperty("value", Integer.class, -1);
+ for (int i = 0; i < totalRows; i++) {
+ addRow(datasource);
+ }
+
+ final Table table = new Table();
+ table.setContainerDataSource(datasource);
+ layout.addComponent(table);
+ addComponent(layout);
+
+ final Label label = new Label("");
+ layout.addComponent(label);
+
+ NativeButton addRowButton = new NativeButton("Add row",
+ new NativeButton.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ addRow(datasource);
+ }
+ });
+
+ NativeButton jumpToLastRowButton = new NativeButton("Jump to last row",
+ new NativeButton.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ jumpToLastRow(table);
+ }
+ });
+ NativeButton jumpTo15thRowButton = new NativeButton("Jump to 15th row",
+ new NativeButton.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ jumpToFifteenthRow(table);
+ }
+ });
+ NativeButton jumpToFirstRowButton = new NativeButton(
+ "Jump to first row", new NativeButton.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ jumpToFirstRow(table);
+ }
+ });
+
+ NativeButton updateLabelButton = new NativeButton("UpdateLabel",
+ new NativeButton.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ label.setValue(Integer.toString(table
+ .getCurrentPageFirstItemIndex()));
+ }
+ });
+ layout.addComponent(addRowButton);
+ layout.addComponent(jumpToLastRowButton);
+ layout.addComponent(jumpTo15thRowButton);
+ layout.addComponent(jumpToFirstRowButton);
+ layout.addComponent(updateLabelButton);
+ }
+
+ private void jumpToFifteenthRow(Table table) {
+ table.setCurrentPageFirstItemIndex(14);
+ }
+
+ private void jumpToLastRow(Table table) {
+ int visibleRows = table.getContainerDataSource().size();
+ table.setCurrentPageFirstItemIndex(visibleRows - 1);
+ }
+
+ private void jumpToFirstRow(Table table) {
+ table.setCurrentPageFirstItemIndex(0);
+ }
+
+ private void addRow(IndexedContainer datasource) {
+ int rowNumber = datasource.size();
+ Item row = datasource.addItem(rowNumber);
+ row.getItemProperty("value").setValue(rowNumber);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
+ */
+ @Override
+ protected String getTestDescription() {
+ // TODO Auto-generated method stub
+ return "";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
+ */
+ @Override
+ protected Integer getTicketNumber() {
+ return 14147;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRowTest.java b/uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRowTest.java
new file mode 100644
index 0000000000..a020ace6b0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/TableScrollAfterAddRowTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.junit.Assert.assertEquals;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.commands.TestBenchCommandExecutor;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.screenshot.ImageComparison;
+import com.vaadin.testbench.screenshot.ReferenceNameGenerator;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ *
+ * @author Vaadin Ltd
+ */
+public class TableScrollAfterAddRowTest extends MultiBrowserTest {
+
+ @Before
+ public void init() {
+ openTestURL();
+ }
+
+ @Test
+ public void testJumpToFirstRow() {
+ jumpToFifteenthRow();
+ jumpToFirstRow();
+ assertEquals("0", getCurrentPageFirstItemIndex());
+ }
+
+ @Test
+ public void testAddRowAfterJumpToLastRow() throws InterruptedException {
+ jumpToLastRow();
+ addRow();
+ sleep(200);
+ assertEquals("85", getCurrentPageFirstItemIndex());
+ }
+
+ @Test
+ public void testAddRowAfterJumpingToLastRowAndScrollingUp()
+ throws InterruptedException {
+ jumpToLastRow();
+ scrollUp();
+ addRow();
+ sleep(200);
+ Assert.assertNotEquals("86", getCurrentPageFirstItemIndex());
+ }
+
+ private void scrollUp() {
+ WebElement actualElement = getDriver().findElement(
+ By.className("v-table-body-wrapper"));
+ JavascriptExecutor js = new TestBenchCommandExecutor(getDriver(),
+ new ImageComparison(), new ReferenceNameGenerator());
+ js.executeScript("arguments[0].scrollTop = " + 30, actualElement);
+ }
+
+ private String getCurrentPageFirstItemIndex() {
+ ButtonElement updateLabelButton = $(ButtonElement.class).get(4);
+ LabelElement label = $(LabelElement.class).get(1);
+ updateLabelButton.click();
+ return label.getText();
+ }
+
+ private void addRow() {
+ ButtonElement button = $(ButtonElement.class).get(0);
+ button.click();
+ }
+
+ private void jumpToFirstRow() {
+ ButtonElement button = $(ButtonElement.class).get(3);
+ button.click();
+ }
+
+ private void jumpToFifteenthRow() {
+ ButtonElement button = $(ButtonElement.class).get(2);
+ button.click();
+ }
+
+ private void jumpToLastRow() {
+ ButtonElement button = $(ButtonElement.class).get(1);
+ button.click();
+ }
+}
' href='#n672'>672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900