@Test void testAddClass() { String html = readFile("addClass.html"); String htmlOK = readFile("addClass-ok.html"); Jerry $ = jerry(html).$("p:last").addClass("selected"); assertEquals(htmlOK, actualHtml($)); }
@Test void testForm() { String html = readFile("form.html"); Jerry doc = jerry(html); final Map<String, String[]> params = new HashMap<>(); doc.form("#myform", (form, parameters) -> params.putAll(parameters)); assertEquals(6, params.size()); assertEquals("text!", params.get("n_text")[0]); assertEquals("password!", params.get("n_password")[0]); assertEquals("on", params.get("n_checkbox1")[0]); assertEquals("check1!", params.get("n_checkbox2")[0]); assertEquals("check2!", params.get("n_checkbox2")[1]); assertEquals("sel2!", params.get("n_select")[0]); assertEquals("sel3!", params.get("n_select")[1]); assertEquals("textarea!", params.get("n_textarea")[0]); }
@Test void testHtml1() { String html = readFile("html1.html"); String text = jerry(html).$("div.demo-container").html(); assertEquals("<div class=\"demo-box\">Demonstration Box</div>", text.trim()); }
@Test void testEmpty() { String html = readFile("empty.html"); String htmlOK = readFile("empty-ok.html"); Jerry doc = jerry(html); doc.$("p").empty(); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testText1() { String html = readFile("text1.html"); String text = jerry(html).$("div.demo-container").text(); String sub = (SystemUtil.info().isWindows()) ? "\r\n" : "\n"; text = StringUtil.remove(text, sub).trim(); text = StringUtil.compressChars(text, ' '); assertEquals("Demonstration Box list item 1 list item 2", text); }
@Test void testBefore() { String html = readFile("before.html"); String htmlOK = readFile("before-ok.html"); Jerry doc = jerry(html); doc.$("p").before("<b>Hello</b>"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testUnwrap() { String html = readFile("unwrap.html"); String htmlOK = readFile("unwrap-ok.html"); Jerry doc = jerry(html); doc.$("p").unwrap(); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoHas() { String html = readFile("pseudoHas.html"); String htmlOK = readFile("pseudoHas-ok.html"); Jerry doc = jerry(html); doc.$("div:has(p)").addClass("test"); 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 testAfter() { String html = readFile("after.html"); String htmlOK = readFile("after-ok.html"); Jerry doc = jerry(html); doc.$("p").after("<b>what is the question?</b>"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testHtml4() { String html = readFile("html4.html"); String htmlOK = readFile("html4-ok.html"); Jerry doc = jerry(html); doc.$("div").html("<span class='red'>Hello <b>Again</b></span>"); 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 testHtml3() { String html = readFile("html3.html"); String htmlOK = readFile("html3-ok.html"); Jerry doc = jerry(html); doc.$("div.demo-container").html("<p>All new content. <em>You bet!</em></p>"); 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 testReplaceWith() { String html = readFile("replaceWith.html"); String htmlOK = readFile("replaceWith-ok.html"); Jerry doc = jerry(html); doc.$("div.second").replaceWith("<h2>New heading</h2>"); assertEquals(htmlOK, actualHtml(doc)); }
@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 testPseudoHeader() { String html = readFile("pseudoHeader.html"); String htmlOK = readFile("pseudoHeader-ok.html"); Jerry doc = jerry(html); doc.$(":header").css("background", "#ccc", "color", "blue"); assertEquals(htmlOK, actualHtml(doc)); }
@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 testPseudoEq() { String html = readFile("pseudoEq.html"); String htmlOK = readFile("pseudoEq-ok.html"); Jerry doc = jerry(html); doc.$("td:eq(2)").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoNot() { String html = readFile("pseudoNot.html"); String htmlOK = readFile("pseudoNot-ok.html"); Jerry doc = jerry(html); doc.$("input:not(\':checked\') + span").css("background-color", "yellow"); assertEquals(htmlOK, actualHtml(doc)); }