]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix Components cleanup on Header/FooterRow remove in Grid (#19497)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Fri, 22 Jan 2016 12:23:55 +0000 (14:23 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 15 Feb 2016 15:11:45 +0000 (17:11 +0200)
Change-Id: Iaa36f2dd6a61487ec49da3adb4cc9a2485641cd9

server/src/com/vaadin/ui/Grid.java
uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java

index 06ab8d15817f6abd20ae3a5f7809938399f65a23..40746726754743e3c5457730d1fd8bda29cbfee2 100644 (file)
@@ -2467,6 +2467,12 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
             }
 
             abstract protected String getCellTagName();
+
+            void detach() {
+                for (CELLTYPE cell : cells.values()) {
+                    cell.detach();
+                }
+            }
         }
 
         /**
@@ -2674,6 +2680,10 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
                             .html()));
                 }
             }
+
+            void detach() {
+                removeComponentIfPresent();
+            }
         }
 
         protected Grid grid;
@@ -2720,6 +2730,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
                         + rowIndex);
             }
             ROWTYPE row = rows.remove(rowIndex);
+            row.detach();
             getSectionState().rows.remove(rowIndex);
 
             markAsDirty();
index 977b16cebd4d4745feee37b298ce7b2e64c73056..e8d3abf42dd017d5c128e897e2640ab018ad86f7 100644 (file)
  */
 package com.vaadin.tests.components.grid;
 
+import static org.junit.Assert.assertFalse;
+
 import java.util.List;
 
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
+import com.vaadin.testbench.By;
 import com.vaadin.testbench.elements.ButtonElement;
 import com.vaadin.testbench.elements.GridElement;
 import com.vaadin.testbench.elements.GridElement.GridCellElement;
@@ -28,9 +32,15 @@ import com.vaadin.tests.tb3.SingleBrowserTest;
 
 public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
 
+    @Before
+    public void setUp() {
+        setDebug(true);
+
+        openTestURL();
+    }
+
     @Test
     public void hideAndShowComponentsInHeader() {
-        openTestURL();
         GridElement grid = $(GridElement.class).first();
 
         int filterRow = 2;
@@ -48,6 +58,8 @@ public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
         textfield.setValue("foo");
         Assert.assertEquals("1. value change for field in string to foo",
                 getLogRow(0));
+
+        assertNoErrorNotifications();
     }
 
     private TextFieldElement getHeaderElement(GridElement grid, int row, int col) {
@@ -66,7 +78,6 @@ public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
 
     @Test
     public void hideAndShowComponentsInFooter() {
-        openTestURL();
         GridElement grid = $(GridElement.class).first();
 
         int filterRow = 0;
@@ -84,6 +95,8 @@ public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
         textfield.setValue("foo");
         Assert.assertEquals("1. value change for field in string to foo",
                 getLogRow(0));
+
+        assertNoErrorNotifications();
     }
 
     private TextFieldElement getFooterElement(GridElement grid, int row, int col) {
@@ -100,4 +113,28 @@ public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
         }
     }
 
+    @Test
+    public void testRemoveAllHeadersAndFooters() {
+        openTestURL();
+
+        for (int i = 2; i >= 0; --i) {
+            // Remove Header
+            $(GridElement.class).first().getHeaderCell(i, 0)
+                    .$(ButtonElement.class).first().click();
+            assertFalse(
+                    "Header " + i + " should not be present.",
+                    $(GridElement.class).first().isElementPresent(
+                            By.vaadin("#header[" + i + "]")));
+
+            // Remove Footer
+            $(GridElement.class).first().getFooterCell(i, 0)
+                    .$(ButtonElement.class).first().click();
+            assertFalse(
+                    "Footer " + i + " should not be present.",
+                    $(GridElement.class).first().isElementPresent(
+                            By.vaadin("#footer[" + i + "]")));
+        }
+
+        assertNoErrorNotifications();
+    }
 }