use of com.vaadin.flow.internal.nodefeature.VisibilityData in project flow by vaadin.
the class StateNodeTest method assertCollectChanges_initiallyVisible.
private void assertCollectChanges_initiallyVisible(StateNode stateNode, ElementPropertyMap properties, Consumer<Boolean> activityUpdater) {
VisibilityData visibility = stateNode.getFeature(VisibilityData.class);
// check that normal flow works as it should (without any inactivity)
properties.setProperty("foo", "bar");
List<NodeChange> changes = new ArrayList<>();
stateNode.collectChanges(changes::add);
Assert.assertEquals(2, changes.size());
// node is attached event
Assert.assertThat(changes.get(0), CoreMatchers.instanceOf(NodeAttachChange.class));
// the property update event
Assert.assertThat(changes.get(1), CoreMatchers.instanceOf(MapPutChange.class));
changes.clear();
// now make the node inactive via the VisibiltyData
activityUpdater.accept(false);
// now the node becomes inactive and should send only changes for
// VisibiltyData, but don't loose changes for other features
properties.setProperty("foo", "baz");
TestStateTree tree = (TestStateTree) stateNode.getOwner();
tree.dirtyNodes.clear();
stateNode.collectChanges(changes::add);
// activity updater may modify visibility of the node itself or its
// ancestor. The number of changes will depend on whether the subject
// node is visible or not
boolean visibilityChanged = !visibility.isVisible();
// The only possible change is visibility value change
Assert.assertEquals(visibilityChanged ? 1 : 0, changes.size());
MapPutChange change;
if (visibilityChanged) {
Assert.assertEquals(0, tree.dirtyNodes.size());
Assert.assertThat(changes.get(0), CoreMatchers.instanceOf(MapPutChange.class));
change = (MapPutChange) changes.get(0);
Assert.assertEquals(VisibilityData.class, change.getFeature());
} else {
// the target node should be marked as dirty because it's visible
// but its parent is inactive
Assert.assertEquals(1, tree.dirtyNodes.size());
tree.dirtyNodes.contains(stateNode);
}
changes.clear();
// make the node active again
activityUpdater.accept(true);
stateNode.collectChanges(changes::add);
// Two possible changes: probable visibility value change and property
// update change
Assert.assertEquals(visibilityChanged ? 2 : 1, changes.size());
Assert.assertThat(changes.get(0), CoreMatchers.instanceOf(MapPutChange.class));
change = (MapPutChange) changes.get(0);
MapPutChange propertyChange;
if (visibilityChanged) {
MapPutChange visibilityChange = VisibilityData.class.equals(change.getFeature()) ? change : (MapPutChange) changes.get(1);
propertyChange = change.equals(visibilityChange) ? (MapPutChange) changes.get(1) : change;
} else {
propertyChange = change;
}
Assert.assertEquals(ElementPropertyMap.class, propertyChange.getFeature());
Assert.assertEquals("baz", propertyChange.getValue());
// Don't make any changes, check that there are no changes collected
changes.clear();
stateNode.collectChanges(changes::add);
Assert.assertEquals(0, changes.size());
}
Aggregations