Search in sources :

Example 6 with TestComponent

use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.

the class ComponentEventBusTest method domEvent_removeListener.

@Test
public void domEvent_removeListener() {
    TestComponent component = new TestComponent();
    EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
    Registration remover = component.addListener(MappedToDomEvent.class, eventTracker);
    remover.remove();
    JsonObject eventData = createData("event.someData", 42, "event.moreData", 1);
    fireDomEvent(component, "dom-event", eventData);
    eventTracker.assertEventNotCalled();
    assertNoListeners(component.getEventBus());
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Registration(com.vaadin.flow.shared.Registration) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 7 with TestComponent

use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.

the class ComponentEventBusUtilTest method domEvent_constructorCached.

@Test
public void domEvent_constructorCached() {
    ReflectionCache<ComponentEvent<?>, ?> cache = ComponentEventBusUtil.cache;
    TestComponent component = new TestComponent();
    cache.clear();
    Assert.assertFalse(cache.contains(MappedToDomEvent.class));
    component.addListener(MappedToDomEvent.class, e -> {
    });
    Assert.assertTrue(cache.contains(MappedToDomEvent.class));
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Example 8 with TestComponent

use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.

the class ComponentEventBusUtilTest method domEvent_dataExpressionCached.

@Test
public void domEvent_dataExpressionCached() {
    TestComponent component = new TestComponent();
    ReflectionCache<ComponentEvent<?>, ?> cache = ComponentEventBusUtil.cache;
    cache.clear();
    Assert.assertFalse(cache.contains(MappedToDomEvent.class));
    component.addListener(MappedToDomEvent.class, e -> {
    });
    Assert.assertTrue(cache.contains(MappedToDomEvent.class));
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Example 9 with TestComponent

use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.

the class ComponentEventBusTest method multipleEventsForSameDomEvent_removeListener.

@Test
public void multipleEventsForSameDomEvent_removeListener() {
    TestComponent component = new TestComponent();
    EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
    EventTracker<MappedToDomNoDataEvent> eventTracker2 = new EventTracker<>();
    Registration remover = component.addListener(MappedToDomEvent.class, eventTracker);
    Registration remover2 = component.addListener(MappedToDomNoDataEvent.class, eventTracker2);
    remover.remove();
    JsonObject eventData = createData("event.someData", 42, "event.moreData", 1);
    fireDomEvent(component, "dom-event", eventData);
    eventTracker.assertEventNotCalled();
    eventTracker2.assertEventCalled(component, true);
    remover2.remove();
    assertNoListeners(component.getEventBus());
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Registration(com.vaadin.flow.shared.Registration) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 10 with TestComponent

use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.

the class ComponentEventBusTest method mappedDomEvent_fire.

@Test
public void mappedDomEvent_fire() {
    TestComponent component = new TestComponent();
    EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
    component.addListener(MappedToDomEvent.class, eventTracker);
    component.getEventBus().fireEvent(new MappedToDomEvent(component));
    eventTracker.assertEventCalled(component, false);
    Assert.assertEquals(32, eventTracker.getEvent().getSomeData());
    Assert.assertEquals("Default constructor", eventTracker.getEvent().getMoreData());
    eventTracker.reset();
    component.getEventBus().fireEvent(new MappedToDomEvent(component, true));
    eventTracker.assertEventCalled(component, true);
    Assert.assertEquals(12, eventTracker.getEvent().getSomeData());
    Assert.assertEquals("Two arg constructor", eventTracker.getEvent().getMoreData());
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Aggregations

TestComponent (com.vaadin.flow.component.ComponentTest.TestComponent)27 Test (org.junit.Test)26 JsonObject (elemental.json.JsonObject)11 UI (com.vaadin.flow.component.UI)6 Element (com.vaadin.flow.dom.Element)6 Registration (com.vaadin.flow.shared.Registration)4 StateNode (com.vaadin.flow.internal.StateNode)3 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)3 Serializable (java.io.Serializable)3 BigDecimal (java.math.BigDecimal)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)2 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)1 JsonValue (elemental.json.JsonValue)1 Before (org.junit.Before)1