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"));
}
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());
}
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());
}
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"));
}
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);
}
Aggregations