Skip to content

Commit

Permalink
Enable previously broken absolute positioning tests (#1488)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1488

These were disabled when they were written because they were broken. The recent changes made them pass now so lets enable them. I also added another test that is already passing

Reviewed By: NickGerleman

Differential Revision: D51404875

fbshipit-source-id: ed10004968b871c1d033640d75138f00afc15968
  • Loading branch information
joevilches authored and facebook-github-bot committed Dec 8, 2023
1 parent bc5dc2d commit 1ea5756
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 20 deletions.
6 changes: 3 additions & 3 deletions gentest/fixtures/YGAbsolutePositionTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@
<div style="position:absolute; width:100px; height:50%;"></div>
</div>

<div id="absolute_layout_padding_left" data-disabled="true" style="width:200px; height:200px; padding-left:100px;">
<div id="absolute_layout_padding_left" style="width:200px; height:200px; padding-left:100px;">
<div style="position:absolute; width:50px; height:50px;"></div>
</div>

<div id="absolute_layout_padding_right" data-disabled="true" style="width:200px; height:200px; padding-right:100px;">
<div id="absolute_layout_padding_right" style="width:200px; height:200px; padding-right:100px;">
<div style="position:absolute; width:50px; height:50px;"></div>
</div>

<div id="absolute_layout_padding_top" data-disabled="true" style="width:200px; height:200px; padding-top:100px;">
<div id="absolute_layout_padding_top" style="width:200px; height:200px; padding-top:100px;">
<div style="position:absolute; width:50px; height:50px;"></div>
</div>

Expand Down
9 changes: 8 additions & 1 deletion gentest/fixtures/YGStaticPositionTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
</div>
</div>

<div id="static_position_absolute_child_containing_block_content_box" data-disabled="true">
<div id="static_position_absolute_child_containing_block_content_box">
<div style="width: 400px; height: 400px; padding: 100px; position: relative">
<div style="height:50px; width: 50%; position: absolute">
</div>
Expand Down Expand Up @@ -633,3 +633,10 @@
</div>
</div>
</div>

<div id="static_position_static_root"
style="height:200px; width: 100px; position: static; padding: 1px 11px 4px 6px;">
<div
style="height: 50%; width: 50%; position: absolute; border-width: 3px 2px 1px 4px; padding: 7px 5px 4px 3px; margin: 11px 15px 1px 12px">
</div>
</div>
3 changes: 0 additions & 3 deletions java/tests/com/facebook/yoga/YGAbsolutePositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ public void test_absolute_layout_percentage_height_based_on_padded_parent_and_al
}

@Test
@Ignore
public void test_absolute_layout_padding_left() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);
Expand Down Expand Up @@ -1258,7 +1257,6 @@ public void test_absolute_layout_padding_left() {
}

@Test
@Ignore
public void test_absolute_layout_padding_right() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);
Expand Down Expand Up @@ -1302,7 +1300,6 @@ public void test_absolute_layout_padding_right() {
}

@Test
@Ignore
public void test_absolute_layout_padding_top() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);
Expand Down
59 changes: 58 additions & 1 deletion java/tests/com/facebook/yoga/YGStaticPositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,6 @@ public void test_static_position_static_child_containing_block_padding_box() {
}

@Test
@Ignore
public void test_static_position_absolute_child_containing_block_content_box() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);
Expand Down Expand Up @@ -5442,6 +5441,64 @@ public void test_static_position_align_flex_end_amalgamation() {
assertEquals(50f, root_child0_child0_child2_child0.getLayoutHeight(), 0.0f);
}

@Test
public void test_static_position_static_root() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);

final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.STATIC);
root.setPadding(YogaEdge.LEFT, 6);
root.setPadding(YogaEdge.TOP, 1);
root.setPadding(YogaEdge.RIGHT, 11);
root.setPadding(YogaEdge.BOTTOM, 4);
root.setWidth(100f);
root.setHeight(200f);

final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setMargin(YogaEdge.LEFT, 12f);
root_child0.setMargin(YogaEdge.TOP, 11f);
root_child0.setMargin(YogaEdge.RIGHT, 15f);
root_child0.setMargin(YogaEdge.BOTTOM, 1f);
root_child0.setPadding(YogaEdge.LEFT, 3);
root_child0.setPadding(YogaEdge.TOP, 7);
root_child0.setPadding(YogaEdge.RIGHT, 5);
root_child0.setPadding(YogaEdge.BOTTOM, 4);
root_child0.setBorder(YogaEdge.LEFT, 4f);
root_child0.setBorder(YogaEdge.TOP, 3f);
root_child0.setBorder(YogaEdge.RIGHT, 2f);
root_child0.setBorder(YogaEdge.BOTTOM, 1f);
root_child0.setWidthPercent(50f);
root_child0.setHeightPercent(50f);
root.addChildAt(root_child0, 0);
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(200f, root.getLayoutHeight(), 0.0f);

assertEquals(18f, root_child0.getLayoutX(), 0.0f);
assertEquals(12f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.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(200f, root.getLayoutHeight(), 0.0f);

assertEquals(24f, root_child0.getLayoutX(), 0.0f);
assertEquals(12f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
}

private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
Expand Down
6 changes: 3 additions & 3 deletions javascript/tests/generated/YGAbsolutePositionTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ test('absolute_layout_percentage_height_based_on_padded_parent_and_align_items_c
config.free();
}
});
test.skip('absolute_layout_padding_left', () => {
test('absolute_layout_padding_left', () => {
const config = Yoga.Config.create();
let root;

Expand Down Expand Up @@ -1405,7 +1405,7 @@ test.skip('absolute_layout_padding_left', () => {
config.free();
}
});
test.skip('absolute_layout_padding_right', () => {
test('absolute_layout_padding_right', () => {
const config = Yoga.Config.create();
let root;

Expand Down Expand Up @@ -1454,7 +1454,7 @@ test.skip('absolute_layout_padding_right', () => {
config.free();
}
});
test.skip('absolute_layout_padding_top', () => {
test('absolute_layout_padding_top', () => {
const config = Yoga.Config.create();
let root;

Expand Down
66 changes: 65 additions & 1 deletion javascript/tests/generated/YGStaticPositionTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ test('static_position_static_child_containing_block_padding_box', () => {
config.free();
}
});
test.skip('static_position_absolute_child_containing_block_content_box', () => {
test('static_position_absolute_child_containing_block_content_box', () => {
const config = Yoga.Config.create();
let root;

Expand Down Expand Up @@ -5765,3 +5765,67 @@ test('static_position_align_flex_end_amalgamation', () => {
config.free();
}
});
test('static_position_static_root', () => {
const config = Yoga.Config.create();
let root;

config.setExperimentalFeatureEnabled(ExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);

try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Static);
root.setPadding(Edge.Left, 6);
root.setPadding(Edge.Top, 1);
root.setPadding(Edge.Right, 11);
root.setPadding(Edge.Bottom, 4);
root.setWidth(100);
root.setHeight(200);

const root_child0 = Yoga.Node.create(config);
root_child0.setPositionType(PositionType.Absolute);
root_child0.setMargin(Edge.Left, 12);
root_child0.setMargin(Edge.Top, 11);
root_child0.setMargin(Edge.Right, 15);
root_child0.setMargin(Edge.Bottom, 1);
root_child0.setPadding(Edge.Left, 3);
root_child0.setPadding(Edge.Top, 7);
root_child0.setPadding(Edge.Right, 5);
root_child0.setPadding(Edge.Bottom, 4);
root_child0.setBorder(Edge.Left, 4);
root_child0.setBorder(Edge.Top, 3);
root_child0.setBorder(Edge.Right, 2);
root_child0.setBorder(Edge.Bottom, 1);
root_child0.setWidth("50%");
root_child0.setHeight("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(200);

expect(root_child0.getComputedLeft()).toBe(18);
expect(root_child0.getComputedTop()).toBe(12);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.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(200);

expect(root_child0.getComputedLeft()).toBe(24);
expect(root_child0.getComputedTop()).toBe(12);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(100);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}

config.free();
}
});
6 changes: 0 additions & 6 deletions tests/generated/YGAbsolutePositionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,6 @@ TEST(YogaTest, absolute_layout_percentage_height_based_on_padded_parent_and_alig
}

TEST(YogaTest, absolute_layout_padding_left) {
GTEST_SKIP();

const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);

Expand Down Expand Up @@ -1271,8 +1269,6 @@ TEST(YogaTest, absolute_layout_padding_left) {
}

TEST(YogaTest, absolute_layout_padding_right) {
GTEST_SKIP();

const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);

Expand Down Expand Up @@ -1317,8 +1313,6 @@ TEST(YogaTest, absolute_layout_padding_right) {
}

TEST(YogaTest, absolute_layout_padding_top) {
GTEST_SKIP();

const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);

Expand Down
61 changes: 59 additions & 2 deletions tests/generated/YGStaticPositionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2497,8 +2497,6 @@ TEST(YogaTest, static_position_static_child_containing_block_padding_box) {
}

TEST(YogaTest, static_position_absolute_child_containing_block_content_box) {
GTEST_SKIP();

const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);

Expand Down Expand Up @@ -5482,3 +5480,62 @@ TEST(YogaTest, static_position_align_flex_end_amalgamation) {

YGConfigFree(config);
}

TEST(YogaTest, static_position_static_root) {
const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);

const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeStatic);
YGNodeStyleSetPadding(root, YGEdgeLeft, 6);
YGNodeStyleSetPadding(root, YGEdgeTop, 1);
YGNodeStyleSetPadding(root, YGEdgeRight, 11);
YGNodeStyleSetPadding(root, YGEdgeBottom, 4);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 200);

const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 12);
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 11);
YGNodeStyleSetMargin(root_child0, YGEdgeRight, 15);
YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 1);
YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 3);
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 7);
YGNodeStyleSetPadding(root_child0, YGEdgeRight, 5);
YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 4);
YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 4);
YGNodeStyleSetBorder(root_child0, YGEdgeTop, 3);
YGNodeStyleSetBorder(root_child0, YGEdgeRight, 2);
YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 1);
YGNodeStyleSetWidthPercent(root_child0, 50);
YGNodeStyleSetHeightPercent(root_child0, 50);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(18, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(12, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(24, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(12, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));

YGNodeFreeRecursive(root);

YGConfigFree(config);
}

0 comments on commit 1ea5756

Please sign in to comment.