mirror of
https://github.com/hanzoai/yoga.git
synced 2026-10-30 19:34:29 +00:00
The package name is also the specifier every test and the playground import, so it moves as one piece: package.json, the tsconfig path, the generator, and the website workspace that depends on it. Generated tests are re-signed. Dated blog posts keep the old name - they are a record of upstream's 2.0 and 3.0 releases, not instructions for this package.
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import Yoga from '@hanzo/layout';
|
|
import {Direction, FlexDirection, Wrap} from '@hanzo/layout';
|
|
|
|
test('children_overflow_no_wrap_and_no_flex_children', () => {
|
|
const root = Yoga.Node.create();
|
|
root.setWidth(200);
|
|
root.setHeight(100);
|
|
root.setFlexDirection(FlexDirection.Column);
|
|
root.setFlexWrap(Wrap.NoWrap);
|
|
|
|
const child0 = Yoga.Node.create();
|
|
child0.setWidth(80);
|
|
child0.setHeight(40);
|
|
child0.setMargin(Yoga.EDGE_TOP, 10);
|
|
child0.setMargin(Yoga.EDGE_BOTTOM, 15);
|
|
root.insertChild(child0, 0);
|
|
|
|
const child1 = Yoga.Node.create();
|
|
child1.setWidth(80);
|
|
child1.setHeight(40);
|
|
child1.setMargin(Yoga.EDGE_BOTTOM, 5);
|
|
root.insertChild(child1, 1);
|
|
|
|
root.calculateLayout(200, 100, Direction.LTR);
|
|
|
|
expect(root.getComputedHadOverflow()).toBe(true);
|
|
});
|
|
|
|
test('no_overflow_no_wrap_and_flex_children', () => {
|
|
const root = Yoga.Node.create();
|
|
root.setWidth(200);
|
|
root.setHeight(100);
|
|
root.setFlexDirection(FlexDirection.Column);
|
|
root.setFlexWrap(Wrap.NoWrap);
|
|
|
|
const child0 = Yoga.Node.create();
|
|
child0.setWidth(80);
|
|
child0.setHeight(40);
|
|
child0.setMargin(Yoga.EDGE_TOP, 10);
|
|
child0.setMargin(Yoga.EDGE_BOTTOM, 10);
|
|
root.insertChild(child0, 0);
|
|
|
|
const child1 = Yoga.Node.create();
|
|
child1.setWidth(80);
|
|
child1.setHeight(40);
|
|
child1.setMargin(Yoga.EDGE_BOTTOM, 5);
|
|
child1.setFlexShrink(1);
|
|
root.insertChild(child1, 1);
|
|
|
|
root.calculateLayout(200, 100, Direction.LTR);
|
|
|
|
expect(root.getComputedHadOverflow()).toBe(false);
|
|
});
|
|
|
|
test('hadOverflow_gets_reset_if_no_longer_valid', () => {
|
|
const root = Yoga.Node.create();
|
|
root.setWidth(200);
|
|
root.setHeight(100);
|
|
root.setFlexDirection(FlexDirection.Column);
|
|
root.setFlexWrap(Wrap.NoWrap);
|
|
|
|
const child0 = Yoga.Node.create();
|
|
child0.setWidth(80);
|
|
child0.setHeight(40);
|
|
child0.setMargin(Yoga.EDGE_TOP, 10);
|
|
child0.setMargin(Yoga.EDGE_BOTTOM, 10);
|
|
root.insertChild(child0, 0);
|
|
|
|
const child1 = Yoga.Node.create();
|
|
child1.setWidth(80);
|
|
child1.setHeight(40);
|
|
child1.setMargin(Yoga.EDGE_BOTTOM, 5);
|
|
root.insertChild(child1, 1);
|
|
|
|
root.calculateLayout(200, 100, Direction.LTR);
|
|
expect(root.getComputedHadOverflow()).toBe(true);
|
|
|
|
child1.setFlexShrink(1);
|
|
root.calculateLayout(200, 100, Direction.LTR);
|
|
expect(root.getComputedHadOverflow()).toBe(false);
|
|
});
|
|
|
|
test('hadOverflow_included_in_getComputedLayout', () => {
|
|
const root = Yoga.Node.create();
|
|
root.setWidth(200);
|
|
root.setHeight(100);
|
|
root.setFlexDirection(FlexDirection.Column);
|
|
|
|
const child0 = Yoga.Node.create();
|
|
child0.setWidth(80);
|
|
child0.setHeight(80);
|
|
root.insertChild(child0, 0);
|
|
|
|
const child1 = Yoga.Node.create();
|
|
child1.setWidth(80);
|
|
child1.setHeight(80);
|
|
root.insertChild(child1, 1);
|
|
|
|
root.calculateLayout(200, 100, Direction.LTR);
|
|
|
|
const layout = root.getComputedLayout();
|
|
expect(layout.hadOverflow).toBe(true);
|
|
});
|