Search in sources :

Example 11 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class ModelDescriptorTest method assertComplexModeType.

private <T extends Serializable> void assertComplexModeType(Class<T> clazz, T wrappedValue, T value) {
    Optional<ComplexModelType<?>> type = BasicComplexModelType.get(clazz);
    StateNode stateNode = type.get().applicationToModel(wrappedValue, null);
    Assert.assertEquals(wrappedValue, stateNode.getFeature(BasicTypeValue.class).getValue());
    stateNode.getFeature(BasicTypeValue.class).setValue(value);
    Object modelValue = type.get().modelToApplication(stateNode);
    Assert.assertEquals(value, modelValue);
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) BasicTypeValue(com.vaadin.flow.internal.nodefeature.BasicTypeValue)

Example 12 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class TemplateModelTest method beanModelType_emptySubBeanAsInitialValue.

@Test
public void beanModelType_emptySubBeanAsInitialValue() {
    SubBeansTemplate template = new SubBeansTemplate();
    // Check that even before calling any model method the properties are
    // available via features
    Serializable bean = template.getElement().getNode().getFeature(ElementPropertyMap.class).getProperty("bean");
    StateNode node = (StateNode) bean;
    Serializable subBean = node.getFeature(ElementPropertyMap.class).getProperty("bean");
    Assert.assertTrue(subBean instanceof StateNode);
    // Now check properties via API
    Assert.assertNotNull(template.getModel().getBean().getBean());
}
Also used : Serializable(java.io.Serializable) StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 13 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class ListChangeTest method testBasicJson.

@Test
public void testBasicJson() {
    StateNode child1 = StateNodeTest.createEmptyNode("child1");
    StateNode child2 = StateNodeTest.createEmptyNode("child2");
    ListAddChange<StateNode> change = new ListAddChange<>(feature, true, 0, Arrays.asList(child1, child2));
    JsonObject json = change.toJson(null);
    Assert.assertEquals(change.getNode().getId(), (int) json.getNumber(JsonConstants.CHANGE_NODE));
    Assert.assertEquals(NodeFeatureRegistry.getId(feature.getClass()), (int) json.getNumber(JsonConstants.CHANGE_FEATURE));
    Assert.assertEquals(JsonConstants.CHANGE_TYPE_SPLICE, json.getString(JsonConstants.CHANGE_TYPE));
    Assert.assertEquals(0, (int) json.getNumber(JsonConstants.CHANGE_SPLICE_INDEX));
    JsonArray addNodes = json.getArray(JsonConstants.CHANGE_SPLICE_ADD_NODES);
    Assert.assertEquals(2, addNodes.length());
    Assert.assertEquals(child1.getId(), (int) addNodes.getNumber(0));
    Assert.assertEquals(child2.getId(), (int) addNodes.getNumber(1));
}
Also used : JsonArray(elemental.json.JsonArray) ListAddChange(com.vaadin.flow.internal.change.ListAddChange) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) Test(org.junit.Test) StateNodeTest(com.vaadin.flow.internal.StateNodeTest) AbstractNodeFeatureTest(com.vaadin.flow.internal.nodefeature.AbstractNodeFeatureTest)

Example 14 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class AttachExistingElementFeatureTest method unregister_dataIsNotAvailaleByNode.

@Test
public void unregister_dataIsNotAvailaleByNode() {
    StateNode node = new StateNode();
    AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
    Element element = Mockito.mock(Element.class);
    StateNode child = Mockito.mock(StateNode.class);
    ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
    Node<?> parent = Mockito.mock(Node.class);
    feature.register(parent, element, child, callback);
    feature.unregister(child);
    Assert.assertNull(feature.getCallback(child));
    Assert.assertNull(feature.getParent(child));
    Assert.assertNull(feature.getPreviousSibling(child));
}
Also used : ChildElementConsumer(com.vaadin.flow.dom.ChildElementConsumer) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) AttachExistingElementFeature(com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature) Test(org.junit.Test)

Example 15 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class AttachExistingElementFeatureTest method forEachChild_register_registeredStatNodeIsAChild.

@Test
public void forEachChild_register_registeredStatNodeIsAChild() {
    StateNode node = new StateNode();
    AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
    Element element = Mockito.mock(Element.class);
    StateNode child = Mockito.mock(StateNode.class);
    ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
    Node<?> parent = Mockito.mock(Node.class);
    feature.register(parent, element, child, callback);
    List<StateNode> children = new ArrayList<>(1);
    feature.forEachChild(children::add);
    Assert.assertEquals(1, children.size());
    Assert.assertEquals(child, children.get(0));
}
Also used : ChildElementConsumer(com.vaadin.flow.dom.ChildElementConsumer) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) AttachExistingElementFeature(com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature) Test(org.junit.Test)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)160 Test (org.junit.Test)99 Element (com.vaadin.flow.dom.Element)29 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)19 JsonObject (elemental.json.JsonObject)19 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ArrayList (java.util.ArrayList)14 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)13 Serializable (java.io.Serializable)13 StateTree (com.vaadin.flow.internal.StateTree)10 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 UI (com.vaadin.flow.component.UI)9 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 ChildElementConsumer (com.vaadin.flow.dom.ChildElementConsumer)8 AttachExistingElementFeature (com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature)8 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)8 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)6