]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert "Fix Push inserts producing duplicate rows in Table (#13562)"
authorSauli Tähkäpää <sauli@vaadin.com>
Mon, 26 May 2014 07:56:50 +0000 (10:56 +0300)
committerSauli Tähkäpää <sauli@vaadin.com>
Mon, 26 May 2014 08:12:05 +0000 (11:12 +0300)
This reverts commit ce1764fb1bad1b82462d73fbfe293b676c2a9c00.

Change-Id: I897e0f3a0876eaea4b68f0e3b75671ccb1398242

server/src/com/vaadin/ui/Table.java
uitest/src/com/vaadin/tests/components/table/ContainerSizeChange.html [deleted file]
uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java [new file with mode: 0644]

index 29dc52a9a6532df4ee1791a13c7e5b513cba8691..b4d79f304c846d96f445cf3197e4c6d9dad4b648 100644 (file)
@@ -2954,23 +2954,15 @@ public class Table extends AbstractSelect implements Action.Container,
             // (row caches emptied by other event)
             if (!containerChangeToBeRendered) {
                 Integer value = (Integer) variables.get("reqfirstrow");
-                int tableSize = size();
                 if (value != null) {
                     reqFirstRowToPaint = value.intValue();
-                    // Sanity check
-                    if (reqFirstRowToPaint < 0) {
-                        reqFirstRowToPaint = -1;
-                    }
-                    if (reqFirstRowToPaint >= tableSize) {
-                        reqFirstRowToPaint = tableSize - 1;
-                    }
                 }
                 value = (Integer) variables.get("reqrows");
                 if (value != null) {
                     reqRowsToPaint = value.intValue();
                     // sanity check
-                    if (reqFirstRowToPaint + reqRowsToPaint > tableSize) {
-                        reqRowsToPaint = tableSize - reqFirstRowToPaint;
+                    if (reqFirstRowToPaint + reqRowsToPaint > size()) {
+                        reqRowsToPaint = size() - reqFirstRowToPaint;
                     }
                 }
             }
diff --git a/uitest/src/com/vaadin/tests/components/table/ContainerSizeChange.html b/uitest/src/com/vaadin/tests/components/table/ContainerSizeChange.html
deleted file mode 100644 (file)
index 7c2374f..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="" />
-<title>ContainerSizeChange</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">ContainerSizeChange</td></tr>
-</thead><tbody>
-<tr>
-       <td>open</td>
-       <td>/run/com.vaadin.tests.components.table.ContainerSizeChange</td>
-       <td></td>
-</tr>
-<tr>
-       <td>waitForVaadin</td>
-       <td></td>
-       <td></td>
-</tr>
-<tr>
-       <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentstableContainerSizeChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>waitForVaadin</td>
-       <td></td>
-       <td></td>
-</tr>
-<tr>
-       <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentstableContainerSizeChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>waitForVaadin</td>
-       <td></td>
-       <td></td>
-</tr>
-<tr>
-       <td>scroll</td>
-       <td>vaadin=runcomvaadintestscomponentstableContainerSizeChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]</td>
-       <td>945</td>
-</tr>
-<tr>
-       <td>pause</td>
-       <td>300</td>
-       <td></td>
-</tr>
-<tr>
-       <td>waitForVaadin</td>
-       <td></td>
-       <td></td>
-</tr>
-<tr>
-       <td>scroll</td>
-       <td>vaadin=runcomvaadintestscomponentstableContainerSizeChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]</td>
-       <td>525</td>
-</tr>
-<tr>
-       <td>pause</td>
-       <td>300</td>
-       <td></td>
-</tr>
-<tr>
-       <td>waitForVaadin</td>
-       <td></td>
-       <td></td>
-</tr>
-<tr>
-       <td>screenCapture</td>
-       <td></td>
-       <td></td>
-</tr>
-
-</tbody></table>
-</body>
-</html>
diff --git a/uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java b/uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java
new file mode 100644 (file)
index 0000000..a866e4a
--- /dev/null
@@ -0,0 +1,53 @@
+package com.vaadin.tests.components.table;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import junit.framework.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.openqa.selenium.NoSuchElementException;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class ContainerSizeChangeTest extends MultiBrowserTest {
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    @Test
+    public void tableShouldLoadCorrectItems() throws IOException, InterruptedException {
+        openTestURL();
+
+        ButtonElement decreaseSize = $(ButtonElement.class).caption("Decrease size").first();
+        decreaseSize.click(); //decreasing container size from 50 to 40
+        decreaseSize.click(); //decreasing container size from 40 to 30
+
+        TableElement table = $(TableElement.class).first();
+        //TableElement scroll not working properly, so we need to do this. http://dev.vaadin.com/ticket/13826
+        testBenchElement(table.findElement(By.className("v-scrollable"))).scroll(1000);
+
+        //waitforvaadin not worky currently for table scroll, so we need to use thread sleep :(
+        Thread.sleep(1000);
+
+        assertThatRowExists(table, 29);
+        assertRowDoesNotExist(table, 30);
+    }
+
+    private void assertThatRowExists(TableElement table, int rowIndex) {
+        assertThat(table.getCell(rowIndex, 0).getText(), is(String.format("a %s", rowIndex)));
+    }
+
+    private void assertRowDoesNotExist(TableElement table, int rowIndex) {
+        //This is a really crappy way to workaround JUnit's limitation to provide a proper assert.throws method...
+        thrown.expect(NoSuchElementException.class);
+        table.getCell(rowIndex, 0);
+
+        Assert.fail(String.format("Row %s should not exists.", rowIndex));
+    }
+}