use of com.vaadin.flow.internal.change.ListAddChange 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));
}
use of com.vaadin.flow.internal.change.ListAddChange in project flow by vaadin.
the class NodeListAddRemoveTest method verifyAdded.
private void verifyAdded(List<NodeChange> changes, List<String> items, Integer... indexes) {
for (int i = 0; i < indexes.length; i++) {
NodeChange nodeChange = changes.get(i);
Assert.assertThat(nodeChange, CoreMatchers.instanceOf(ListAddChange.class));
ListAddChange<?> change = (ListAddChange<?>) nodeChange;
Assert.assertEquals(indexes[i].intValue(), change.getIndex());
Assert.assertEquals(1, change.getNewItems().size());
Assert.assertEquals(items.get(i), change.getNewItems().get(0));
}
}
use of com.vaadin.flow.internal.change.ListAddChange in project flow by vaadin.
the class ListChangeTest method testZeroRemoveNotInJson.
@Test
public void testZeroRemoveNotInJson() {
ListAddChange<StateNode> change = new ListAddChange<>(feature, false, 1, Arrays.asList());
JsonObject json = change.toJson(null);
Assert.assertFalse(json.hasKey(JsonConstants.CHANGE_SPLICE_REMOVE));
}
use of com.vaadin.flow.internal.change.ListAddChange in project flow by vaadin.
the class ListChangeTest method testEmptyAddNotInJson.
@Test
public void testEmptyAddNotInJson() {
ListAddChange<StateNode> change = new ListAddChange<>(feature, false, 1, Arrays.asList());
JsonObject json = change.toJson(null);
Assert.assertFalse(json.hasKey(JsonConstants.CHANGE_SPLICE_ADD_NODES));
}
use of com.vaadin.flow.internal.change.ListAddChange in project flow by vaadin.
the class StateNodeNodeListTest method testAddingAndRemoving.
@Test
public void testAddingAndRemoving() {
StateNode value1 = StateNodeTest.createEmptyNode("value1");
StateNode value2 = StateNodeTest.createEmptyNode("value2");
nodeList.add(value1);
Assert.assertEquals(1, nodeList.size());
Assert.assertSame(value1, nodeList.get(0));
List<NodeChange> firstAddChanges = collectChanges(nodeList);
Assert.assertEquals(1, firstAddChanges.size());
ListAddChange<?> firstAddChange = (ListAddChange<?>) firstAddChanges.get(0);
Assert.assertEquals(0, firstAddChange.getIndex());
Assert.assertEquals(Arrays.asList(value1), firstAddChange.getNewItems());
nodeList.add(0, value2);
Assert.assertEquals(2, nodeList.size());
Assert.assertSame(value2, nodeList.get(0));
Assert.assertSame(value1, nodeList.get(1));
List<NodeChange> secondAddChanges = collectChanges(nodeList);
Assert.assertEquals(1, secondAddChanges.size());
ListAddChange<?> secondAddChange = (ListAddChange<?>) secondAddChanges.get(0);
Assert.assertEquals(0, secondAddChange.getIndex());
Assert.assertEquals(Arrays.asList(value2), secondAddChange.getNewItems());
StateNode removedItem = nodeList.remove(0);
Assert.assertEquals(1, nodeList.size());
Assert.assertSame(value1, nodeList.get(0));
Assert.assertSame(value2, removedItem);
List<NodeChange> removeChanges = collectChanges(nodeList);
Assert.assertEquals(1, removeChanges.size());
ListRemoveChange<?> removeChange = (ListRemoveChange<?>) removeChanges.get(0);
Assert.assertEquals(0, removeChange.getIndex());
}
Aggregations