use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method serverNoDataEvent_fire_noListeners.
@Test
public void serverNoDataEvent_fire_noListeners() {
TestComponent c = new TestComponent();
c.fireEvent(new ServerNoDataEvent(c, false));
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method multipleListenersForSameEvent_removeListener.
@Test
public void multipleListenersForSameEvent_removeListener() {
TestComponent component = new TestComponent();
EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
EventTracker<MappedToDomEvent> eventTracker2 = new EventTracker<>();
Registration remover = component.addListener(MappedToDomEvent.class, eventTracker);
Registration remover2 = component.addListener(MappedToDomEvent.class, eventTracker2);
remover.remove();
JsonObject eventData = createData("event.someData", 42, "event.moreData", 19);
fireDomEvent(component, "dom-event", eventData);
eventTracker.assertEventNotCalled();
eventTracker2.assertEventCalled(component, true);
Assert.assertEquals("19", eventTracker2.getEvent().getMoreData());
Assert.assertEquals(42, eventTracker2.getEvent().getSomeData());
Assert.assertEquals(component, eventTracker2.getEvent().getSource());
remover2.remove();
assertNoListeners(component.getEventBus());
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method domEvent_fireServerEvent.
@Test
public void domEvent_fireServerEvent() {
TestComponent component = new TestComponent();
EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
component.addListener(MappedToDomEvent.class, eventTracker);
JsonObject eventData = Json.createObject();
eventData.put("event.someData", 42);
eventData.put("event.moreData", 1);
fireDomEvent(component, "dom-event", eventData);
eventTracker.assertEventCalled(component, true);
MappedToDomEvent event = eventTracker.getEvent();
Assert.assertEquals(42, event.getSomeData());
Assert.assertEquals("1", event.getMoreData());
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method testFireEvent_noListeners_eventBusNotCreated.
@Test
public void testFireEvent_noListeners_eventBusNotCreated() {
AtomicInteger eventBusCreated = new AtomicInteger();
TestComponent c = new TestComponent() {
@Override
public ComponentEventBus getEventBus() {
eventBusCreated.incrementAndGet();
return super.getEventBus();
}
};
c.fireEvent(new ServerEvent(c, new BigDecimal(0)));
Assert.assertEquals(0, eventBusCreated.get());
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class EventRpcHandlerTest method testElementEventData.
@Test
public void testElementEventData() throws Exception {
TestComponent c = new TestComponent();
Element element = c.getElement();
UI ui = new UI();
ui.add(c);
AtomicInteger invocationData = new AtomicInteger(0);
element.addEventListener("test-event", e -> invocationData.addAndGet((int) e.getEventData().getNumber("nr")));
JsonObject eventData = Json.createObject();
eventData.put("nr", 123);
sendElementEvent(element, ui, "test-event", eventData);
Assert.assertEquals(123, invocationData.get());
}
Aggregations