Add some tests for padding and border for absolute positioning (#1650)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1650

See https://github.com/facebook/yoga/issues/1436#issuecomment-2070877918

Reviewed By: NickGerleman

Differential Revision: D56478788

fbshipit-source-id: 94a552ed55eb4127eddc6c2018706661fff64093
This commit is contained in:
Joe Vilches
2024-04-23 21:02:36 -07:00
committed by Facebook GitHub Bot
parent 932361cdbf
commit dc23284cf7
4 changed files with 499 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<777a238fc942436d2c803822110bcd07>>
* @generated SignedSource<<9c27293180ef7ffd5b683046588f9dd7>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAbsolutePositionTest.html
*/
@@ -1497,6 +1497,172 @@ test('absolute_layout_padding_bottom', () => {
config.free();
}
});
test('absolute_layout_padding', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
const root_child0 = Yoga.Node.create(config);
root_child0.setMargin(Edge.Left, 10);
root_child0.setMargin(Edge.Top, 10);
root_child0.setMargin(Edge.Right, 10);
root_child0.setMargin(Edge.Bottom, 10);
root_child0.setWidth(200);
root_child0.setHeight(200);
root.insertChild(root_child0, 0);
const root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setPositionType(PositionType.Static);
root_child0_child0.setPadding(Edge.Left, 50);
root_child0_child0.setPadding(Edge.Top, 50);
root_child0_child0.setPadding(Edge.Right, 50);
root_child0_child0.setPadding(Edge.Bottom, 50);
root_child0_child0.setWidth(200);
root_child0_child0.setHeight(200);
root_child0.insertChild(root_child0_child0, 0);
const root_child0_child0_child0 = Yoga.Node.create(config);
root_child0_child0_child0.setPositionType(PositionType.Absolute);
root_child0_child0_child0.setWidth(50);
root_child0_child0_child0.setHeight(50);
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(220);
expect(root.getComputedHeight()).toBe(220);
expect(root_child0.getComputedLeft()).toBe(10);
expect(root_child0.getComputedTop()).toBe(10);
expect(root_child0.getComputedWidth()).toBe(200);
expect(root_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(200);
expect(root_child0_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0_child0.getComputedLeft()).toBe(50);
expect(root_child0_child0_child0.getComputedTop()).toBe(50);
expect(root_child0_child0_child0.getComputedWidth()).toBe(50);
expect(root_child0_child0_child0.getComputedHeight()).toBe(50);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(220);
expect(root.getComputedHeight()).toBe(220);
expect(root_child0.getComputedLeft()).toBe(10);
expect(root_child0.getComputedTop()).toBe(10);
expect(root_child0.getComputedWidth()).toBe(200);
expect(root_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(200);
expect(root_child0_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0_child0.getComputedLeft()).toBe(100);
expect(root_child0_child0_child0.getComputedTop()).toBe(50);
expect(root_child0_child0_child0.getComputedWidth()).toBe(50);
expect(root_child0_child0_child0.getComputedHeight()).toBe(50);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('absolute_layout_border', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
const root_child0 = Yoga.Node.create(config);
root_child0.setMargin(Edge.Left, 10);
root_child0.setMargin(Edge.Top, 10);
root_child0.setMargin(Edge.Right, 10);
root_child0.setMargin(Edge.Bottom, 10);
root_child0.setWidth(200);
root_child0.setHeight(200);
root.insertChild(root_child0, 0);
const root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setPositionType(PositionType.Static);
root_child0_child0.setBorder(Edge.Left, 10);
root_child0_child0.setBorder(Edge.Top, 10);
root_child0_child0.setBorder(Edge.Right, 10);
root_child0_child0.setBorder(Edge.Bottom, 10);
root_child0_child0.setWidth(200);
root_child0_child0.setHeight(200);
root_child0.insertChild(root_child0_child0, 0);
const root_child0_child0_child0 = Yoga.Node.create(config);
root_child0_child0_child0.setPositionType(PositionType.Absolute);
root_child0_child0_child0.setWidth(50);
root_child0_child0_child0.setHeight(50);
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(220);
expect(root.getComputedHeight()).toBe(220);
expect(root_child0.getComputedLeft()).toBe(10);
expect(root_child0.getComputedTop()).toBe(10);
expect(root_child0.getComputedWidth()).toBe(200);
expect(root_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(200);
expect(root_child0_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0_child0.getComputedLeft()).toBe(10);
expect(root_child0_child0_child0.getComputedTop()).toBe(10);
expect(root_child0_child0_child0.getComputedWidth()).toBe(50);
expect(root_child0_child0_child0.getComputedHeight()).toBe(50);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(220);
expect(root.getComputedHeight()).toBe(220);
expect(root_child0.getComputedLeft()).toBe(10);
expect(root_child0.getComputedTop()).toBe(10);
expect(root_child0.getComputedWidth()).toBe(200);
expect(root_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(200);
expect(root_child0_child0.getComputedHeight()).toBe(200);
expect(root_child0_child0_child0.getComputedLeft()).toBe(140);
expect(root_child0_child0_child0.getComputedTop()).toBe(10);
expect(root_child0_child0_child0.getComputedWidth()).toBe(50);
expect(root_child0_child0_child0.getComputedHeight()).toBe(50);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('absolute_layout_column_reverse_margin_border', () => {
const config = Yoga.Config.create();
let root;