Search in sources :

Example 11 with NodeChange

use of com.vaadin.flow.internal.change.NodeChange in project flow by vaadin.

the class StateTreeTest method allValuesAfterReattach.

@Test
public void allValuesAfterReattach() {
    StateNode node1 = tree.getRootNode();
    StateNode node2 = new StateNode(ElementData.class);
    StateNodeTest.setParent(node2, node1);
    node2.getFeature(ElementData.class).setTag("foo");
    collectChangesExceptChildrenAddRemove();
    StateNodeTest.setParent(node2, null);
    collectChangesExceptChildrenAddRemove();
    StateNodeTest.setParent(node2, node1);
    List<NodeChange> changes = collectChangesExceptChildrenAddRemove();
    Assert.assertEquals("Should be two changes.", 2, changes.size());
    Assert.assertTrue("First change should re-attach the node.", changes.get(0) instanceof NodeAttachChange);
    Assert.assertTrue("Second change should re-put the value.", changes.get(1) instanceof MapPutChange);
    MapPutChange nodeChange = (MapPutChange) changes.get(1);
    Assert.assertEquals(ElementData.class, nodeChange.getFeature());
    Assert.assertEquals("tag", nodeChange.getKey());
    Assert.assertEquals("foo", nodeChange.getValue());
}
Also used : MapPutChange(com.vaadin.flow.internal.change.MapPutChange) NodeChange(com.vaadin.flow.internal.change.NodeChange) NodeAttachChange(com.vaadin.flow.internal.change.NodeAttachChange) ElementData(com.vaadin.flow.internal.nodefeature.ElementData) Test(org.junit.Test)

Example 12 with NodeChange

use of com.vaadin.flow.internal.change.NodeChange in project flow by vaadin.

the class StateTreeTest method testTreeChangeCollection.

@Test
public void testTreeChangeCollection() {
    StateNode node2 = StateNodeTest.createEmptyNode();
    StateNodeTest.setParent(node2, tree.getRootNode());
    List<NodeChange> changes = collectChangesExceptChildrenAddRemove();
    Assert.assertEquals(1, changes.size());
    NodeAttachChange nodeChange = (NodeAttachChange) changes.get(0);
    Assert.assertSame(node2, nodeChange.getNode());
}
Also used : NodeChange(com.vaadin.flow.internal.change.NodeChange) NodeAttachChange(com.vaadin.flow.internal.change.NodeAttachChange) Test(org.junit.Test)

Example 13 with NodeChange

use of com.vaadin.flow.internal.change.NodeChange in project flow by vaadin.

the class NodeListAddRemoveTest method verifyRemoved.

private void verifyRemoved(List<NodeChange> changes, List<String> items, Integer... indexes) {
    Assert.assertTrue(changes.size() > 0);
    for (int i = 0; i < indexes.length; i++) {
        NodeChange nodeChange = changes.get(i);
        Assert.assertThat(nodeChange, CoreMatchers.instanceOf(ListRemoveChange.class));
        ListRemoveChange<?> change = (ListRemoveChange<?>) nodeChange;
        Assert.assertEquals(indexes[i].intValue(), change.getIndex());
        Assert.assertEquals(items.get(i), change.getRemovedItem());
    }
}
Also used : NodeChange(com.vaadin.flow.internal.change.NodeChange) ListRemoveChange(com.vaadin.flow.internal.change.ListRemoveChange)

Example 14 with NodeChange

use of com.vaadin.flow.internal.change.NodeChange in project flow by vaadin.

the class NodeListEmptyRequiredFeatureTest method generateChangesFromEmpty_noEmptyChange.

@Test
public void generateChangesFromEmpty_noEmptyChange() {
    nodeList.add(new StateNode());
    node.clearChanges();
    nodeList.generateChangesFromEmpty();
    List<NodeChange> changes = new ArrayList<>();
    node.collectChanges(changes::add);
    Assert.assertEquals(1, changes.size());
    Assert.assertTrue(changes.get(0) instanceof ListAddChange<?>);
}
Also used : NodeChange(com.vaadin.flow.internal.change.NodeChange) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with NodeChange

use of com.vaadin.flow.internal.change.NodeChange in project flow by vaadin.

the class NodeListEmptyRequiredFeatureTest method collectChanges_noEmptyChange.

@Test
public void collectChanges_noEmptyChange() {
    nodeList.add(new StateNode());
    List<NodeChange> changes = new ArrayList<>();
    node.collectChanges(changes::add);
    Assert.assertEquals(1, changes.size());
    Assert.assertTrue(changes.get(0) instanceof ListAddChange<?>);
}
Also used : NodeChange(com.vaadin.flow.internal.change.NodeChange) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

NodeChange (com.vaadin.flow.internal.change.NodeChange)19 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 MapPutChange (com.vaadin.flow.internal.change.MapPutChange)8 StateNode (com.vaadin.flow.internal.StateNode)5 ListAddChange (com.vaadin.flow.internal.change.ListAddChange)4 NodeAttachChange (com.vaadin.flow.internal.change.NodeAttachChange)4 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)3 ListRemoveChange (com.vaadin.flow.internal.change.ListRemoveChange)3 EmptyChange (com.vaadin.flow.internal.change.EmptyChange)2 ListClearChange (com.vaadin.flow.internal.change.ListClearChange)2 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)2 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)2 VisibilityData (com.vaadin.flow.internal.nodefeature.VisibilityData)2 JsonObject (elemental.json.JsonObject)2 Serializable (java.io.Serializable)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2