use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class EventRpcHandlerTest method testElementEventNoData.
@Test
public void testElementEventNoData() throws Exception {
TestComponent c = new TestComponent();
Element element = c.getElement();
UI ui = new UI();
ui.add(c);
AtomicInteger invocations = new AtomicInteger(0);
element.addEventListener("test-event", e -> invocations.incrementAndGet());
sendElementEvent(element, ui, "test-event", null);
Assert.assertEquals(1, invocations.get());
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class MapSyncRpcHandlerTest method testSynchronizeProperty.
@Test
public void testSynchronizeProperty() throws Exception {
TestComponent c = new TestComponent();
Element element = c.getElement();
ElementPropertyMap.getModel(element.getNode()).setUpdateFromClientFilter(name -> true);
UI ui = new UI();
ui.add(c);
Assert.assertFalse(element.hasProperty(TEST_PROPERTY));
sendSynchronizePropertyEvent(element, ui, TEST_PROPERTY, "value1");
Assert.assertEquals("value1", element.getPropertyRaw(TEST_PROPERTY));
sendSynchronizePropertyEvent(element, ui, TEST_PROPERTY, "value2");
Assert.assertEquals("value2", element.getPropertyRaw(TEST_PROPERTY));
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsPropertyValueOfStateNode_propertySetToNode.
@Test
public void syncJSON_jsonIsPropertyValueOfStateNode_propertySetToNode() throws Exception {
// Let's use element's ElementPropertyMap for testing.
TestComponent component = new TestComponent();
Element element = component.getElement();
UI ui = new UI();
ui.add(component);
StateNode node = element.getNode();
// Set model value directly via ElementPropertyMap
ElementPropertyMap propertyMap = node.getFeature(ElementPropertyMap.class);
propertyMap.setUpdateFromClientFilter(name -> true);
ElementPropertyMap modelMap = propertyMap.resolveModelMap("foo");
// fake StateNode has been created for the model
StateNode model = modelMap.getNode();
modelMap.setProperty("bar", "baz");
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", model.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, "foo", json);
Serializable testPropertyValue = propertyMap.getProperty("foo");
Assert.assertTrue(testPropertyValue instanceof StateNode);
StateNode newNode = (StateNode) testPropertyValue;
Assert.assertSame(model, newNode);
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method nonDomEvent_removeListener.
@Test
public void nonDomEvent_removeListener() {
TestComponent component = new TestComponent();
EventTracker<ServerEvent> eventTracker = new EventTracker<>();
Registration remover = component.addListener(ServerEvent.class, eventTracker);
remover.remove();
component.fireEvent(new ServerEvent(component, new BigDecimal("12.2")));
eventTracker.assertEventNotCalled();
assertNoListeners(component.getEventBus());
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method multipleListenersForSameEvent_fireEvent.
@Test
public void multipleListenersForSameEvent_fireEvent() {
TestComponent component = new TestComponent();
EventTracker<MappedToDomEvent> eventTracker = new EventTracker<>();
EventTracker<MappedToDomEvent> eventTracker2 = new EventTracker<>();
component.addListener(MappedToDomEvent.class, eventTracker);
component.addListener(MappedToDomEvent.class, eventTracker2);
JsonObject eventData = createData("event.someData", 42, "event.moreData", 19);
fireDomEvent(component, "dom-event", eventData);
eventTracker.assertEventCalled(component, true);
eventTracker2.assertEventCalled(component, true);
Assert.assertEquals("19", eventTracker.getEvent().getMoreData());
Assert.assertEquals("19", eventTracker2.getEvent().getMoreData());
Assert.assertEquals(42, eventTracker.getEvent().getSomeData());
Assert.assertEquals(42, eventTracker2.getEvent().getSomeData());
Assert.assertEquals(component, eventTracker.getEvent().getSource());
Assert.assertEquals(component, eventTracker2.getEvent().getSource());
}
Aggregations