use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsForStateNodeInList_propertySetToStateNodeCopy.
@Test
public void syncJSON_jsonIsForStateNodeInList_propertySetToStateNodeCopy() 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);
ModelList modelList = propertyMap.resolveModelList("foo");
// fake StateNode has been created for the model
StateNode item = new StateNode(ElementPropertyMap.class);
modelList.add(item);
item.getFeature(ElementPropertyMap.class).setProperty("bar", "baz");
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", item.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, TEST_PROPERTY, json);
// Now the model node should be copied and available as the
// TEST_PROPERTY value
Serializable testPropertyValue = propertyMap.getProperty(TEST_PROPERTY);
Assert.assertTrue(testPropertyValue instanceof StateNode);
StateNode newNode = (StateNode) testPropertyValue;
Assert.assertNotEquals(item.getId(), newNode.getId());
Assert.assertEquals("baz", newNode.getFeature(ElementPropertyMap.class).getProperty("bar"));
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsNotListItemAndNotPropertyValue_propertySetToJSON.
@Test
public void syncJSON_jsonIsNotListItemAndNotPropertyValue_propertySetToJSON() 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();
TestComponent anotherComonent = new TestComponent();
StateNode anotherNode = anotherComonent.getElement().getNode();
ElementPropertyMap.getModel(node).setUpdateFromClientFilter(name -> true);
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", anotherNode.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, "foo", json);
Serializable testPropertyValue = node.getFeature(ElementPropertyMap.class).getProperty("foo");
Assert.assertNotSame(anotherNode, testPropertyValue);
Assert.assertTrue(testPropertyValue instanceof JsonValue);
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method invalidEventDataInConstructor_addListener.
@Test(expected = IllegalArgumentException.class)
public void invalidEventDataInConstructor_addListener() {
TestComponent c = new TestComponent();
c.addListener(MappedToDomInvalidEventData.class, e -> {
});
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method mappedDomEvent_fire_missingData.
@Test
public void mappedDomEvent_fire_missingData() {
TestComponent c = new TestComponent();
EventTracker<MappedToDomEvent> eventListener = new EventTracker<>();
c.addListener(MappedToDomEvent.class, eventListener);
fireDomEvent(c, "dom-event", createData("event.someData", 2));
eventListener.assertEventCalled(c, true);
Assert.assertEquals(2, eventListener.getEvent().getSomeData());
Assert.assertNull(eventListener.getEvent().getMoreData());
}
use of com.vaadin.flow.component.ComponentTest.TestComponent in project flow by vaadin.
the class ComponentEventBusTest method invalidEventConstructor_addListener.
@Test(expected = IllegalArgumentException.class)
public void invalidEventConstructor_addListener() {
TestComponent c = new TestComponent();
c.addListener(InvalidMappedToDomEvent.class, e -> {
});
}
Aggregations