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