aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components
diff options
context:
space:
mode:
authorJarno Rantala <jarno.rantala@vaadin.com>2013-12-11 11:10:43 +0200
committerVaadin Code Review <review@vaadin.com>2014-01-07 08:41:21 +0000
commit0b95f8d6f6e3f278b51c0242e8ce2dfc82ed829e (patch)
tree6ef5846321221f1e10710ab0b7a2dc7d9737cca3 /uitest/src/com/vaadin/tests/components
parente9a547ac4e153f85597e056f5c51ade60fe29c45 (diff)
downloadvaadin-framework-0b95f8d6f6e3f278b51c0242e8ce2dfc82ed829e.tar.gz
vaadin-framework-0b95f8d6f6e3f278b51c0242e8ce2dfc82ed829e.zip
Moved selection of selected rows in TableConnector to occur after the new rows are created (#13008)
The selection of selected rows happened before the new rows were created. This resulted in situation where the visible items on server side were different than the rows in scrollbody during the selection of selected rows. Therefore, the selected keys in uidl contained wrong information and some selected rows was marked as unselected even though they shouldn't. This again resulted in the original bug that all the rows was not selected because the 'selectionRangeStart' row was not selected anymore. Change-Id: I9f985cb45c97bacb6b71e36fa4bf077a1ac1311d
Diffstat (limited to 'uitest/src/com/vaadin/tests/components')
-rw-r--r--uitest/src/com/vaadin/tests/components/table/SelectAllRows.java83
-rw-r--r--uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java105
2 files changed, 188 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/SelectAllRows.java b/uitest/src/com/vaadin/tests/components/table/SelectAllRows.java
new file mode 100644
index 0000000000..6007ea2984
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/SelectAllRows.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2000-2013 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 java.util.Set;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+public class SelectAllRows extends AbstractTestUI {
+
+ static final String TABLE = "table";
+ static final String COUNT_SELECTED_BUTTON = "button";
+ static final int TOTAL_NUMBER_OF_ROWS = 300;
+ static final String COUNT_OF_SELECTED_ROWS_LABEL = "label";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ VerticalLayout layout = new VerticalLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ setContent(layout);
+
+ final Table table = new Table();
+ table.setId(TABLE);
+ table.setImmediate(true);
+ table.setMultiSelect(true);
+ table.setSelectable(true);
+ table.addContainerProperty("row", String.class, null);
+ layout.addComponent(table);
+
+ Button button = new Button("Count");
+ button.setId(COUNT_SELECTED_BUTTON);
+ layout.addComponent(button);
+
+ final Label label = new Label();
+ label.setId(COUNT_OF_SELECTED_ROWS_LABEL);
+ label.setCaption("Selected count:");
+ layout.addComponent(label);
+
+ button.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ Set selected = (Set) table.getValue();
+ label.setValue(String.valueOf(selected.size()));
+ }
+ });
+
+ for (int i = 0; i < TOTAL_NUMBER_OF_ROWS; i++) {
+ Object itemId = table.addItem();
+ table.getContainerProperty(itemId, "row").setValue("row " + i);
+ }
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Selecting all rows does not work by selecting first row, press shift then select last row";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 13008;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java b/uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java
new file mode 100644
index 0000000000..664b36fa75
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/SelectAllRowsTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2000-2013 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 com.vaadin.tests.components.table.SelectAllRows.COUNT_OF_SELECTED_ROWS_LABEL;
+import static com.vaadin.tests.components.table.SelectAllRows.COUNT_SELECTED_BUTTON;
+import static com.vaadin.tests.components.table.SelectAllRows.TABLE;
+import static com.vaadin.tests.components.table.SelectAllRows.TOTAL_NUMBER_OF_ROWS;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class SelectAllRowsTest extends MultiBrowserTest {
+
+ private final static String TABLE_ROW = "v-table-row";
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // Pressing Shift modifier key does not work with TestBench and IE
+ // (#8621)
+ return Arrays.asList(Browser.FIREFOX.getDesiredCapabilities(),
+ Browser.CHROME.getDesiredCapabilities());
+ }
+
+ @Test
+ public void testAllRowsAreSelected() {
+ openTestURL();
+
+ selectAllRowsInTable();
+ int selectedRows = countSelectedItems();
+
+ assertEquals(TOTAL_NUMBER_OF_ROWS, selectedRows);
+ }
+
+ private int countSelectedItems() {
+ WebElement countButton = vaadinElementById(COUNT_SELECTED_BUTTON);
+ countButton.click();
+ WebElement countOfSelectedRows = vaadinElementById(COUNT_OF_SELECTED_ROWS_LABEL);
+ String count = countOfSelectedRows.getText();
+ return Integer.parseInt(count);
+ }
+
+ private void selectAllRowsInTable() {
+ clickFirstRow();
+ scrollTableToBottom();
+ new Actions(getDriver()).keyDown(Keys.SHIFT).perform();
+ clickLastRow();
+ new Actions(getDriver()).keyUp(Keys.SHIFT).perform();
+ }
+
+ private void clickLastRow() {
+ List<WebElement> rows = allVisibleTableRows();
+ WebElement lastRow = rows.get(rows.size() - 1);
+ lastRow.click();
+ }
+
+ private void clickFirstRow() {
+ WebElement firstRow = allVisibleTableRows().get(0);
+ firstRow.click();
+ }
+
+ private void scrollTableToBottom() {
+ WebElement table = vaadinElementById(TABLE);
+ testBenchElement(table.findElement(By.className("v-scrollable")))
+ .scroll(TOTAL_NUMBER_OF_ROWS * 30);
+
+ // Wait for scrolling to complete. Otherwise, clicking last row will
+ // fail with Chrome
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private List<WebElement> allVisibleTableRows() {
+ WebElement table = vaadinElementById(TABLE);
+ List<WebElement> rows = table.findElements(By
+ .cssSelector(".v-table-table tr"));
+ return rows;
+ }
+}