|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import Yoga from 'yoga-layout'; |
| 9 | + |
| 10 | +test('new_layout_can_be_marked_seen', () => { |
| 11 | + const root = Yoga.Node.create(); |
| 12 | + root.markLayoutSeen(); |
| 13 | + expect(root.hasNewLayout()).toBe(false); |
| 14 | +}); |
| 15 | + |
| 16 | +test('new_layout_calculating_layout_marks_layout_as_unseen', () => { |
| 17 | + const root = Yoga.Node.create(); |
| 18 | + root.markLayoutSeen(); |
| 19 | + root.calculateLayout(undefined, undefined); |
| 20 | + expect(root.hasNewLayout()).toBe(true); |
| 21 | +}); |
| 22 | + |
| 23 | +test('new_layout_calculated_layout_can_be_marked_seen', () => { |
| 24 | + const root = Yoga.Node.create(); |
| 25 | + root.calculateLayout(undefined, undefined); |
| 26 | + root.markLayoutSeen(); |
| 27 | + expect(root.hasNewLayout()).toBe(false); |
| 28 | +}); |
| 29 | + |
| 30 | +test('new_layout_recalculating_layout_does_mark_as_unseen', () => { |
| 31 | + const root = Yoga.Node.create(); |
| 32 | + root.calculateLayout(undefined, undefined); |
| 33 | + root.markLayoutSeen(); |
| 34 | + root.calculateLayout(undefined, undefined); |
| 35 | + expect(root.hasNewLayout()).toBe(true); |
| 36 | +}); |
| 37 | + |
| 38 | +test('new_layout_reset_also_resets_layout_seen', () => { |
| 39 | + const root = Yoga.Node.create(); |
| 40 | + root.markLayoutSeen(); |
| 41 | + root.reset(); |
| 42 | + expect(root.hasNewLayout()).toBe(true); |
| 43 | +}); |
| 44 | + |
| 45 | +test('new_layout_children_sets_new_layout', () => { |
| 46 | + const root = Yoga.Node.create(); |
| 47 | + root.setAlignItems(Yoga.ALIGN_FLEX_START); |
| 48 | + root.setWidth(100); |
| 49 | + root.setHeight(100); |
| 50 | + |
| 51 | + const root_child0 = Yoga.Node.create(); |
| 52 | + root_child0.setAlignItems(Yoga.ALIGN_FLEX_START); |
| 53 | + root_child0.setWidth(50); |
| 54 | + root_child0.setHeight(20); |
| 55 | + root.insertChild(root_child0, 0); |
| 56 | + |
| 57 | + const root_child1 = Yoga.Node.create(); |
| 58 | + root_child1.setAlignItems(Yoga.ALIGN_FLEX_START); |
| 59 | + root_child1.setWidth(50); |
| 60 | + root_child1.setHeight(20); |
| 61 | + root.insertChild(root_child1, 0); |
| 62 | + |
| 63 | + expect(root.hasNewLayout()).toEqual(true); |
| 64 | + expect(root_child0.hasNewLayout()).toEqual(true); |
| 65 | + expect(root_child1.hasNewLayout()).toEqual(true); |
| 66 | + |
| 67 | + root.markLayoutSeen(); |
| 68 | + root_child0.markLayoutSeen(); |
| 69 | + root_child1.markLayoutSeen(); |
| 70 | + |
| 71 | + expect(root.hasNewLayout()).toEqual(false); |
| 72 | + expect(root_child0.hasNewLayout()).toEqual(false); |
| 73 | + expect(root_child1.hasNewLayout()).toEqual(false); |
| 74 | + |
| 75 | + root_child1.setHeight(30); |
| 76 | + root.calculateLayout(undefined, undefined); |
| 77 | + |
| 78 | + expect(root.hasNewLayout()).toEqual(true); |
| 79 | + expect(root_child0.hasNewLayout()).toEqual(true); |
| 80 | + expect(root_child1.hasNewLayout()).toEqual(true); |
| 81 | +}); |
0 commit comments