Skip to content

Commit

Permalink
Add some tests for justification under row-reverse (#1560)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1560

I added these when I was trying to debug the Facepile break removing the row-reverse errata caused. Yoga is doing the right thing, and the tests pass. We didn't have this specific coverage before, so add it.

Reviewed By: joevilches

Differential Revision: D52909633

fbshipit-source-id: d1e8f55bb534d76bd7dfdc46a1e1cc6f0a3ca211
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jan 20, 2024
1 parent 8744792 commit 395c596
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 3 deletions.
12 changes: 12 additions & 0 deletions gentest/fixtures/YGJustifyContentTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@
<div style="width: 50px; height: 50px;"></div>
</div>
</div>

<div id="justify_content_flex_start_row_reverse" style="width: 100px; height: 100px; flex-direction: row-reverse; justify-content: flex-start;">
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
</div>

<div id="justify_content_flex_end_row_reverse" style="width: 100px; height: 100px; flex-direction: row-reverse; justify-content: flex-start;">
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
</div>
138 changes: 137 additions & 1 deletion java/tests/com/facebook/yoga/YGJustifyContentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<<f1f4fb9b85e0a3a11d9fd07de9412a24>>
* @generated SignedSource<<88d2dd510790179efc539f8d3cba00bb>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGJustifyContentTest.html
*/

Expand Down Expand Up @@ -1239,6 +1239,142 @@ public void test_justify_content_space_between_indefinite_container_dim_with_fre
assertEquals(50f, root_child0_child1.getLayoutHeight(), 0.0f);
}

@Test
public void test_justify_content_flex_start_row_reverse() {
YogaConfig config = YogaConfigFactory.create();

final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW_REVERSE);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);

final YogaNode root_child0 = createNode(config);
root_child0.setWidth(20f);
root.addChildAt(root_child0, 0);

final YogaNode root_child1 = createNode(config);
root_child1.setWidth(20f);
root.addChildAt(root_child1, 1);

final YogaNode root_child2 = createNode(config);
root_child2.setWidth(20f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);

assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);

assertEquals(80f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);

assertEquals(60f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(20f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);

assertEquals(40f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(20f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);

root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);

assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);

assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);

assertEquals(20f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(20f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);

assertEquals(40f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(20f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
}

@Test
public void test_justify_content_flex_end_row_reverse() {
YogaConfig config = YogaConfigFactory.create();

final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW_REVERSE);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(100f);
root.setHeight(100f);

final YogaNode root_child0 = createNode(config);
root_child0.setWidth(20f);
root.addChildAt(root_child0, 0);

final YogaNode root_child1 = createNode(config);
root_child1.setWidth(20f);
root.addChildAt(root_child1, 1);

final YogaNode root_child2 = createNode(config);
root_child2.setWidth(20f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);

assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);

assertEquals(80f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);

assertEquals(60f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(20f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);

assertEquals(40f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(20f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);

root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);

assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);

assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);

assertEquals(20f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(20f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);

assertEquals(40f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(20f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
}

private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
Expand Down
148 changes: 147 additions & 1 deletion javascript/tests/generated/YGJustifyContentTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<<1bf27853929efafcaddd97d42631623a>>
* @generated SignedSource<<22142a9aaf328ac001ca4629e6c12f87>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGJustifyContentTest.html
*/

Expand Down Expand Up @@ -1334,3 +1334,149 @@ test('justify_content_space_between_indefinite_container_dim_with_free_space', (
config.free();
}
});
test('justify_content_flex_start_row_reverse', () => {
const config = Yoga.Config.create();
let root;

try {
root = Yoga.Node.create(config);
root.setFlexDirection(FlexDirection.RowReverse);
root.setPositionType(PositionType.Absolute);
root.setWidth(100);
root.setHeight(100);

const root_child0 = Yoga.Node.create(config);
root_child0.setWidth(20);
root.insertChild(root_child0, 0);

const root_child1 = Yoga.Node.create(config);
root_child1.setWidth(20);
root.insertChild(root_child1, 1);

const root_child2 = Yoga.Node.create(config);
root_child2.setWidth(20);
root.insertChild(root_child2, 2);
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(80);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(100);

expect(root_child1.getComputedLeft()).toBe(60);
expect(root_child1.getComputedTop()).toBe(0);
expect(root_child1.getComputedWidth()).toBe(20);
expect(root_child1.getComputedHeight()).toBe(100);

expect(root_child2.getComputedLeft()).toBe(40);
expect(root_child2.getComputedTop()).toBe(0);
expect(root_child2.getComputedWidth()).toBe(20);
expect(root_child2.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);

expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(100);

expect(root_child1.getComputedLeft()).toBe(20);
expect(root_child1.getComputedTop()).toBe(0);
expect(root_child1.getComputedWidth()).toBe(20);
expect(root_child1.getComputedHeight()).toBe(100);

expect(root_child2.getComputedLeft()).toBe(40);
expect(root_child2.getComputedTop()).toBe(0);
expect(root_child2.getComputedWidth()).toBe(20);
expect(root_child2.getComputedHeight()).toBe(100);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}

config.free();
}
});
test('justify_content_flex_end_row_reverse', () => {
const config = Yoga.Config.create();
let root;

try {
root = Yoga.Node.create(config);
root.setFlexDirection(FlexDirection.RowReverse);
root.setPositionType(PositionType.Absolute);
root.setWidth(100);
root.setHeight(100);

const root_child0 = Yoga.Node.create(config);
root_child0.setWidth(20);
root.insertChild(root_child0, 0);

const root_child1 = Yoga.Node.create(config);
root_child1.setWidth(20);
root.insertChild(root_child1, 1);

const root_child2 = Yoga.Node.create(config);
root_child2.setWidth(20);
root.insertChild(root_child2, 2);
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(80);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(100);

expect(root_child1.getComputedLeft()).toBe(60);
expect(root_child1.getComputedTop()).toBe(0);
expect(root_child1.getComputedWidth()).toBe(20);
expect(root_child1.getComputedHeight()).toBe(100);

expect(root_child2.getComputedLeft()).toBe(40);
expect(root_child2.getComputedTop()).toBe(0);
expect(root_child2.getComputedWidth()).toBe(20);
expect(root_child2.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);

expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(100);

expect(root_child1.getComputedLeft()).toBe(20);
expect(root_child1.getComputedTop()).toBe(0);
expect(root_child1.getComputedWidth()).toBe(20);
expect(root_child1.getComputedHeight()).toBe(100);

expect(root_child2.getComputedLeft()).toBe(40);
expect(root_child2.getComputedTop()).toBe(0);
expect(root_child2.getComputedWidth()).toBe(20);
expect(root_child2.getComputedHeight()).toBe(100);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}

config.free();
}
});
Loading

0 comments on commit 395c596

Please sign in to comment.