]> source.dussan.org Git - vaadin-framework.git/commitdiff
Testing Escalator (post|pre)(Attach|Detach) functionality (#13334)
authorHenrik Paul <henrik@vaadin.com>
Thu, 11 Sep 2014 11:59:22 +0000 (14:59 +0300)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 11 Sep 2014 13:12:32 +0000 (13:12 +0000)
Change-Id: If7a61560a96c5720b54bf3b5dcc83aef3ff7e357

uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUiTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java
uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorUpdaterTestConnector.java [new file with mode: 0644]

index c7fb66fa0dd312803a48980ad4dc982f1bfa30d3..5a282a15b62d1ff68d896767e3414fa71a19ac67 100644 (file)
@@ -15,7 +15,9 @@
  */
 package com.vaadin.tests.components.grid.basicfeatures;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.openqa.selenium.By;
 import org.openqa.selenium.Dimension;
@@ -34,6 +36,8 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest
     protected static final String COLUMNS = "Columns";
     protected static final String ADD_ONE_COLUMN_TO_BEGINNING = "Add one column to beginning";
     protected static final String ADD_ONE_ROW_TO_BEGINNING = "Add one row to beginning";
+    protected static final String REMOVE_ONE_COLUMN_FROM_BEGINNING = "Remove one column from beginning";
+    protected static final String REMOVE_ONE_ROW_FROM_BEGINNING = "Remove one row from beginning";
 
     protected static final String HEADER_ROWS = "Header Rows";
     protected static final String BODY_ROWS = "Body Rows";
@@ -133,9 +137,33 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest
     }
 
     protected void assertLogContains(String substring) {
+        assertTrue("log should've contained, but didn't: " + substring,
+                getLogText().contains(substring));
+    }
+
+    protected void assertLogDoesNotContain(String substring) {
+        assertFalse("log shouldn't have contained, but did: " + substring,
+                getLogText().contains(substring));
+    }
+
+    private String getLogText() {
         WebElement log = getDriver().findElement(By.cssSelector("#log"));
-        assertTrue("log did not contain: " + substring,
-                log.getText().contains(substring));
+        return log.getText();
+    }
+
+    protected void assertLogContainsInOrder(String... substrings) {
+        String log = getLogText();
+        int cursor = 0;
+        for (String substring : substrings) {
+            String remainingLog = log.substring(cursor, log.length());
+            int substringIndex = remainingLog.indexOf(substring);
+            if (substringIndex == -1) {
+                fail("substring \"" + substring
+                        + "\" was not found in order from log.");
+            }
+
+            cursor += substringIndex + substring.length();
+        }
     }
 
     protected void scrollVerticallyTo(int px) {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java
new file mode 100644 (file)
index 0000000..7e822e4
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.grid.basicfeatures;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.UI;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class EscalatorUpdaterUi extends UI {
+
+    public class EscalatorUpdaterTestComponent extends AbstractComponent {
+        // empty
+    }
+
+    @Override
+    protected void init(VaadinRequest request) {
+        setContent(new EscalatorUpdaterTestComponent());
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUiTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUiTest.java
new file mode 100644 (file)
index 0000000..c1c3a31
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * 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.grid.basicfeatures;
+
+import org.junit.Test;
+
+public class EscalatorUpdaterUiTest extends EscalatorBasicClientFeaturesTest {
+    @Override
+    protected Class<?> getUIClass() {
+        return EscalatorUpdaterUi.class;
+    }
+
+    @Test
+    public void testHeaderPaintOrderRowColRowCol() {
+        boolean addColumnFirst = false;
+        boolean removeColumnFirst = false;
+        testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testHeaderPaintOrderRowColColRow() {
+        boolean addColumnFirst = false;
+        boolean removeColumnFirst = true;
+        testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testHeaderPaintOrderColRowColRow() {
+        boolean addColumnFirst = true;
+        boolean removeColumnFirst = true;
+        testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testHeaderPaintOrderColRowRowCol() {
+        boolean addColumnFirst = true;
+        boolean removeColumnFirst = false;
+        testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testBodyPaintOrderRowColRowCol() {
+        boolean addColumnFirst = false;
+        boolean removeColumnFirst = false;
+        testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testBodyPaintOrderRowColColRow() {
+        boolean addColumnFirst = false;
+        boolean removeColumnFirst = true;
+        testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testBodyPaintOrderColRowColRow() {
+        boolean addColumnFirst = true;
+        boolean removeColumnFirst = true;
+        testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testBodyPaintOrderColRowRowCol() {
+        boolean addColumnFirst = true;
+        boolean removeColumnFirst = false;
+        testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testFooterPaintOrderRowColRowCol() {
+        boolean addColumnFirst = false;
+        boolean removeColumnFirst = false;
+        testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testFooterPaintOrderRowColColRow() {
+        boolean addColumnFirst = false;
+        boolean removeColumnFirst = true;
+        testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testFooterPaintOrderColRowColRow() {
+        boolean addColumnFirst = true;
+        boolean removeColumnFirst = true;
+        testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    @Test
+    public void testFooterPaintOrderColRowRowCol() {
+        boolean addColumnFirst = true;
+        boolean removeColumnFirst = false;
+        testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+    }
+
+    private void testPaintOrder(String tableSection, boolean addColumnFirst,
+            boolean removeColumnFirst) {
+        openTestURL();
+
+        if (addColumnFirst) {
+            selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+                    ADD_ONE_COLUMN_TO_BEGINNING);
+            selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+                    ADD_ONE_ROW_TO_BEGINNING);
+        } else {
+            selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+                    ADD_ONE_ROW_TO_BEGINNING);
+            selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+                    ADD_ONE_COLUMN_TO_BEGINNING);
+        }
+
+        assertLogContainsInOrder("preAttach: elementIsAttached == false",
+                "postAttach: elementIsAttached == true",
+                "update: elementIsAttached == true");
+        assertLogDoesNotContain("preDetach");
+        assertLogDoesNotContain("postDetach");
+
+        if (removeColumnFirst) {
+            selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+                    REMOVE_ONE_COLUMN_FROM_BEGINNING);
+            selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+                    REMOVE_ONE_ROW_FROM_BEGINNING);
+        } else {
+            selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+                    REMOVE_ONE_ROW_FROM_BEGINNING);
+            selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+                    REMOVE_ONE_COLUMN_FROM_BEGINNING);
+        }
+
+        assertLogContainsInOrder("preDetach: elementIsAttached == true",
+                "postDetach: elementIsAttached == false");
+    }
+
+}
index 1af5940e649e96c3f326f25931a5b9f23a070aeb..54c870b8f7db2aad6e322ab58572741bea9ad9b8 100644 (file)
@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.google.gwt.core.client.Duration;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.dom.client.TableCellElement;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.HTML;
 import com.vaadin.client.ui.grid.Escalator;
@@ -60,6 +61,59 @@ public class EscalatorBasicClientFeaturesWidget extends
         }
     }
 
+    public static class UpdaterLifetimeWidget extends
+            EscalatorBasicClientFeaturesWidget {
+
+        private final EscalatorUpdater debugUpdater = new EscalatorUpdater() {
+            @Override
+            public void preAttach(Row row, Iterable<FlyweightCell> cellsToAttach) {
+                log("preAttach", cellsToAttach);
+            }
+
+            @Override
+            public void postAttach(Row row,
+                    Iterable<FlyweightCell> attachedCells) {
+                log("postAttach", attachedCells);
+            }
+
+            @Override
+            public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) {
+                log("update", cellsToUpdate);
+            }
+
+            @Override
+            public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
+                log("preDetach", cellsToDetach);
+            }
+
+            @Override
+            public void postDetach(Row row,
+                    Iterable<FlyweightCell> detachedCells) {
+                log("postDetach", detachedCells);
+            }
+
+            private void log(String methodName, Iterable<FlyweightCell> cells) {
+                if (!cells.iterator().hasNext()) {
+                    return;
+                }
+
+                TableCellElement cellElement = cells.iterator().next()
+                        .getElement();
+                boolean isAttached = cellElement.getParentElement() != null
+                        && cellElement.getParentElement().getParentElement() != null;
+                logWidget.log(methodName + ": elementIsAttached == "
+                        + isAttached);
+            }
+        };
+
+        public UpdaterLifetimeWidget() {
+            super();
+            escalator.getHeader().setEscalatorUpdater(debugUpdater);
+            escalator.getBody().setEscalatorUpdater(debugUpdater);
+            escalator.getFooter().setEscalatorUpdater(debugUpdater);
+        }
+    }
+
     private static final String COLUMNS_AND_ROWS_MENU = "Columns and Rows";
     private static final String GENERAL_MENU = "General";
     private static final String FEATURES_MENU = "Features";
@@ -217,7 +271,7 @@ public class EscalatorBasicClientFeaturesWidget extends
     }
 
     private Colspan colspan = Colspan.NONE;
-    private final LogWidget logWidget = new LogWidget();
+    protected final LogWidget logWidget = new LogWidget();
 
     public EscalatorBasicClientFeaturesWidget() {
         super(new EscalatorProxy());
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorUpdaterTestConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorUpdaterTestConnector.java
new file mode 100644 (file)
index 0000000..4ef8972
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.widgetset.client.grid;
+
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.components.grid.basicfeatures.EscalatorUpdaterUi.EscalatorUpdaterTestComponent;
+
+@Connect(EscalatorUpdaterTestComponent.class)
+public class EscalatorUpdaterTestConnector extends AbstractComponentConnector {
+
+    @Override
+    public EscalatorBasicClientFeaturesWidget.UpdaterLifetimeWidget getWidget() {
+        return (EscalatorBasicClientFeaturesWidget.UpdaterLifetimeWidget) super
+                .getWidget();
+    }
+}