Search in sources :

Example 21 with TestComponent

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

the class ComponentEventBusTest method multipleEventsForSameDomEvent_fireEvent.

@Test
public void multipleEventsForSameDomEvent_fireEvent() {
    TestComponent component = new TestComponent();
    EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
    EventTracker<MappedToDomNoDataEvent> eventTracker2 = new EventTracker<>();
    component.addListener(MappedToDomEvent.class, eventTracker);
    component.addListener(MappedToDomNoDataEvent.class, eventTracker2);
    JsonObject eventData = createData("event.someData", 42, "event.moreData", 19);
    fireDomEvent(component, "dom-event", eventData);
    eventTracker.assertEventCalled(component, true);
    Assert.assertEquals("19", eventTracker.getEvent().getMoreData());
    Assert.assertEquals(42, eventTracker.getEvent().getSomeData());
    Assert.assertEquals(component, eventTracker.getEvent().getSource());
    eventTracker2.assertEventCalled(component, true);
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 22 with TestComponent

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

the class ComponentEventBusTest method serverNoDataEvent_fire.

@Test
public void serverNoDataEvent_fire() {
    TestComponent c = new TestComponent();
    EventTracker<ServerNoDataEvent> eventTracker = new EventTracker<>();
    c.addListener(ServerNoDataEvent.class, eventTracker);
    c.fireEvent(new ServerNoDataEvent(c, false));
    eventTracker.assertEventCalled(c, false);
    Assert.assertFalse(eventTracker.getEvent().isFromClient());
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Example 23 with TestComponent

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

the class ComponentEventBusTest method domEvent_fireClientEvent.

@Test
public void domEvent_fireClientEvent() {
    TestComponent component = new TestComponent();
    EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
    component.addListener(MappedToDomEvent.class, eventTracker);
    JsonObject eventData = createData("event.someData", 42, "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());
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 24 with TestComponent

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

the class ComponentEventBusTest method nonDomEvent_fireEvent.

@Test
public void nonDomEvent_fireEvent() {
    TestComponent component = new TestComponent();
    EventTracker<ServerEvent> eventTracker = new EventTracker<>();
    component.addListener(ServerEvent.class, eventTracker);
    component.fireEvent(new ServerEvent(component, new BigDecimal("12.2")));
    eventTracker.assertEventCalled(component, false);
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 25 with TestComponent

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

the class ComponentEventBusTest method mappedDomEvent_fire_noListeners.

@Test
public void mappedDomEvent_fire_noListeners() {
    TestComponent c = new TestComponent();
    fireDomEvent(c, "dom-event", Json.createObject());
}
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