Skip to content

Commit

Permalink
Add yoga tests (diegomura#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored Apr 25, 2021
1 parent 951806b commit d075289
Show file tree
Hide file tree
Showing 28 changed files with 16,149 additions and 0 deletions.
942 changes: 942 additions & 0 deletions packages/yoga/tests/absolutePosition.test.js

Large diffs are not rendered by default.

1,770 changes: 1,770 additions & 0 deletions packages/yoga/tests/alignContent.test.js

Large diffs are not rendered by default.

2,010 changes: 2,010 additions & 0 deletions packages/yoga/tests/alignItems.test.js

Large diffs are not rendered by default.

216 changes: 216 additions & 0 deletions packages/yoga/tests/alignSelf.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
const Yoga = require('../src/dist/entry-browser');

describe('Align self', () => {
test('align_self_center', () => {
const root = Yoga.Node.create();

root.setWidth(100);
root.setHeight(100);

const child = Yoga.Node.create();
child.setAlignSelf(Yoga.ALIGN_CENTER);
child.setWidth(10);
child.setHeight(10);
root.insertChild(child, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(45);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);

root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(45);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);
});

test('align_self_flex_end', () => {
const root = Yoga.Node.create();

root.setWidth(100);
root.setHeight(100);

const child = Yoga.Node.create();
child.setAlignSelf(Yoga.ALIGN_FLEX_END);
child.setWidth(10);
child.setHeight(10);
root.insertChild(child, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(90);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);

root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(0);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);
});

test('align_self_flex_start', () => {
const root = Yoga.Node.create();

root.setWidth(100);
root.setHeight(100);

const child = Yoga.Node.create();
child.setAlignSelf(Yoga.ALIGN_FLEX_START);
child.setWidth(10);
child.setHeight(10);
root.insertChild(child, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(0);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);

root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(90);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);
});

test('align_self_flex_end_override_flex_start', () => {
const root = Yoga.Node.create();

root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);

const child = Yoga.Node.create();
child.setAlignSelf(Yoga.ALIGN_FLEX_END);
child.setWidth(10);
child.setHeight(10);
root.insertChild(child, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(90);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);

root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(0);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(10);
expect(child.getComputedLayout().height).toBe(10);
});

test('align_self_baseline', () => {
const root = Yoga.Node.create();

root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(100);
root.setHeight(100);

const child = Yoga.Node.create();
child.setAlignSelf(Yoga.ALIGN_BASELINE);
child.setWidth(50);
child.setHeight(50);
root.insertChild(child, 0);

const child2 = Yoga.Node.create();
child2.setAlignSelf(Yoga.ALIGN_BASELINE);
child2.setWidth(50);
child2.setHeight(20);
root.insertChild(child2, 1);

const child3 = Yoga.Node.create();
child3.setWidth(50);
child3.setHeight(10);
child2.insertChild(child3, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(0);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(50);
expect(child.getComputedLayout().height).toBe(50);

expect(child2.getComputedLayout().left).toBe(50);
expect(child2.getComputedLayout().top).toBe(40);
expect(child2.getComputedLayout().width).toBe(50);
expect(child2.getComputedLayout().height).toBe(20);

expect(child3.getComputedLayout().left).toBe(0);
expect(child3.getComputedLayout().top).toBe(0);
expect(child3.getComputedLayout().width).toBe(50);
expect(child3.getComputedLayout().height).toBe(10);

root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL);

expect(root.getComputedLayout().left).toBe(0);
expect(root.getComputedLayout().top).toBe(0);
expect(root.getComputedLayout().width).toBe(100);
expect(root.getComputedLayout().height).toBe(100);

expect(child.getComputedLayout().left).toBe(50);
expect(child.getComputedLayout().top).toBe(0);
expect(child.getComputedLayout().width).toBe(50);
expect(child.getComputedLayout().height).toBe(50);

expect(child2.getComputedLayout().left).toBe(0);
expect(child2.getComputedLayout().top).toBe(40);
expect(child2.getComputedLayout().width).toBe(50);
expect(child2.getComputedLayout().height).toBe(20);

expect(child3.getComputedLayout().left).toBe(0);
expect(child3.getComputedLayout().top).toBe(0);
expect(child3.getComputedLayout().width).toBe(50);
expect(child3.getComputedLayout().height).toBe(10);
});
});
Loading

0 comments on commit d075289

Please sign in to comment.