Search in sources :

Example 1 with InlineTemplate

use of com.vaadin.flow.template.angular.InlineTemplate in project flow by vaadin.

the class ElementUtilTest method includesScriptTags.

@Test
public void includesScriptTags() {
    InlineTemplate template = new InlineTemplate("<div><script>window.alert('shazbot');</script></div>");
    Node jsoupNode = ElementUtil.toJsoup(new Document(""), template.getElement());
    Assert.assertEquals(1, jsoupNode.childNodeSize());
    Node child = jsoupNode.childNode(0);
    Assert.assertEquals("<script>window.alert('shazbot');</script>", child.outerHtml());
}
Also used : Node(org.jsoup.nodes.Node) Document(org.jsoup.nodes.Document) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) Test(org.junit.Test)

Example 2 with InlineTemplate

use of com.vaadin.flow.template.angular.InlineTemplate in project flow by vaadin.

the class EventRpcHandlerTest method templateChildElementEventListener.

@Test
public void templateChildElementEventListener() throws Exception {
    UI ui = new UI();
    AngularTemplate t = new InlineTemplate("<root><child></child></root>");
    Element element = t.getElement().getChild(0);
    ui.add(t);
    AtomicInteger invoked = new AtomicInteger(0);
    element.addEventListener("test-event", e -> {
        invoked.incrementAndGet();
    });
    sendElementEvent(element, ui, "test-event", null);
    Assert.assertEquals(1, invoked.get());
}
Also used : UI(com.vaadin.flow.component.UI) AngularTemplate(com.vaadin.flow.template.angular.AngularTemplate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(com.vaadin.flow.dom.Element) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 3 with InlineTemplate

use of com.vaadin.flow.template.angular.InlineTemplate in project flow by vaadin.

the class EventRpcHandlerTest method templateRootElementEventListener.

@Test
public void templateRootElementEventListener() throws Exception {
    UI ui = new UI();
    AngularTemplate t = new InlineTemplate("<root><child></child></root>");
    Element element = t.getElement();
    ui.add(t);
    AtomicInteger invoked = new AtomicInteger(0);
    element.addEventListener("test-event", e -> {
        invoked.incrementAndGet();
    });
    sendElementEvent(element, ui, "test-event", null);
    Assert.assertEquals(1, invoked.get());
}
Also used : UI(com.vaadin.flow.component.UI) AngularTemplate(com.vaadin.flow.template.angular.AngularTemplate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(com.vaadin.flow.dom.Element) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Aggregations

InlineTemplate (com.vaadin.flow.template.angular.InlineTemplate)3 Test (org.junit.Test)3 UI (com.vaadin.flow.component.UI)2 Element (com.vaadin.flow.dom.Element)2 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)2 AngularTemplate (com.vaadin.flow.template.angular.AngularTemplate)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Document (org.jsoup.nodes.Document)1 Node (org.jsoup.nodes.Node)1