Search in sources :

Example 16 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class ResponsiveImageTest method testImageTagIsRenderedWithXValuesAndSrcSet.

@Test
public void testImageTagIsRenderedWithXValuesAndSrcSet() {
    tester.startPage(ImageSrcSetTestPage.class);
    String lastResponseAsString = tester.getLastResponse().getDocument();
    TagTester imgTagTester = TagTester.createTagByAttribute(lastResponseAsString, "img");
    Assert.assertTrue(imgTagTester.hasAttribute("src"));
    Assert.assertTrue(imgTagTester.hasAttribute("srcset"));
    String attribute = imgTagTester.getAttribute("srcset");
    String[] srcSetElements = attribute.split(",");
    int i = 0;
    for (String srcSetElement : srcSetElements) {
        if (i == 0) {
            Assert.assertTrue(srcSetElement.endsWith("320w"));
        }
        if (i == 1) {
            Assert.assertTrue(srcSetElement.endsWith("2x"));
        }
        if (i == 2) {
            Assert.assertTrue(srcSetElement.endsWith("900w"));
        }
        i++;
    }
    Assert.assertEquals("(min-width: 50em) 33vw,(min-width: 28em) 50vw,100vw", imgTagTester.getAttribute("sizes"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 17 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class AbstractLinkTest method testSetBodyModel.

/**
 * @see <a href="https://issues.apache.org/jira/browse/WICKET-3338">WICKET-3338</a>
 */
@Test
public void testSetBodyModel() {
    final String linkBody = "Link body";
    MockPageWithLink mockPageWithLink = new MockPageWithLink();
    AbstractLink link = new AbstractLink("link") {

        private static final long serialVersionUID = 1L;
    };
    link.setMarkupId("link");
    link.setBody(Model.of(linkBody));
    mockPageWithLink.add(link);
    tester.startPage(mockPageWithLink);
    TagTester tagTester = tester.getTagById("link");
    Assert.assertEquals(linkBody, tagTester.getValue());
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 18 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class AbstractLinkTest method testRenderUsingGetBody.

/**
 * Tests that the {@link AbstractLink} uses the {@link AbstractLink#getBody()} to get its body. This
 * method can be overridden to provide a dynamic model.
 */
@Test
public void testRenderUsingGetBody() {
    final AtomicInteger counter = new AtomicInteger(0);
    MockPageWithLink mockPageWithLink = new MockPageWithLink();
    AbstractLink link = new AbstractLink("link") {

        private static final long serialVersionUID = 1L;

        @Override
        public IModel<?> getBody() {
            return Model.of(counter.getAndIncrement());
        }
    };
    link.setMarkupId("link");
    mockPageWithLink.add(link);
    tester.startPage(mockPageWithLink);
    TagTester tagTester = tester.getTagById("link");
    Assert.assertEquals("0", tagTester.getValue());
    tester.startPage(mockPageWithLink);
    tagTester = tester.getTagById("link");
    Assert.assertEquals("1", tagTester.getValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TagTester(org.apache.wicket.util.tester.TagTester) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 19 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class MediaTagsTest method videoTagIsRenderedRight.

@Test
public void videoTagIsRenderedRight() {
    tester.startPage(MediaTagsTestPage.class);
    String lastResponseAsString = tester.getLastResponse().getDocument();
    TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, "video");
    String attribute = createTagByAttribute.getAttribute("poster");
    assertTrue("page parameter is in the url of the poster", attribute.contains("test2=test2"));
    String attributesrc = createTagByAttribute.getAttribute("src");
    assertTrue("video url is in the src attribute", attributesrc.contains("dummyVideo.m4a"));
    assertEquals("500", createTagByAttribute.getAttribute("width"));
    assertEquals("400", createTagByAttribute.getAttribute("height"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 20 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class DebugSettingsTest method setComponentPathAttributeName.

/**
 * https://issues.apache.org/jira/browse/WICKET-5498
 */
@Test
public void setComponentPathAttributeName() {
    String attributeName = "data-wicket-path";
    tester.getApplication().getDebugSettings().setComponentPathAttributeName(attributeName);
    MockPageWithLink page = new MockPageWithLink();
    Component link = new Link<Void>(MockPageWithLink.LINK_ID) {

        @Override
        public void onClick() {
        }
    }.setMarkupId(MockPageWithLink.LINK_ID);
    page.add(link);
    tester.startPage(page);
    TagTester tagTester = tester.getTagById(MockPageWithLink.LINK_ID);
    String wicketPath = tagTester.getAttribute(attributeName);
    assertEquals(link.getPageRelativePath(), wicketPath);
}
Also used : Component(org.apache.wicket.Component) TagTester(org.apache.wicket.util.tester.TagTester) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Aggregations

TagTester (org.apache.wicket.util.tester.TagTester)21 Test (org.junit.Test)21 MockPageWithLink (org.apache.wicket.MockPageWithLink)3 Component (org.apache.wicket.Component)2 MarkupContainer (org.apache.wicket.MarkupContainer)2 MockPageWithOneComponent (org.apache.wicket.MockPageWithOneComponent)2 HTML5Attributes (org.apache.wicket.markup.html.HTML5Attributes)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)2 WicketTestCase (org.apache.wicket.util.tester.WicketTestCase)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.is (org.hamcrest.Matchers.is)2 Serializable (java.io.Serializable)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1