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.
1979 lines
69 KiB
TypeScript
1979 lines
69 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.
|
|
*
|
|
* @generated SignedSource<<c3816d106e81414a7c3e2ead083eef51>>
|
|
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGBoxSizingTest.html
|
|
*/
|
|
|
|
import { intrinsicSizeMeasureFunc } from '../tools/utils.ts'
|
|
import Yoga from '@hanzo/layout';
|
|
import {
|
|
Align,
|
|
BoxSizing,
|
|
Direction,
|
|
Display,
|
|
Edge,
|
|
Errata,
|
|
ExperimentalFeature,
|
|
FlexDirection,
|
|
Gutter,
|
|
Justify,
|
|
MeasureMode,
|
|
Overflow,
|
|
PositionType,
|
|
Unit,
|
|
Wrap,
|
|
} from '@hanzo/layout';
|
|
|
|
test('box_sizing_content_box_simple', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 5);
|
|
root.setBorder(Edge.All, 10);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(130);
|
|
expect(root.getComputedHeight()).toBe(130);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(130);
|
|
expect(root.getComputedHeight()).toBe(130);
|
|
});
|
|
test('box_sizing_border_box_simple', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 5);
|
|
root.setBorder(Edge.All, 10);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_content_box_percent', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth("50%");
|
|
root_child0.setHeight("25%");
|
|
root_child0.setPadding(Edge.All, 4);
|
|
root_child0.setBorder(Edge.All, 16);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
});
|
|
test('box_sizing_border_box_percent', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth("50%");
|
|
root_child0.setHeight("25%");
|
|
root_child0.setPadding(Edge.All, 4);
|
|
root_child0.setBorder(Edge.All, 16);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
});
|
|
test('box_sizing_content_box_absolute', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setHeight("25%");
|
|
root_child0.setPadding(Edge.All, 12);
|
|
root_child0.setBorder(Edge.All, 8);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPositionType(PositionType.Absolute);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(40);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(60);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(40);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
});
|
|
test('box_sizing_border_box_absolute', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setHeight("25%");
|
|
root_child0.setPadding(Edge.All, 12);
|
|
root_child0.setBorder(Edge.All, 8);
|
|
root_child0.setPositionType(PositionType.Absolute);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(40);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(60);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(40);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
});
|
|
test('box_sizing_content_box_comtaining_block', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 12);
|
|
root.setBorder(Edge.All, 8);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setPositionType(PositionType.Static);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0.setWidth(50);
|
|
root_child0_child0.setHeight("25%");
|
|
root_child0_child0.setPositionType(PositionType.Absolute);
|
|
root_child0.insertChild(root_child0_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(140);
|
|
expect(root.getComputedHeight()).toBe(140);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(20);
|
|
expect(root_child0.getComputedTop()).toBe(20);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(31);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(140);
|
|
expect(root.getComputedHeight()).toBe(140);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(20);
|
|
expect(root_child0.getComputedTop()).toBe(20);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(31);
|
|
});
|
|
test('box_sizing_border_box_comtaining_block', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 12);
|
|
root.setBorder(Edge.All, 8);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setPositionType(PositionType.Static);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0.setWidth(50);
|
|
root_child0_child0.setHeight("25%");
|
|
root_child0_child0.setPositionType(PositionType.Absolute);
|
|
root_child0.insertChild(root_child0_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(20);
|
|
expect(root_child0.getComputedTop()).toBe(20);
|
|
expect(root_child0.getComputedWidth()).toBe(60);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(21);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(20);
|
|
expect(root_child0.getComputedTop()).toBe(20);
|
|
expect(root_child0.getComputedWidth()).toBe(60);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(21);
|
|
});
|
|
test('box_sizing_content_box_padding_only', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 5);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(110);
|
|
expect(root.getComputedHeight()).toBe(110);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(110);
|
|
expect(root.getComputedHeight()).toBe(110);
|
|
});
|
|
test('box_sizing_content_box_padding_only_percent', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(150);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(50);
|
|
root_child0.setHeight(75);
|
|
root_child0.setPadding(Edge.All, "10%");
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(150);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(70);
|
|
expect(root_child0.getComputedHeight()).toBe(95);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(150);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(30);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(70);
|
|
expect(root_child0.getComputedHeight()).toBe(95);
|
|
});
|
|
test('box_sizing_border_box_padding_only', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 5);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_padding_only_percent', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(150);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(50);
|
|
root_child0.setHeight(75);
|
|
root_child0.setPadding(Edge.All, "10%");
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(150);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(75);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(150);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(75);
|
|
});
|
|
test('box_sizing_content_box_border_only', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBorder(Edge.All, 10);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(120);
|
|
expect(root.getComputedHeight()).toBe(120);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(120);
|
|
expect(root.getComputedHeight()).toBe(120);
|
|
});
|
|
test('box_sizing_content_box_border_only_percent', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth("50%");
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
});
|
|
test('box_sizing_border_box_border_only', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBorder(Edge.All, 10);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_border_only_percent', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth("50%");
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(0);
|
|
});
|
|
test('box_sizing_content_box_no_padding_no_border', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_no_padding_no_border', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_content_box_children', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 5);
|
|
root.setBorder(Edge.All, 10);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(25);
|
|
root_child0.setHeight(25);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
|
|
const root_child2 = Yoga.Node.create(config);
|
|
root_child2.setWidth(25);
|
|
root_child2.setHeight(25);
|
|
root.insertChild(root_child2, 2);
|
|
|
|
const root_child3 = Yoga.Node.create(config);
|
|
root_child3.setWidth(25);
|
|
root_child3.setHeight(25);
|
|
root.insertChild(root_child3, 3);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(130);
|
|
expect(root.getComputedHeight()).toBe(130);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(15);
|
|
expect(root_child0.getComputedTop()).toBe(15);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(15);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(15);
|
|
expect(root_child2.getComputedTop()).toBe(65);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(15);
|
|
expect(root_child3.getComputedTop()).toBe(90);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(130);
|
|
expect(root.getComputedHeight()).toBe(130);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(90);
|
|
expect(root_child0.getComputedTop()).toBe(15);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(90);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(90);
|
|
expect(root_child2.getComputedTop()).toBe(65);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(90);
|
|
expect(root_child3.getComputedTop()).toBe(90);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_border_box_children', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 5);
|
|
root.setBorder(Edge.All, 10);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(25);
|
|
root_child0.setHeight(25);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
|
|
const root_child2 = Yoga.Node.create(config);
|
|
root_child2.setWidth(25);
|
|
root_child2.setHeight(25);
|
|
root.insertChild(root_child2, 2);
|
|
|
|
const root_child3 = Yoga.Node.create(config);
|
|
root_child3.setWidth(25);
|
|
root_child3.setHeight(25);
|
|
root.insertChild(root_child3, 3);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(15);
|
|
expect(root_child0.getComputedTop()).toBe(15);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(15);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(15);
|
|
expect(root_child2.getComputedTop()).toBe(65);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(15);
|
|
expect(root_child3.getComputedTop()).toBe(90);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(60);
|
|
expect(root_child0.getComputedTop()).toBe(15);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(60);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(60);
|
|
expect(root_child2.getComputedTop()).toBe(65);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(60);
|
|
expect(root_child3.getComputedTop()).toBe(90);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_content_box_siblings', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(25);
|
|
root_child0.setHeight(25);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root_child1.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child1.setPadding(Edge.All, 10);
|
|
root_child1.setBorder(Edge.All, 10);
|
|
root.insertChild(root_child1, 1);
|
|
|
|
const root_child2 = Yoga.Node.create(config);
|
|
root_child2.setWidth(25);
|
|
root_child2.setHeight(25);
|
|
root.insertChild(root_child2, 2);
|
|
|
|
const root_child3 = Yoga.Node.create(config);
|
|
root_child3.setWidth(25);
|
|
root_child3.setHeight(25);
|
|
root.insertChild(root_child3, 3);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(25);
|
|
expect(root_child1.getComputedWidth()).toBe(65);
|
|
expect(root_child1.getComputedHeight()).toBe(65);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(0);
|
|
expect(root_child2.getComputedTop()).toBe(90);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(0);
|
|
expect(root_child3.getComputedTop()).toBe(115);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(75);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(35);
|
|
expect(root_child1.getComputedTop()).toBe(25);
|
|
expect(root_child1.getComputedWidth()).toBe(65);
|
|
expect(root_child1.getComputedHeight()).toBe(65);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(75);
|
|
expect(root_child2.getComputedTop()).toBe(90);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(75);
|
|
expect(root_child3.getComputedTop()).toBe(115);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_border_box_siblings', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(25);
|
|
root_child0.setHeight(25);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root_child1.setPadding(Edge.All, 10);
|
|
root_child1.setBorder(Edge.All, 10);
|
|
root.insertChild(root_child1, 1);
|
|
|
|
const root_child2 = Yoga.Node.create(config);
|
|
root_child2.setWidth(25);
|
|
root_child2.setHeight(25);
|
|
root.insertChild(root_child2, 2);
|
|
|
|
const root_child3 = Yoga.Node.create(config);
|
|
root_child3.setWidth(25);
|
|
root_child3.setHeight(25);
|
|
root.insertChild(root_child3, 3);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(25);
|
|
expect(root_child1.getComputedWidth()).toBe(40);
|
|
expect(root_child1.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(0);
|
|
expect(root_child2.getComputedTop()).toBe(65);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(0);
|
|
expect(root_child3.getComputedTop()).toBe(90);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(75);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(25);
|
|
expect(root_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(60);
|
|
expect(root_child1.getComputedTop()).toBe(25);
|
|
expect(root_child1.getComputedWidth()).toBe(40);
|
|
expect(root_child1.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child2.getComputedLeft()).toBe(75);
|
|
expect(root_child2.getComputedTop()).toBe(65);
|
|
expect(root_child2.getComputedWidth()).toBe(25);
|
|
expect(root_child2.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child3.getComputedLeft()).toBe(75);
|
|
expect(root_child3.getComputedTop()).toBe(90);
|
|
expect(root_child3.getComputedWidth()).toBe(25);
|
|
expect(root_child3.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_content_box_max_width', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setMaxWidth(50);
|
|
root_child0.setHeight(25);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(65);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(65);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_border_box_max_width', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setMaxWidth(50);
|
|
root_child0.setHeight(25);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_content_box_max_height', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(50);
|
|
root_child0.setMaxHeight(50);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_border_box_max_height', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(50);
|
|
root_child0.setMaxHeight(50);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_content_box_min_width', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setMinWidth(50);
|
|
root_child0.setHeight(25);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(65);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(65);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(65);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_border_box_min_width', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setMinWidth(50);
|
|
root_child0.setHeight(25);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(40);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_content_box_min_height', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(50);
|
|
root_child0.setMinHeight(50);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(90);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(90);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(90);
|
|
expect(root_child0.getComputedHeight()).toBe(90);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(90);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_border_box_min_height', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(50);
|
|
root_child0.setMinHeight(50);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 15);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child1 = Yoga.Node.create(config);
|
|
root_child1.setWidth(25);
|
|
root_child1.setHeight(25);
|
|
root.insertChild(root_child1, 1);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(50);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(0);
|
|
expect(root_child1.getComputedTop()).toBe(50);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(50);
|
|
|
|
expect(root_child1.getComputedLeft()).toBe(75);
|
|
expect(root_child1.getComputedTop()).toBe(50);
|
|
expect(root_child1.getComputedWidth()).toBe(25);
|
|
expect(root_child1.getComputedHeight()).toBe(25);
|
|
});
|
|
test('box_sizing_content_box_no_height_no_width', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 2);
|
|
root_child0.setBorder(Edge.All, 7);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(18);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(18);
|
|
});
|
|
test('box_sizing_border_box_no_height_no_width', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setPadding(Edge.All, 2);
|
|
root_child0.setBorder(Edge.All, 7);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(18);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(18);
|
|
});
|
|
test('box_sizing_content_box_nested', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.setPadding(Edge.All, 15);
|
|
root.setBorder(Edge.All, 3);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(20);
|
|
root_child0.setHeight(20);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 2);
|
|
root_child0.setBorder(Edge.All, 7);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0.setWidth(10);
|
|
root_child0_child0.setHeight(5);
|
|
root_child0_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0_child0.setPadding(Edge.All, 1);
|
|
root_child0_child0.setBorder(Edge.All, 2);
|
|
root_child0.insertChild(root_child0_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(136);
|
|
expect(root.getComputedHeight()).toBe(136);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(18);
|
|
expect(root_child0.getComputedTop()).toBe(18);
|
|
expect(root_child0.getComputedWidth()).toBe(38);
|
|
expect(root_child0.getComputedHeight()).toBe(38);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(9);
|
|
expect(root_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(16);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(11);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(136);
|
|
expect(root.getComputedHeight()).toBe(136);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(80);
|
|
expect(root_child0.getComputedTop()).toBe(18);
|
|
expect(root_child0.getComputedWidth()).toBe(38);
|
|
expect(root_child0.getComputedHeight()).toBe(38);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(13);
|
|
expect(root_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(16);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(11);
|
|
});
|
|
test('box_sizing_border_box_nested', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 15);
|
|
root.setBorder(Edge.All, 3);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(20);
|
|
root_child0.setHeight(20);
|
|
root_child0.setPadding(Edge.All, 2);
|
|
root_child0.setBorder(Edge.All, 7);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0.setWidth(10);
|
|
root_child0_child0.setHeight(5);
|
|
root_child0_child0.setPadding(Edge.All, 1);
|
|
root_child0_child0.setBorder(Edge.All, 2);
|
|
root_child0.insertChild(root_child0_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(18);
|
|
expect(root_child0.getComputedTop()).toBe(18);
|
|
expect(root_child0.getComputedWidth()).toBe(20);
|
|
expect(root_child0.getComputedHeight()).toBe(20);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(9);
|
|
expect(root_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(10);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(6);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(62);
|
|
expect(root_child0.getComputedTop()).toBe(18);
|
|
expect(root_child0.getComputedWidth()).toBe(20);
|
|
expect(root_child0.getComputedHeight()).toBe(20);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(1);
|
|
expect(root_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(10);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(6);
|
|
});
|
|
test('box_sizing_content_box_nested_alternating', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.setPadding(Edge.All, 3);
|
|
root.setBorder(Edge.All, 2);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(40);
|
|
root_child0.setHeight(40);
|
|
root_child0.setPadding(Edge.All, 8);
|
|
root_child0.setBorder(Edge.All, 2);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0.setWidth(20);
|
|
root_child0_child0.setHeight(25);
|
|
root_child0_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0_child0.setPadding(Edge.All, 3);
|
|
root_child0_child0.setBorder(Edge.All, 6);
|
|
root_child0.insertChild(root_child0_child0, 0);
|
|
|
|
const root_child0_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0_child0.setWidth(10);
|
|
root_child0_child0_child0.setHeight(5);
|
|
root_child0_child0_child0.setPadding(Edge.All, 1);
|
|
root_child0_child0_child0.setBorder(Edge.All, 1);
|
|
root_child0_child0.insertChild(root_child0_child0_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(110);
|
|
expect(root.getComputedHeight()).toBe(110);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(5);
|
|
expect(root_child0.getComputedTop()).toBe(5);
|
|
expect(root_child0.getComputedWidth()).toBe(40);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0_child0.getComputedTop()).toBe(10);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(38);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(43);
|
|
|
|
expect(root_child0_child0_child0.getComputedLeft()).toBe(9);
|
|
expect(root_child0_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0_child0.getComputedWidth()).toBe(10);
|
|
expect(root_child0_child0_child0.getComputedHeight()).toBe(5);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(110);
|
|
expect(root.getComputedHeight()).toBe(110);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(65);
|
|
expect(root_child0.getComputedTop()).toBe(5);
|
|
expect(root_child0.getComputedWidth()).toBe(40);
|
|
expect(root_child0.getComputedHeight()).toBe(40);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(-8);
|
|
expect(root_child0_child0.getComputedTop()).toBe(10);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(38);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(43);
|
|
|
|
expect(root_child0_child0_child0.getComputedLeft()).toBe(19);
|
|
expect(root_child0_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0_child0.getComputedWidth()).toBe(10);
|
|
expect(root_child0_child0_child0.getComputedHeight()).toBe(5);
|
|
});
|
|
test('box_sizing_border_box_nested_alternating', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.All, 3);
|
|
root.setBorder(Edge.All, 2);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setWidth(40);
|
|
root_child0.setHeight(40);
|
|
root_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0.setPadding(Edge.All, 8);
|
|
root_child0.setBorder(Edge.All, 2);
|
|
root.insertChild(root_child0, 0);
|
|
|
|
const root_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0.setWidth(20);
|
|
root_child0_child0.setHeight(25);
|
|
root_child0_child0.setPadding(Edge.All, 3);
|
|
root_child0_child0.setBorder(Edge.All, 6);
|
|
root_child0.insertChild(root_child0_child0, 0);
|
|
|
|
const root_child0_child0_child0 = Yoga.Node.create(config);
|
|
root_child0_child0_child0.setWidth(10);
|
|
root_child0_child0_child0.setHeight(5);
|
|
root_child0_child0_child0.setBoxSizing(BoxSizing.ContentBox);
|
|
root_child0_child0_child0.setPadding(Edge.All, 1);
|
|
root_child0_child0_child0.setBorder(Edge.All, 1);
|
|
root_child0_child0.insertChild(root_child0_child0_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(5);
|
|
expect(root_child0.getComputedTop()).toBe(5);
|
|
expect(root_child0.getComputedWidth()).toBe(60);
|
|
expect(root_child0.getComputedHeight()).toBe(60);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(10);
|
|
expect(root_child0_child0.getComputedTop()).toBe(10);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(20);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child0_child0_child0.getComputedLeft()).toBe(9);
|
|
expect(root_child0_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0_child0.getComputedWidth()).toBe(14);
|
|
expect(root_child0_child0_child0.getComputedHeight()).toBe(9);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(35);
|
|
expect(root_child0.getComputedTop()).toBe(5);
|
|
expect(root_child0.getComputedWidth()).toBe(60);
|
|
expect(root_child0.getComputedHeight()).toBe(60);
|
|
|
|
expect(root_child0_child0.getComputedLeft()).toBe(30);
|
|
expect(root_child0_child0.getComputedTop()).toBe(10);
|
|
expect(root_child0_child0.getComputedWidth()).toBe(20);
|
|
expect(root_child0_child0.getComputedHeight()).toBe(25);
|
|
|
|
expect(root_child0_child0_child0.getComputedLeft()).toBe(-3);
|
|
expect(root_child0_child0_child0.getComputedTop()).toBe(9);
|
|
expect(root_child0_child0_child0.getComputedWidth()).toBe(14);
|
|
expect(root_child0_child0_child0.getComputedHeight()).toBe(9);
|
|
});
|
|
test('box_sizing_border_box_flex_basis_row', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setFlexDirection(FlexDirection.Row);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setFlexBasis(50);
|
|
root_child0.setHeight(25);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 10);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(30);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(50);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(50);
|
|
expect(root_child0.getComputedHeight()).toBe(30);
|
|
});
|
|
test('box_sizing_border_box_flex_basis_column', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
|
|
const root_child0 = Yoga.Node.create(config);
|
|
root_child0.setFlexBasis(50);
|
|
root_child0.setHeight(25);
|
|
root_child0.setPadding(Edge.All, 5);
|
|
root_child0.setBorder(Edge.All, 10);
|
|
root.insertChild(root_child0, 0);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(50);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
expect(root_child0.getComputedLeft()).toBe(0);
|
|
expect(root_child0.getComputedTop()).toBe(0);
|
|
expect(root_child0.getComputedWidth()).toBe(100);
|
|
expect(root_child0.getComputedHeight()).toBe(50);
|
|
});
|
|
test('box_sizing_content_box_padding_start', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.Start, 5);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_padding_start', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.Start, 5);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_content_box_padding_end', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.End, 5);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_padding_end', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setPadding(Edge.End, 5);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_content_box_border_start', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBorder(Edge.Start, 5);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_border_start', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBorder(Edge.Start, 5);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_content_box_border_end', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBorder(Edge.End, 5);
|
|
root.setBoxSizing(BoxSizing.ContentBox);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(105);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|
|
test('box_sizing_border_box_border_end', () => {
|
|
const config = Yoga.Config.create();
|
|
|
|
const root = Yoga.Node.create(config);
|
|
root.setPositionType(PositionType.Absolute);
|
|
root.setWidth(100);
|
|
root.setHeight(100);
|
|
root.setBorder(Edge.End, 5);
|
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
|
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
|
|
|
expect(root.getComputedLeft()).toBe(0);
|
|
expect(root.getComputedTop()).toBe(0);
|
|
expect(root.getComputedWidth()).toBe(100);
|
|
expect(root.getComputedHeight()).toBe(100);
|
|
});
|