From: Julien Dramaix Date: Tue, 29 Mar 2011 13:18:04 +0000 (+0000) Subject: improve tests for detach and remove methods X-Git-Tag: release-1.3.2~444 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d6be4ff6362bb63305caf4a9c85863e28b741864;p=gwtquery.git improve tests for detach and remove methods --- diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index 1a53a88b..0e9db738 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -1000,6 +1000,10 @@ public class GQueryCoreTest extends GWTTestCase { $("#parent", e).remove(); + //child and the parent was removed + assertEquals(0,$("#child", e).length()); + assertEquals(0,$("#parent", e).length()); + assertNull($(child).data("key")); assertNull($(parent).data("key")); //if failCallback is always binded, test fails... @@ -1038,6 +1042,10 @@ public class GQueryCoreTest extends GWTTestCase { $("div", e).remove("#child"); + //child was removed but not the parent + assertEquals(0,$("#child", e).length()); + assertEquals(1,$("#parent", e).length()); + assertNull($(child).data("key")); assertEquals("parent",$(parent).data("key")); @@ -1072,11 +1080,17 @@ public class GQueryCoreTest extends GWTTestCase { GQuery $parent = $("#parent", e).detach(); + //test parent an child well detached + assertEquals(0,$("#parent", e).length()); + assertEquals(0,$("#child", e).length()); + //test that data was not cleaned assertEquals("child",$(child).data("key")); assertEquals("parent",$(parent).data("key")); $(e).append($parent); - + + assertEquals(1,$("#parent", e).length()); + assertEquals(1,$("#child", e).length()); assertEquals("child",$("#child", e).data("key")); assertEquals("parent",$("#parent", e).data("key")); @@ -1087,6 +1101,49 @@ public class GQueryCoreTest extends GWTTestCase { + } + + public void testDetachMethodWithFilter(){ + String html = "
parent
child
"; + $(e).html(html); + + Function noFailCallback = new Function(){ + @Override + public void f(Element e) { + $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED)); + } + }; + + Element parent = $("#parent", e).get(0); + Element child = $("#child", e).get(0); + + $("#child", e).data("key", "child"); + $("#child", e).click(noFailCallback); + $("#parent", e).data("key", "parent"); + $("#parent", e).click(noFailCallback); + + GQuery $parent = $("div", e).detach("#child"); + + //child was removed but not the parent + assertEquals(0,$("#child", e).length()); + assertEquals(1,$("#parent", e).length()); + + //data must always exist + assertEquals("child", $(child).data("key")); + assertEquals("parent",$(parent).data("key")); + + $(e).append($parent.filter("#child")); + + assertEquals(1,$("#child", e).length()); + assertEquals(1,$("#parent", e).length()); + + $(child).click(); + assertEquals("red", $("#child", e).css(CSS.BACKGROUND_COLOR)); + + $(parent).click(); + assertEquals("red", $("#parent", e).css(CSS.BACKGROUND_COLOR)); + + } }