From 5514722ce27a6c094c91a310fd27942f64f658ed Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 21 Dec 2018 03:12:17 -0800 Subject: [PATCH] Add tests for `YogaNode#hasNewLayout()` / `#markLayoutSeen()` Summary: @public Adds test for the `hasNewLayout()` and `markLayoutSeen()` methods of `YogaNode`. The behavior of these methods wasn't previously covered by a test. This will allow us to change the implementation with confidence. Reviewed By: SidharthGuglani Differential Revision: D13534351 fbshipit-source-id: 23a9f9b70df18fd7c34023fd77b9df9fbd733f61 --- .../tests/com/facebook/yoga/YogaNodeTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index e65c4ff7..405c322e 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -386,6 +386,52 @@ public class YogaNodeTest { assertFalse(root.getDoesLegacyStretchFlagAffectsLayout()); } + @Test + public void initiallyHasNewLayout() { + YogaNode root = createNode(); + assertTrue(root.hasNewLayout()); + } + + @Test + public void initialLayoutCanBeMarkedSeen() { + YogaNode root = createNode(); + root.markLayoutSeen(); + assertFalse(root.hasNewLayout()); + } + + @Test + public void calculatingLayoutMarksLayoutAsUnseen() { + YogaNode root = createNode(); + root.markLayoutSeen(); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + assertTrue(root.hasNewLayout()); + } + + @Test + public void calculatedLayoutCanBeMarkedSeen() { + YogaNode root = createNode(); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + root.markLayoutSeen(); + assertFalse(root.hasNewLayout()); + } + + @Test + public void recalculatingLayoutDoesMarkAsUnseen() { + YogaNode root = createNode(); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + root.markLayoutSeen(); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + assertTrue(root.hasNewLayout()); + } + + @Test + public void resetAlsoResetsLayoutSeen() { + YogaNode root = createNode(); + root.markLayoutSeen(); + root.reset(); + assertTrue(root.hasNewLayout()); + } + private YogaNode createNode() { return mNodeFactory.create(); }