@Test void testFilter4() { String html = readFile("filter4.html"); String htmlOK = readFile("filter4-ok.html"); Jerry doc = jerry(html); doc.$("div").css("background", "#b4b0da") .filter(($this, index) -> index == 1 || $this.attr("id").equals("fourth")) .css("border", "3px double red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoButton() { String html = readFile("pseudoButton.html"); String htmlOK = readFile("pseudoButton-ok.html"); Jerry doc = jerry(html); Jerry input = doc.$(":button").css("background", "yellow", "border", "3px red solid"); doc.$("div").text("For this type jQuery found " + input.length() + ".").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoFile() { String html = readFile("pseudoFile.html"); String htmlOK = readFile("pseudoFile-ok.html"); Jerry doc = jerry(html); Jerry input = doc.$("form input:file").css("background", "yellow", "border", "3px red solid"); doc.$("div").text("For this type jQuery found " + input.length() + ".").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoCheckbox() { String html = readFile("pseudoCheckbox.html"); String htmlOK = readFile("pseudoCheckbox-ok.html"); Jerry doc = jerry(html); Jerry input = doc.$("form input:checkbox").wrap("<span></span>").parent().css("background", "yellow", "border", "3px red solid"); doc.$("div").text("For this type jQuery found " + input.length() + ".").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoContains2() { String html = readFile("pseudoContains.html"); String htmlOK = readFile("pseudoContains-ok.html"); Jerry doc = jerry(html); doc.$("div:contains(John)").css("text-decoration", "underline"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoEven() { String html = readFile("pseudoEven.html"); String htmlOK = readFile("pseudoEven-ok.html"); Jerry doc = jerry(html); doc.$("tr:even").css("background-color", "#bbbbff"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoFirst() { String html = readFile("pseudoFirst.html"); String htmlOK = readFile("pseudoFirst-ok.html"); Jerry $ = jerry(html).$("tr:first").css("font-style", "italic"); assertEquals(htmlOK, actualHtml($)); }
@Test void testPseudoLast() { String html = readFile("pseudoLast.html"); String htmlOK = readFile("pseudoLast-ok.html"); Jerry $ = jerry(html).$("tr:last").css("background-color", "yellow", "font-weight", "bolder"); assertEquals(htmlOK, actualHtml($)); }
@Test void testPseudoParent() { String html = readFile("pseudoParent.html"); String htmlOK = readFile("pseudoParent-ok.html"); Jerry doc = jerry(html); doc.$("td:parent").css("background", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testNot() { String html = readFile("not.html"); String htmlOK = readFile("not-ok.html"); Jerry $ = jerry(html).$("div").not(".green, #blueone").css("border-color", "red"); assertEquals(htmlOK, actualHtml($)); }
@Test void testFilter() { String html = readFile("filter.html"); String htmlOK = readFile("filter-ok.html"); Jerry doc = jerry(html); doc.$("li").filter(":even").css("background-color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testFilter2_2() { String html = readFile("filter2.html"); String htmlOK = readFile("filter2-ok2.html"); Jerry doc = jerry(html); doc.$("li").filter(($this, index) -> index % 3 == 2).css("background-color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testEnd() { String html = readFile("end.html"); String htmlOK = readFile("end-ok.html"); Jerry $ = jerry(html).$("p").find("span").end().css("border", "2px red solid"); assertEquals(htmlOK, actualHtml($)); }
@Test void testHas2() { String html = readFile("has2.html"); String htmlOK = readFile("has2-ok.html"); Jerry doc = jerry(html); doc.$("li").has("ul").css("background-color", "red"); doc.$( "ul" ).append( "<li>" + ( doc.$( "ul" ).has( "li" ).length() > 0 ? "Yes" : "No" ) + "</li>" ); doc.$( "ul" ).has( "li" ).addClass( "full" ); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testHtml5() { String html = readFile("html5.html"); String htmlOK = readFile("html5-ok.html"); Jerry doc = jerry(html); doc.$("div").html("<b>Wow!</b> Such excitement..."); doc.$("div b").append("!!!").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testFilter2() { String html = readFile("filter2.html"); String htmlOK = readFile("filter2-ok.html"); Jerry doc = jerry(html); doc.$("li").filter(($this, index) -> Jerry.$("strong", $this).length() == 1).css("background-color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testNullForEmpty() { Jerry doc = Jerry.jerry().parse("<html></html>"); assertNull(doc.$("#not-a-valid-id").attr("someAttribute")); assertNull(doc.$("#not-a-valid-id").css("name")); assertNull(doc.$("#not-a-valid-id").html()); }