Search in sources :

Example 6 with AngularTemplate

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

the class ClientDelegteHandlersTest method attach_handlersContainsAllTemplateMethods.

@Test
public void attach_handlersContainsAllTemplateMethods() {
    UI ui = new UI();
    AngularTemplate template = new ChildTemplateWithMultipleMethods();
    ui.add(template);
    ClientDelegateHandlers feature = template.getElement().getNode().getFeature(ClientDelegateHandlers.class);
    Assert.assertEquals(3, feature.size());
    Set<String> methods = getDeclaredMethods(ChildTemplateWithMultipleMethods.class).collect(Collectors.toCollection(HashSet::new));
    methods.add(getDeclaredMethods(Template1.class).findFirst().get());
    for (int i = 0; i < feature.size(); i++) {
        methods.remove(feature.get(i));
    }
    Assert.assertTrue("Feature doesn't contain methods: " + methods.toString(), methods.isEmpty());
}
Also used : UI(com.vaadin.flow.component.UI) AngularTemplate(com.vaadin.flow.template.angular.AngularTemplate) ClientDelegateHandlers(com.vaadin.flow.internal.nodefeature.ClientDelegateHandlers) Test(org.junit.Test)

Example 7 with AngularTemplate

use of com.vaadin.flow.template.angular.AngularTemplate 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 8 with AngularTemplate

use of com.vaadin.flow.template.angular.AngularTemplate 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)

Example 9 with AngularTemplate

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

the class ClientDelegteHandlersTest method attach_twoMethodsWithTheSameName_ExceptionIsThrown.

@Test
public void attach_twoMethodsWithTheSameName_ExceptionIsThrown() {
    UI ui = new UI();
    AngularTemplate template = new ChildTemplateWithOverriddenMethod();
    ui.add(template);
}
Also used : UI(com.vaadin.flow.component.UI) AngularTemplate(com.vaadin.flow.template.angular.AngularTemplate) Test(org.junit.Test)

Example 10 with AngularTemplate

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

the class ClientDelegteHandlersTest method attach_handlersContainsOnlyOneTemplateMethod.

@Test
public void attach_handlersContainsOnlyOneTemplateMethod() {
    UI ui = new UI();
    AngularTemplate template = new ChildTemplateWithOverriddenMethod();
    ui.add(template);
    ClientDelegateHandlers feature = template.getElement().getNode().getFeature(ClientDelegateHandlers.class);
    Assert.assertEquals(1, feature.size());
    Assert.assertEquals(getDeclaredMethods(ChildTemplateWithOverriddenMethod.class).findFirst().get(), feature.get(0));
}
Also used : UI(com.vaadin.flow.component.UI) AngularTemplate(com.vaadin.flow.template.angular.AngularTemplate) ClientDelegateHandlers(com.vaadin.flow.internal.nodefeature.ClientDelegateHandlers) Test(org.junit.Test)

Aggregations

UI (com.vaadin.flow.component.UI)11 AngularTemplate (com.vaadin.flow.template.angular.AngularTemplate)11 Test (org.junit.Test)11 ClientDelegateHandlers (com.vaadin.flow.internal.nodefeature.ClientDelegateHandlers)5 Element (com.vaadin.flow.dom.Element)2 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)2 InlineTemplate (com.vaadin.flow.template.angular.InlineTemplate)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2