From b227e0e303da8bca754910f55f5d27dd18f3a874 Mon Sep 17 00:00:00 2001 From: Martin Skec Date: Sun, 14 Jan 2024 22:11:28 +0100 Subject: [PATCH] chore(deps): upgraded yoga to v2 and removed bundled package (#2473) --- .changeset/eighty-boats-bow.md | 5 + .eslintrc.js | 1 + jest.config.js | 1 - packages/layout/package.json | 4 +- packages/layout/src/image/measureImage.js | 2 +- packages/layout/src/node/getBorderWidth.js | 2 +- packages/layout/src/node/getMargin.js | 2 +- packages/layout/src/node/getPadding.js | 2 +- packages/layout/src/node/setAlign.js | 2 +- packages/layout/src/node/setBorderWidth.js | 2 +- packages/layout/src/node/setDisplay.js | 2 +- packages/layout/src/node/setFlexDirection.js | 2 +- packages/layout/src/node/setFlexWrap.js | 2 +- packages/layout/src/node/setGap.js | 2 +- packages/layout/src/node/setJustifyContent.js | 2 +- packages/layout/src/node/setMargin.js | 2 +- packages/layout/src/node/setOverflow.js | 2 +- packages/layout/src/node/setPadding.js | 2 +- packages/layout/src/node/setPosition.js | 2 +- packages/layout/src/node/setPositionType.js | 2 +- .../layout/src/steps/resolveDimensions.js | 2 +- packages/layout/src/svg/measureSvg.js | 2 +- packages/layout/src/text/measureText.js | 2 +- .../layout/tests/node/getBorderWidth.test.js | 2 +- packages/layout/tests/node/getMargin.test.js | 2 +- packages/layout/tests/node/getPadding.test.js | 2 +- .../layout/tests/node/setAlignContent.test.js | 2 +- .../layout/tests/node/setAlignItems.test.js | 2 +- .../layout/tests/node/setAlignSelf.test.js | 2 +- .../layout/tests/node/setBorderWidth.test.js | 2 +- packages/layout/tests/node/setDisplay.test.js | 2 +- .../tests/node/setFlexDirection.test.js | 2 +- .../layout/tests/node/setFlexWrap.test.js | 2 +- .../tests/node/setJustifyContent.test.js | 2 +- packages/layout/tests/node/setMargin.test.js | 2 +- .../layout/tests/node/setOverflow.test.js | 2 +- packages/layout/tests/node/setPadding.test.js | 2 +- .../layout/tests/node/setPosition.test.js | 2 +- .../layout/tests/node/setPositionType.test.js | 2 +- packages/yoga/.gitignore | 1 - packages/yoga/CHANGELOG.md | 43 - packages/yoga/README.md | 24 - packages/yoga/babel.config.js | 1 - packages/yoga/index.d.ts | 3 - packages/yoga/index.js | 4 - packages/yoga/package.json | 30 - packages/yoga/rollup.config.js | 25 - packages/yoga/tests/absolutePosition.test.js | 942 -------- packages/yoga/tests/alignContent.test.js | 1770 --------------- packages/yoga/tests/alignItems.test.js | 2010 ----------------- packages/yoga/tests/alignSelf.test.js | 216 -- packages/yoga/tests/aspectRatio.test.js | 731 ------ packages/yoga/tests/border.test.js | 317 --- packages/yoga/tests/computedMargin.test.js | 20 - packages/yoga/tests/computedPadding.test.js | 20 - packages/yoga/tests/defaultValues.test.js | 106 - packages/yoga/tests/dimention.test.js | 245 -- packages/yoga/tests/display.test.js | 294 --- packages/yoga/tests/edge.test.js | 141 -- packages/yoga/tests/flexDirection.test.js | 371 --- packages/yoga/tests/flexSpec.test.js | 435 ---- packages/yoga/tests/flexWrap.test.js | 1607 ------------- packages/yoga/tests/flexbox.test.js | 143 -- packages/yoga/tests/index.test.js | 53 - packages/yoga/tests/infiniteHeight.test.js | 38 - packages/yoga/tests/justifyContent.test.js | 895 -------- packages/yoga/tests/margin.test.js | 1741 -------------- packages/yoga/tests/minMaxDimension.test.js | 1133 ---------- packages/yoga/tests/misc.test.js | 54 - packages/yoga/tests/nodeChild.test.js | 26 - packages/yoga/tests/padding.test.js | 429 ---- packages/yoga/tests/percentage.test.js | 1066 --------- packages/yoga/tests/position.test.js | 232 -- packages/yoga/tests/rounding.test.js | 991 -------- packages/yoga/tests/sizeOverflow.test.js | 147 -- .../tests/zeroOutLayoutRecursivly.test.js | 29 - yarn.lock | 8 +- 77 files changed, 47 insertions(+), 16375 deletions(-) create mode 100644 .changeset/eighty-boats-bow.md delete mode 100644 packages/yoga/.gitignore delete mode 100644 packages/yoga/CHANGELOG.md delete mode 100644 packages/yoga/README.md delete mode 100644 packages/yoga/babel.config.js delete mode 100644 packages/yoga/index.d.ts delete mode 100644 packages/yoga/index.js delete mode 100644 packages/yoga/package.json delete mode 100644 packages/yoga/rollup.config.js delete mode 100644 packages/yoga/tests/absolutePosition.test.js delete mode 100644 packages/yoga/tests/alignContent.test.js delete mode 100644 packages/yoga/tests/alignItems.test.js delete mode 100644 packages/yoga/tests/alignSelf.test.js delete mode 100644 packages/yoga/tests/aspectRatio.test.js delete mode 100644 packages/yoga/tests/border.test.js delete mode 100644 packages/yoga/tests/computedMargin.test.js delete mode 100644 packages/yoga/tests/computedPadding.test.js delete mode 100644 packages/yoga/tests/defaultValues.test.js delete mode 100644 packages/yoga/tests/dimention.test.js delete mode 100644 packages/yoga/tests/display.test.js delete mode 100644 packages/yoga/tests/edge.test.js delete mode 100644 packages/yoga/tests/flexDirection.test.js delete mode 100644 packages/yoga/tests/flexSpec.test.js delete mode 100644 packages/yoga/tests/flexWrap.test.js delete mode 100644 packages/yoga/tests/flexbox.test.js delete mode 100644 packages/yoga/tests/index.test.js delete mode 100644 packages/yoga/tests/infiniteHeight.test.js delete mode 100644 packages/yoga/tests/justifyContent.test.js delete mode 100644 packages/yoga/tests/margin.test.js delete mode 100644 packages/yoga/tests/minMaxDimension.test.js delete mode 100644 packages/yoga/tests/misc.test.js delete mode 100644 packages/yoga/tests/nodeChild.test.js delete mode 100644 packages/yoga/tests/padding.test.js delete mode 100644 packages/yoga/tests/percentage.test.js delete mode 100644 packages/yoga/tests/position.test.js delete mode 100644 packages/yoga/tests/rounding.test.js delete mode 100644 packages/yoga/tests/sizeOverflow.test.js delete mode 100644 packages/yoga/tests/zeroOutLayoutRecursivly.test.js diff --git a/.changeset/eighty-boats-bow.md b/.changeset/eighty-boats-bow.md new file mode 100644 index 000000000..e6ce34cc3 --- /dev/null +++ b/.changeset/eighty-boats-bow.md @@ -0,0 +1,5 @@ +--- +'@react-pdf/layout': minor +--- + +Upgraded yoga to v2 and dropped bundled yoga v1 package diff --git a/.eslintrc.js b/.eslintrc.js index 409dc1a06..1e0c70eb3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -40,5 +40,6 @@ module.exports = { 'react/jsx-filename-extension': 0, 'react/jsx-props-no-spreading': 0, 'react/destructuring-assignment': 0, + 'import/no-unresolved': ['error', { ignore: ['^yoga-layout'] }], }, }; diff --git a/jest.config.js b/jest.config.js index 5439cc2d0..4d46d501c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,6 @@ module.exports = { projects: [ 'packages/fns', - 'packages/yoga', 'packages/font', 'packages/image', 'packages/render', diff --git a/packages/layout/package.json b/packages/layout/package.json index c4a2bfe84..b90839add 100644 --- a/packages/layout/package.json +++ b/packages/layout/package.json @@ -26,10 +26,10 @@ "@react-pdf/stylesheet": "^4.1.8", "@react-pdf/textkit": "^4.2.0", "@react-pdf/types": "^2.3.4", - "@react-pdf/yoga": "^4.1.2", "cross-fetch": "^3.1.5", "emoji-regex": "^10.2.1", - "queue": "^6.0.1" + "queue": "^6.0.1", + "yoga-layout": "^2.0.1" }, "devDependencies": { "jest-fetch-mock": "^2.1.1" diff --git a/packages/layout/src/image/measureImage.js b/packages/layout/src/image/measureImage.js index 4a6007d32..593a24f9b 100644 --- a/packages/layout/src/image/measureImage.js +++ b/packages/layout/src/image/measureImage.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import getRatio from './getRatio'; import getMargin from '../node/getMargin'; diff --git a/packages/layout/src/node/getBorderWidth.js b/packages/layout/src/node/getBorderWidth.js index 1901672d1..e2f82f131 100644 --- a/packages/layout/src/node/getBorderWidth.js +++ b/packages/layout/src/node/getBorderWidth.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; const getComputedBorder = (yogaNode, edge) => yogaNode ? yogaNode.getComputedBorder(edge) : 0; diff --git a/packages/layout/src/node/getMargin.js b/packages/layout/src/node/getMargin.js index 206bbe819..7bb0dd4f6 100644 --- a/packages/layout/src/node/getMargin.js +++ b/packages/layout/src/node/getMargin.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; const getComputedMargin = (node, edge) => { const { yogaNode } = node; diff --git a/packages/layout/src/node/getPadding.js b/packages/layout/src/node/getPadding.js index 9133ba9ba..c124b14e4 100644 --- a/packages/layout/src/node/getPadding.js +++ b/packages/layout/src/node/getPadding.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; const getComputedPadding = (node, edge) => { const { yogaNode } = node; diff --git a/packages/layout/src/node/setAlign.js b/packages/layout/src/node/setAlign.js index b4b3e6755..c5c3c1d05 100644 --- a/packages/layout/src/node/setAlign.js +++ b/packages/layout/src/node/setAlign.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import { upperFirst } from '@react-pdf/fns'; const ALIGN = { diff --git a/packages/layout/src/node/setBorderWidth.js b/packages/layout/src/node/setBorderWidth.js index ba69c3ccf..09c07ab81 100644 --- a/packages/layout/src/node/setBorderWidth.js +++ b/packages/layout/src/node/setBorderWidth.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setYogaValue from './setYogaValue'; diff --git a/packages/layout/src/node/setDisplay.js b/packages/layout/src/node/setDisplay.js index 6357d8c67..5bcc13eea 100644 --- a/packages/layout/src/node/setDisplay.js +++ b/packages/layout/src/node/setDisplay.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; /** * Set display attribute to node's Yoga instance diff --git a/packages/layout/src/node/setFlexDirection.js b/packages/layout/src/node/setFlexDirection.js index 6cb30d8b3..eb0f476ee 100644 --- a/packages/layout/src/node/setFlexDirection.js +++ b/packages/layout/src/node/setFlexDirection.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; const FLEX_DIRECTIONS = { row: Yoga.FLEX_DIRECTION_ROW, diff --git a/packages/layout/src/node/setFlexWrap.js b/packages/layout/src/node/setFlexWrap.js index 07ad03c5a..51ba30f48 100644 --- a/packages/layout/src/node/setFlexWrap.js +++ b/packages/layout/src/node/setFlexWrap.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; const FLEX_WRAP = { wrap: Yoga.WRAP_WRAP, diff --git a/packages/layout/src/node/setGap.js b/packages/layout/src/node/setGap.js index d40e17608..d7a8d56fe 100644 --- a/packages/layout/src/node/setGap.js +++ b/packages/layout/src/node/setGap.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import { isNil, matchPercent } from '@react-pdf/fns'; const checkPercents = (attr, value) => { diff --git a/packages/layout/src/node/setJustifyContent.js b/packages/layout/src/node/setJustifyContent.js index 2edcfae6d..0b3cd4265 100644 --- a/packages/layout/src/node/setJustifyContent.js +++ b/packages/layout/src/node/setJustifyContent.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import { isNil } from '@react-pdf/fns'; const JUSTIFY_CONTENT = { diff --git a/packages/layout/src/node/setMargin.js b/packages/layout/src/node/setMargin.js index 2750d0c65..9bad014a7 100644 --- a/packages/layout/src/node/setMargin.js +++ b/packages/layout/src/node/setMargin.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setYogaValue from './setYogaValue'; diff --git a/packages/layout/src/node/setOverflow.js b/packages/layout/src/node/setOverflow.js index d14ab4a10..3793234b5 100644 --- a/packages/layout/src/node/setOverflow.js +++ b/packages/layout/src/node/setOverflow.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import { isNil } from '@react-pdf/fns'; const OVERFLOW = { diff --git a/packages/layout/src/node/setPadding.js b/packages/layout/src/node/setPadding.js index 4858266b2..4a948950d 100644 --- a/packages/layout/src/node/setPadding.js +++ b/packages/layout/src/node/setPadding.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setYogaValue from './setYogaValue'; diff --git a/packages/layout/src/node/setPosition.js b/packages/layout/src/node/setPosition.js index c9640a392..82a9a8f6c 100644 --- a/packages/layout/src/node/setPosition.js +++ b/packages/layout/src/node/setPosition.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setYogaValue from './setYogaValue'; diff --git a/packages/layout/src/node/setPositionType.js b/packages/layout/src/node/setPositionType.js index 4c54ad15c..79573e9ae 100644 --- a/packages/layout/src/node/setPositionType.js +++ b/packages/layout/src/node/setPositionType.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import { isNil } from '@react-pdf/fns'; /** diff --git a/packages/layout/src/steps/resolveDimensions.js b/packages/layout/src/steps/resolveDimensions.js index 7d2102a4b..e4f21ba73 100644 --- a/packages/layout/src/steps/resolveDimensions.js +++ b/packages/layout/src/steps/resolveDimensions.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import * as P from '@react-pdf/primitives'; import { isNil, compose } from '@react-pdf/fns'; diff --git a/packages/layout/src/svg/measureSvg.js b/packages/layout/src/svg/measureSvg.js index 2fa397570..52e4a3ac8 100644 --- a/packages/layout/src/svg/measureSvg.js +++ b/packages/layout/src/svg/measureSvg.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; const getAspectRatio = viewbox => { if (!viewbox) return null; diff --git a/packages/layout/src/text/measureText.js b/packages/layout/src/text/measureText.js index a1efe3bec..ea3afe2d0 100644 --- a/packages/layout/src/text/measureText.js +++ b/packages/layout/src/text/measureText.js @@ -1,6 +1,6 @@ /* eslint-disable no-param-reassign */ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import layoutText from './layoutText'; import linesWidth from './linesWidth'; diff --git a/packages/layout/tests/node/getBorderWidth.test.js b/packages/layout/tests/node/getBorderWidth.test.js index cdeaa2185..5110f6ab7 100644 --- a/packages/layout/tests/node/getBorderWidth.test.js +++ b/packages/layout/tests/node/getBorderWidth.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import getBorderWidth from '../../src/node/getBorderWidth'; diff --git a/packages/layout/tests/node/getMargin.test.js b/packages/layout/tests/node/getMargin.test.js index fafa42dd7..b398e75c9 100644 --- a/packages/layout/tests/node/getMargin.test.js +++ b/packages/layout/tests/node/getMargin.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import getMargin from '../../src/node/getMargin'; diff --git a/packages/layout/tests/node/getPadding.test.js b/packages/layout/tests/node/getPadding.test.js index 96b84ae97..526314158 100644 --- a/packages/layout/tests/node/getPadding.test.js +++ b/packages/layout/tests/node/getPadding.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import getPadding from '../../src/node/getPadding'; diff --git a/packages/layout/tests/node/setAlignContent.test.js b/packages/layout/tests/node/setAlignContent.test.js index b8d23d761..dad2eb489 100644 --- a/packages/layout/tests/node/setAlignContent.test.js +++ b/packages/layout/tests/node/setAlignContent.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setAlignContent from '../../src/node/setAlignContent'; diff --git a/packages/layout/tests/node/setAlignItems.test.js b/packages/layout/tests/node/setAlignItems.test.js index 89d46f87b..ea1800535 100644 --- a/packages/layout/tests/node/setAlignItems.test.js +++ b/packages/layout/tests/node/setAlignItems.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setAlignItems from '../../src/node/setAlignItems'; diff --git a/packages/layout/tests/node/setAlignSelf.test.js b/packages/layout/tests/node/setAlignSelf.test.js index 4b54efff6..e84194693 100644 --- a/packages/layout/tests/node/setAlignSelf.test.js +++ b/packages/layout/tests/node/setAlignSelf.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setAlignSelf from '../../src/node/setAlignSelf'; diff --git a/packages/layout/tests/node/setBorderWidth.test.js b/packages/layout/tests/node/setBorderWidth.test.js index f5a10c066..0d09c2750 100644 --- a/packages/layout/tests/node/setBorderWidth.test.js +++ b/packages/layout/tests/node/setBorderWidth.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setBorder, { setBorderTop, diff --git a/packages/layout/tests/node/setDisplay.test.js b/packages/layout/tests/node/setDisplay.test.js index 9cd36fb24..15e64ec5e 100644 --- a/packages/layout/tests/node/setDisplay.test.js +++ b/packages/layout/tests/node/setDisplay.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setDisplay from '../../src/node/setDisplay'; diff --git a/packages/layout/tests/node/setFlexDirection.test.js b/packages/layout/tests/node/setFlexDirection.test.js index 54e5a453a..1d8d895c3 100644 --- a/packages/layout/tests/node/setFlexDirection.test.js +++ b/packages/layout/tests/node/setFlexDirection.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setFlexDirection from '../../src/node/setFlexDirection'; diff --git a/packages/layout/tests/node/setFlexWrap.test.js b/packages/layout/tests/node/setFlexWrap.test.js index 53013f4f4..f66e7f380 100644 --- a/packages/layout/tests/node/setFlexWrap.test.js +++ b/packages/layout/tests/node/setFlexWrap.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setFlexWrap from '../../src/node/setFlexWrap'; diff --git a/packages/layout/tests/node/setJustifyContent.test.js b/packages/layout/tests/node/setJustifyContent.test.js index f7bdaabe5..6ddd88aaf 100644 --- a/packages/layout/tests/node/setJustifyContent.test.js +++ b/packages/layout/tests/node/setJustifyContent.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setJustifyContent from '../../src/node/setJustifyContent'; diff --git a/packages/layout/tests/node/setMargin.test.js b/packages/layout/tests/node/setMargin.test.js index 9b8d69be7..f6aeeb0e0 100644 --- a/packages/layout/tests/node/setMargin.test.js +++ b/packages/layout/tests/node/setMargin.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setMargin, { setMarginTop, diff --git a/packages/layout/tests/node/setOverflow.test.js b/packages/layout/tests/node/setOverflow.test.js index 2cbb3ac7c..33f60b1c3 100644 --- a/packages/layout/tests/node/setOverflow.test.js +++ b/packages/layout/tests/node/setOverflow.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setOverflow from '../../src/node/setOverflow'; diff --git a/packages/layout/tests/node/setPadding.test.js b/packages/layout/tests/node/setPadding.test.js index 904820f0c..cce9fc8f2 100644 --- a/packages/layout/tests/node/setPadding.test.js +++ b/packages/layout/tests/node/setPadding.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setPadding, { setPaddingTop, diff --git a/packages/layout/tests/node/setPosition.test.js b/packages/layout/tests/node/setPosition.test.js index 3fb2998cc..3e1dc029b 100644 --- a/packages/layout/tests/node/setPosition.test.js +++ b/packages/layout/tests/node/setPosition.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setPosition, { setPositionTop, diff --git a/packages/layout/tests/node/setPositionType.test.js b/packages/layout/tests/node/setPositionType.test.js index a3fdd9d63..fb7e9fb3d 100644 --- a/packages/layout/tests/node/setPositionType.test.js +++ b/packages/layout/tests/node/setPositionType.test.js @@ -1,4 +1,4 @@ -import Yoga from '@react-pdf/yoga'; +import Yoga from 'yoga-layout/sync'; import setPositionType from '../../src/node/setPositionType'; diff --git a/packages/yoga/.gitignore b/packages/yoga/.gitignore deleted file mode 100644 index 1521c8b76..000000000 --- a/packages/yoga/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist diff --git a/packages/yoga/CHANGELOG.md b/packages/yoga/CHANGELOG.md deleted file mode 100644 index 868e07906..000000000 --- a/packages/yoga/CHANGELOG.md +++ /dev/null @@ -1,43 +0,0 @@ -# @react-pdf/yoga - -## 4.1.2 - -### Patch Changes - -- [#2224](https://github.com/diegomura/react-pdf/pull/2224) [`c5b21fc`](https://github.com/diegomura/react-pdf/commit/c5b21fc97b704b3616522b897847a9d3c9dc0052) Thanks [@jeetiss](https://github.com/jeetiss)! - update yoga - -## 4.1.1 - -### Patch Changes - -- [#2205](https://github.com/diegomura/react-pdf/pull/2205) [`9a5e0be`](https://github.com/diegomura/react-pdf/commit/9a5e0befb89756db07ce053192a136df9d4ba905) Thanks [@jeetiss](https://github.com/jeetiss)! - update babel - -## 4.1.0 - -### Minor Changes - -- [#2186](https://github.com/diegomura/react-pdf/pull/2186) [`72435bd`](https://github.com/diegomura/react-pdf/commit/72435bd81afdada5b811a1d82af0c873cfb62fa0) Thanks [@jeetiss](https://github.com/jeetiss)! - update yoga-layout to support flexBasis auto - -## 4.0.1 - -### Patch Changes - -- [#2168](https://github.com/diegomura/react-pdf/pull/2168) [`a45355a`](https://github.com/diegomura/react-pdf/commit/a45355afa4568fc01020e520af56eaa1e48dd85b) Thanks [@jeetiss](https://github.com/jeetiss)! - transpile modern js - -## 4.0.0 - -### Major Changes - -- [#2105](https://github.com/diegomura/react-pdf/pull/2105) [`a14ca9e`](https://github.com/diegomura/react-pdf/commit/a14ca9e62c9edc37f239558f8dbae29212b0da4d) Thanks [@jeetiss](https://github.com/jeetiss)! - migrate from yoga-layout-prebuilt to yoga-wasm-web - -## 3.0.0 - -### Major Changes - -- [#1891](https://github.com/diegomura/react-pdf/pull/1891) [`a5a933c`](https://github.com/diegomura/react-pdf/commit/a5a933c9733e4c77338ef76a2b3545b84a646a81) Thanks [@carlobeltrame](https://github.com/carlobeltrame)! - feat: compatibility with modern web bundlers and browsers - -## 2.0.4 - -### Patch Changes - -- [#1581](https://github.com/diegomura/react-pdf/pull/1581) [`04449ab`](https://github.com/diegomura/react-pdf/commit/04449ab352db0cca2155024dd3e8c690e42193ca) Thanks [@jeetiss](https://github.com/jeetiss)! - added changelog with changesets diff --git a/packages/yoga/README.md b/packages/yoga/README.md deleted file mode 100644 index 6b25ce45a..000000000 --- a/packages/yoga/README.md +++ /dev/null @@ -1,24 +0,0 @@ -

- -

- -# @react-pdf/yoga - -> Prebuilt [yoga-layout](https://github.com/facebook/yoga) - -## Acknowledges - -This package ship [yoga-wasm-web/asm](https://github.com/shuding/yoga-wasm-web) with commonjs entry - -## Install - -``` -$ npm install @react-pdf/yoga -``` - -## Usage - -```js -import Yoga from '@react-pdf/yoga'; -// Same as if imported from yoga-layout -``` diff --git a/packages/yoga/babel.config.js b/packages/yoga/babel.config.js deleted file mode 100644 index 27f83582f..000000000 --- a/packages/yoga/babel.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' }; diff --git a/packages/yoga/index.d.ts b/packages/yoga/index.d.ts deleted file mode 100644 index 1222e3562..000000000 --- a/packages/yoga/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Yoga } from 'yoga-wasm-web'; - -export default Yoga; diff --git a/packages/yoga/index.js b/packages/yoga/index.js deleted file mode 100644 index 6d7068936..000000000 --- a/packages/yoga/index.js +++ /dev/null @@ -1,4 +0,0 @@ -// eslint-disable-next-line import/no-unresolved -import initYoga from 'yoga-wasm-web/asm'; - -export default initYoga(); diff --git a/packages/yoga/package.json b/packages/yoga/package.json deleted file mode 100644 index 1c1ad25e5..000000000 --- a/packages/yoga/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@react-pdf/yoga", - "version": "4.1.2", - "description": "Prebuilt yoga-layout package", - "license": "MIT", - "author": "Diego Muracciole ", - "homepage": "https://github.com/diegomura/react-pdf#readme", - "main": "dist/index.js", - "module": "dist/index.esm.js", - "types": "index.d.ts", - "repository": { - "type": "git", - "url": "https://github.com/diegomura/react-pdf.git", - "directory": "packages/yoga" - }, - "scripts": { - "test": "jest", - "build": "rollup -c" - }, - "files": [ - "dist", - "index.d.ts" - ], - "dependencies": { - "@babel/runtime": "^7.20.13" - }, - "devDependencies": { - "yoga-wasm-web": "~0.3.2" - } -} diff --git a/packages/yoga/rollup.config.js b/packages/yoga/rollup.config.js deleted file mode 100644 index 12df6851b..000000000 --- a/packages/yoga/rollup.config.js +++ /dev/null @@ -1,25 +0,0 @@ -import commonjs from '@rollup/plugin-commonjs'; -import nodeResolve from '@rollup/plugin-node-resolve'; -import babel from '@rollup/plugin-babel'; - -const babelConfig = () => ({ - babelrc: true, - babelHelpers: 'runtime', -}); - -export default { - input: 'index.js', - output: [ - { - file: 'dist/index.js', - exports: 'auto', - format: 'cjs', - }, - { - file: 'dist/index.esm.js', - format: 'esm', - }, - ], - plugins: [commonjs(), nodeResolve(), babel(babelConfig())], - external: [/@babel\/runtime/], -}; diff --git a/packages/yoga/tests/absolutePosition.test.js b/packages/yoga/tests/absolutePosition.test.js deleted file mode 100644 index 37336aa0e..000000000 --- a/packages/yoga/tests/absolutePosition.test.js +++ /dev/null @@ -1,942 +0,0 @@ -const Yoga = require('..'); - -describe('Absloute position', () => { - test('absolute layout width height start to', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_START, 10); - child.setPosition(Yoga.EDGE_TOP, 10); - child.setWidth(10); - child.setHeight(10); - - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - }); - - test('absolute layout width height end bottom', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_END, 10); - child.setPosition(Yoga.EDGE_BOTTOM, 10); - child.setWidth(10); - child.setHeight(10); - - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(80); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(80); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - }); - - test('absolute layout start top end bottom', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_START, 10); - child.setPosition(Yoga.EDGE_TOP, 10); - child.setPosition(Yoga.EDGE_END, 10); - child.setPosition(Yoga.EDGE_BOTTOM, 10); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(80); - expect(child.getComputedLayout().height).toEqual(80); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(80); - expect(child.getComputedLayout().height).toEqual(80); - }); - - test('absolute layout width height start top end bottom', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_START, 10); - child.setPosition(Yoga.EDGE_TOP, 10); - child.setPosition(Yoga.EDGE_END, 10); - child.setPosition(Yoga.EDGE_BOTTOM, 10); - child.setWidth(10); - child.setHeight(10); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - }); - - test('do not clamp height of absolute node to height of its overflow hidden parent', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setOverflow(Yoga.OVERFLOW_HIDDEN); - root.setWidth(50); - root.setHeight(50); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_START, 0); - child.setPosition(Yoga.EDGE_TOP, 0); - root.insertChild(child, 0); - - const childChild = Yoga.Node.create(); - childChild.setWidth(100); - childChild.setHeight(100); - child.insertChild(childChild, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(50); - expect(root.getComputedLayout().height).toEqual(50); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(100); - expect(child.getComputedLayout().height).toEqual(100); - - expect(childChild.getComputedLayout().left).toEqual(0); - expect(childChild.getComputedLayout().top).toEqual(0); - expect(childChild.getComputedLayout().width).toEqual(100); - expect(childChild.getComputedLayout().height).toEqual(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(50); - expect(root.getComputedLayout().height).toEqual(50); - - expect(child.getComputedLayout().left).toEqual(-50); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(100); - expect(child.getComputedLayout().height).toEqual(100); - - expect(childChild.getComputedLayout().left).toEqual(0); - expect(childChild.getComputedLayout().top).toEqual(0); - expect(childChild.getComputedLayout().width).toEqual(100); - expect(childChild.getComputedLayout().height).toEqual(100); - }); - - test('absolute layout within border', () => { - const root = Yoga.Node.create(); - - root.setMargin(Yoga.EDGE_LEFT, 10); - root.setMargin(Yoga.EDGE_TOP, 10); - root.setMargin(Yoga.EDGE_RIGHT, 10); - root.setMargin(Yoga.EDGE_BOTTOM, 10); - root.setPadding(Yoga.EDGE_LEFT, 10); - root.setPadding(Yoga.EDGE_TOP, 10); - root.setPadding(Yoga.EDGE_RIGHT, 10); - root.setPadding(Yoga.EDGE_BOTTOM, 10); - root.setBorder(Yoga.EDGE_LEFT, 10); - root.setBorder(Yoga.EDGE_TOP, 10); - root.setBorder(Yoga.EDGE_RIGHT, 10); - root.setBorder(Yoga.EDGE_BOTTOM, 10); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_LEFT, 0); - child.setPosition(Yoga.EDGE_TOP, 0); - child.setWidth(50); - child.setHeight(50); - root.insertChild(child, 0); - - const child2 = Yoga.Node.create(); - child2.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child2.setPosition(Yoga.EDGE_RIGHT, 0); - child2.setPosition(Yoga.EDGE_BOTTOM, 0); - child2.setWidth(50); - child2.setHeight(50); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child3.setPosition(Yoga.EDGE_LEFT, 0); - child3.setPosition(Yoga.EDGE_TOP, 0); - child3.setMargin(Yoga.EDGE_LEFT, 10); - child3.setMargin(Yoga.EDGE_TOP, 10); - child3.setMargin(Yoga.EDGE_RIGHT, 10); - child3.setMargin(Yoga.EDGE_BOTTOM, 10); - child3.setWidth(50); - child3.setHeight(50); - root.insertChild(child3, 2); - - const child4 = Yoga.Node.create(); - child4.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child4.setPosition(Yoga.EDGE_RIGHT, 0); - child4.setPosition(Yoga.EDGE_BOTTOM, 0); - child4.setMargin(Yoga.EDGE_LEFT, 10); - child4.setMargin(Yoga.EDGE_TOP, 10); - child4.setMargin(Yoga.EDGE_RIGHT, 10); - child4.setMargin(Yoga.EDGE_BOTTOM, 10); - child4.setWidth(50); - child4.setHeight(50); - root.insertChild(child4, 3); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(10); - expect(root.getComputedLayout().top).toEqual(10); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(50); - expect(child.getComputedLayout().height).toEqual(50); - - expect(child2.getComputedLayout().left).toEqual(40); - expect(child2.getComputedLayout().top).toEqual(40); - expect(child2.getComputedLayout().width).toEqual(50); - expect(child2.getComputedLayout().height).toEqual(50); - - expect(child3.getComputedLayout().left).toEqual(20); - expect(child3.getComputedLayout().top).toEqual(20); - expect(child3.getComputedLayout().width).toEqual(50); - expect(child3.getComputedLayout().height).toEqual(50); - - expect(child4.getComputedLayout().left).toEqual(30); - expect(child4.getComputedLayout().top).toEqual(30); - expect(child4.getComputedLayout().width).toEqual(50); - expect(child4.getComputedLayout().height).toEqual(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(10); - expect(root.getComputedLayout().top).toEqual(10); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(10); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(50); - expect(child.getComputedLayout().height).toEqual(50); - - expect(child2.getComputedLayout().left).toEqual(40); - expect(child2.getComputedLayout().top).toEqual(40); - expect(child2.getComputedLayout().width).toEqual(50); - expect(child2.getComputedLayout().height).toEqual(50); - - expect(child3.getComputedLayout().left).toEqual(20); - expect(child3.getComputedLayout().top).toEqual(20); - expect(child3.getComputedLayout().width).toEqual(50); - expect(child3.getComputedLayout().height).toEqual(50); - - expect(child4.getComputedLayout().left).toEqual(30); - expect(child4.getComputedLayout().top).toEqual(30); - expect(child4.getComputedLayout().width).toEqual(50); - expect(child4.getComputedLayout().height).toEqual(50); - }); - - test('absolute layout align items and justify content center', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items and justify content flex end', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - root.setAlignItems(Yoga.ALIGN_FLEX_END); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(50); - expect(child.getComputedLayout().top).toEqual(60); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(60); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout justify content center', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(50); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items center', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items center on child only', () => { - const root = Yoga.Node.create(); - - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setAlignSelf(Yoga.ALIGN_CENTER); - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items and justify content center and top position', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_TOP, 10); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(10); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items and justify content center and bottom position', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_BOTTOM, 10); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(50); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(25); - expect(child.getComputedLayout().top).toEqual(50); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items and justify content center and left position', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_LEFT, 5); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(5); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(5); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('absolute layout align items and justify content center and right position', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexGrow(1); - root.setWidth(110); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPosition(Yoga.EDGE_RIGHT, 5); - child.setWidth(60); - child.setHeight(40); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(45); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(110); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(45); - expect(child.getComputedLayout().top).toEqual(30); - expect(child.getComputedLayout().width).toEqual(60); - expect(child.getComputedLayout().height).toEqual(40); - }); - - test('position root with rtl should position withoutdirection', () => { - const root = Yoga.Node.create(); - - root.setPosition(Yoga.EDGE_LEFT, 72); - root.setWidth(52); - root.setHeight(52); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(72); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(52); - expect(root.getComputedLayout().height).toEqual(52); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(72); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(52); - expect(root.getComputedLayout().height).toEqual(52); - }); - - test('absolute layout percentage bottom based on parent height', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(200); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setPositionPercent(Yoga.EDGE_TOP, 50); - child.setWidth(10); - child.setHeight(10); - root.insertChild(child, 0); - - const child2 = Yoga.Node.create(); - child2.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child2.setPositionPercent(Yoga.EDGE_BOTTOM, 50); - child2.setWidth(10); - child2.setHeight(10); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child3.setPositionPercent(Yoga.EDGE_TOP, 10); - child3.setPositionPercent(Yoga.EDGE_BOTTOM, 10); - child3.setWidth(10); - root.insertChild(child3, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(200); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(100); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - - expect(child2.getComputedLayout().left).toEqual(0); - expect(child2.getComputedLayout().top).toEqual(90); - expect(child2.getComputedLayout().width).toEqual(10); - expect(child2.getComputedLayout().height).toEqual(10); - - expect(child3.getComputedLayout().left).toEqual(0); - expect(child3.getComputedLayout().top).toEqual(20); - expect(child3.getComputedLayout().width).toEqual(10); - expect(child3.getComputedLayout().height).toEqual(160); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(200); - - expect(child.getComputedLayout().left).toEqual(90); - expect(child.getComputedLayout().top).toEqual(100); - expect(child.getComputedLayout().width).toEqual(10); - expect(child.getComputedLayout().height).toEqual(10); - - expect(child2.getComputedLayout().left).toEqual(90); - expect(child2.getComputedLayout().top).toEqual(90); - expect(child2.getComputedLayout().width).toEqual(10); - expect(child2.getComputedLayout().height).toEqual(10); - - expect(child3.getComputedLayout().left).toEqual(90); - expect(child3.getComputedLayout().top).toEqual(20); - expect(child3.getComputedLayout().width).toEqual(10); - expect(child3.getComputedLayout().height).toEqual(160); - }); - - test('absolute layout in wrap reverse column container', () => { - const root = Yoga.Node.create(); - - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(20); - child.setHeight(20); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - }); - - test('absolute layout in wrap reverse row container', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(20); - child.setHeight(20); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(80); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(80); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - }); - - test('absolute layout in wrap reverse column container flex end', () => { - const root = Yoga.Node.create(); - - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setAlignSelf(Yoga.ALIGN_FLEX_END); - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(20); - child.setHeight(20); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - }); - - test('absolute layout in wrap reverse row container flex end', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - - child.setAlignSelf(Yoga.ALIGN_FLEX_END); - child.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child.setWidth(20); - child.setHeight(20); - root.insertChild(child, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(0); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toEqual(0); - expect(root.getComputedLayout().top).toEqual(0); - expect(root.getComputedLayout().width).toEqual(100); - expect(root.getComputedLayout().height).toEqual(100); - - expect(child.getComputedLayout().left).toEqual(80); - expect(child.getComputedLayout().top).toEqual(0); - expect(child.getComputedLayout().width).toEqual(20); - expect(child.getComputedLayout().height).toEqual(20); - }); -}); diff --git a/packages/yoga/tests/alignContent.test.js b/packages/yoga/tests/alignContent.test.js deleted file mode 100644 index c1aee0d37..000000000 --- a/packages/yoga/tests/alignContent.test.js +++ /dev/null @@ -1,1770 +0,0 @@ -const Yoga = require('..'); - -describe('Align content', () => { - test('align content flex start', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(130); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(10); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(10); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(10); - root.insertChild(child4, 4); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(130); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(10); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(20); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.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(130); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(80); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(80); - expect(child2.getComputedLayout().top).toBe(10); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(30); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(80); - expect(child4.getComputedLayout().top).toBe(20); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(10); - }); - - test('align content flex start without height on children', () => { - const root = Yoga.Node.create(); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(10); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(10); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(20); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(0); - - 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(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(10); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(20); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(0); - }); - - test('align content flex start with flex', () => { - const root = Yoga.Node.create(); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(120); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexBasisPercent(0); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexBasisPercent(0); - child1.setWidth(50); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexShrink(1); - child3.setFlexBasisPercent(0); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - 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(120); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(40); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(40); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(40); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(80); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(120); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(0); - - 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(120); - - expect(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(40); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(40); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(40); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(80); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(120); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(0); - }); - - test('align content flex end', () => { - const root = Yoga.Node.create(); - root.setAlignContent(Yoga.ALIGN_FLEX_END); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(10); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(10); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(10); - root.insertChild(child4, 4); - 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(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(40); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(40); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(10); - }); - - test('align content stretch', () => { - const root = Yoga.Node.create(); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(0); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(100); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(0); - - expect(child4.getComputedLayout().left).toBe(100); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(0); - }); - - test('align content spacebetween', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_SPACE_BETWEEN); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(130); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(10); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(10); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(10); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(130); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(45); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(45); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(90); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.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(130); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(80); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(80); - expect(child2.getComputedLayout().top).toBe(45); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(30); - expect(child3.getComputedLayout().top).toBe(45); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(80); - expect(child4.getComputedLayout().top).toBe(90); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(10); - }); - - test('align content spacearound', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_SPACE_AROUND); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(140); - root.setHeight(120); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(10); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(10); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(10); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(140); - expect(root.getComputedLayout().height).toBe(120); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(15); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(15); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(55); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(55); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(95); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.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(140); - expect(root.getComputedLayout().height).toBe(120); - - expect(child0.getComputedLayout().left).toBe(90); - expect(child0.getComputedLayout().top).toBe(15); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(15); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(90); - expect(child2.getComputedLayout().top).toBe(55); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(10); - - expect(child3.getComputedLayout().left).toBe(40); - expect(child3.getComputedLayout().top).toBe(55); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(90); - expect(child4.getComputedLayout().top).toBe(95); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(10); - }); - - test('align content stretch row', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('align content stretch row with children', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child00 = Yoga.Node.create(); - child00.setFlexGrow(1); - child00.setFlexShrink(1); - child00.setFlexBasisPercent(0); - child0.insertChild(child00, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child00.getComputedLayout().left).toBe(0); - expect(child00.getComputedLayout().top).toBe(0); - expect(child00.getComputedLayout().width).toBe(50); - expect(child00.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child00.getComputedLayout().left).toBe(0); - expect(child00.getComputedLayout().top).toBe(0); - expect(child00.getComputedLayout().width).toBe(50); - expect(child00.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('align content stretch row with flex', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexShrink(1); - child1.setFlexBasisPercent(0); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexShrink(1); - child3.setFlexBasisPercent(0); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(100); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(100); - - expect(child4.getComputedLayout().left).toBe(100); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(100); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(100); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(100); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(100); - }); - - test('align content stretch row with flex no shrink', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexShrink(1); - child1.setFlexBasisPercent(0); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexBasisPercent(0); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(100); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(100); - - expect(child4.getComputedLayout().left).toBe(100); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(100); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(100); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(100); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(100); - }); - - test('align content stretch row with margin', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setMargin(Yoga.EDGE_LEFT, 10); - child1.setMargin(Yoga.EDGE_TOP, 10); - child1.setMargin(Yoga.EDGE_RIGHT, 10); - child1.setMargin(Yoga.EDGE_BOTTOM, 10); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setMargin(Yoga.EDGE_LEFT, 10); - child3.setMargin(Yoga.EDGE_TOP, 10); - child3.setMargin(Yoga.EDGE_RIGHT, 10); - child3.setMargin(Yoga.EDGE_BOTTOM, 10); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(40); - - expect(child1.getComputedLayout().left).toBe(60); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(40); - - expect(child3.getComputedLayout().left).toBe(60); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(80); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(40); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(40); - - expect(child3.getComputedLayout().left).toBe(40); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(100); - expect(child4.getComputedLayout().top).toBe(80); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - }); - - test('align content stretch row with padding', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setPadding(Yoga.EDGE_LEFT, 10); - child1.setPadding(Yoga.EDGE_TOP, 10); - child1.setPadding(Yoga.EDGE_RIGHT, 10); - child1.setPadding(Yoga.EDGE_BOTTOM, 10); - child1.setWidth(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setPadding(Yoga.EDGE_LEFT, 10); - child3.setPadding(Yoga.EDGE_TOP, 10); - child3.setPadding(Yoga.EDGE_RIGHT, 10); - child3.setPadding(Yoga.EDGE_BOTTOM, 10); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('align content stretch row with single row', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('align content stretch row with fixed height', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(60); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(80); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(80); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(80); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(80); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(80); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(80); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(80); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(80); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - }); - - test('align content stretch row with max height', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setMaxHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(50); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('align content stretch row with min height', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setMinHeight(80); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(90); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(90); - - expect(child2.getComputedLayout().left).toBe(100); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(90); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(90); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(90); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.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(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(90); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(90); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(90); - - expect(child3.getComputedLayout().left).toBe(100); - expect(child3.getComputedLayout().top).toBe(90); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(90); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(10); - }); - - test('align content stretch column', () => { - const root = Yoga.Node.create(); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(150); - - const child0 = Yoga.Node.create(); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child00 = Yoga.Node.create(); - child00.setFlexGrow(1); - child00.setFlexShrink(1); - child00.setFlexBasisPercent(0); - child0.insertChild(child00, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexShrink(1); - child1.setFlexBasisPercent(0); - child1.setHeight(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(50); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setHeight(50); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setHeight(50); - root.insertChild(child4, 4); - 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(150); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child00.getComputedLayout().left).toBe(0); - expect(child00.getComputedLayout().top).toBe(0); - expect(child00.getComputedLayout().width).toBe(50); - expect(child00.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(100); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - - 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(150); - - expect(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child00.getComputedLayout().left).toBe(0); - expect(child00.getComputedLayout().top).toBe(0); - expect(child00.getComputedLayout().width).toBe(50); - expect(child00.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(100); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(50); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('align content stretch is not overriding align items', () => { - const root = Yoga.Node.create(); - root.setAlignContent(Yoga.ALIGN_STRETCH); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setAlignContent(Yoga.ALIGN_STRETCH); - child0.setAlignItems(Yoga.ALIGN_CENTER); - child0.setWidth(100); - child0.setHeight(100); - root.insertChild(child0, 0); - - const child00 = Yoga.Node.create(); - child00.setAlignContent(Yoga.ALIGN_STRETCH); - child00.setWidth(10); - child00.setHeight(10); - child0.insertChild(child00, 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child00.getComputedLayout().left).toBe(0); - expect(child00.getComputedLayout().top).toBe(45); - expect(child00.getComputedLayout().width).toBe(10); - expect(child00.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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child00.getComputedLayout().left).toBe(90); - expect(child00.getComputedLayout().top).toBe(45); - expect(child00.getComputedLayout().width).toBe(10); - expect(child00.getComputedLayout().height).toBe(10); - }); -}); diff --git a/packages/yoga/tests/alignItems.test.js b/packages/yoga/tests/alignItems.test.js deleted file mode 100644 index a0f224611..000000000 --- a/packages/yoga/tests/alignItems.test.js +++ /dev/null @@ -1,2010 +0,0 @@ -const Yoga = require('..'); - -describe('Align items', () => { - test('align items stretch', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - }); - - test('align items center', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - child1.setHeight(10); - root.insertChild(child1, 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(child1.getComputedLayout().left).toBe(45); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.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(child1.getComputedLayout().left).toBe(45); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(10); - }); - - test('align items flex start', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - child1.setHeight(10); - root.insertChild(child1, 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.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(child1.getComputedLayout().left).toBe(90); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(10); - }); - - test('align items flex end', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_END); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - child1.setHeight(10); - root.insertChild(child1, 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(child1.getComputedLayout().left).toBe(90); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(10); - }); - - test('align baseline', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(20); - root.insertChild(child2, 1); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(30); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(30); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - }); - - test('align baseline child', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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); - }); - - test('align baseline child multiline', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(60); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child2.setFlexWrap(Yoga.WRAP_WRAP); - child2.setWidth(50); - child2.setHeight(25); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setWidth(25); - child3.setHeight(20); - child2.insertChild(child3, 0); - - const child4 = Yoga.Node.create(); - child4.setWidth(25); - child4.setHeight(10); - child2.insertChild(child4, 1); - - const child5 = Yoga.Node.create(); - child5.setWidth(25); - child5.setHeight(20); - child2.insertChild(child5, 2); - - const child6 = Yoga.Node.create(); - child6.setWidth(25); - child6.setHeight(10); - child2.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(25); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(25); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(25); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(25); - expect(child4.getComputedLayout().height).toBe(10); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(20); - expect(child5.getComputedLayout().width).toBe(25); - expect(child5.getComputedLayout().height).toBe(20); - - expect(child6.getComputedLayout().left).toBe(25); - expect(child6.getComputedLayout().top).toBe(20); - expect(child6.getComputedLayout().width).toBe(25); - expect(child6.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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(25); - - expect(child3.getComputedLayout().left).toBe(25); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(25); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(25); - expect(child4.getComputedLayout().height).toBe(10); - - expect(child5.getComputedLayout().left).toBe(25); - expect(child5.getComputedLayout().top).toBe(20); - expect(child5.getComputedLayout().width).toBe(25); - expect(child5.getComputedLayout().height).toBe(20); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(20); - expect(child6.getComputedLayout().width).toBe(25); - expect(child6.getComputedLayout().height).toBe(10); - }); - - test('align baseline child multiline override', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(60); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child2.setFlexWrap(Yoga.WRAP_WRAP); - child2.setWidth(50); - child2.setHeight(25); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setWidth(25); - child3.setHeight(20); - child2.insertChild(child3, 0); - - const child4 = Yoga.Node.create(); - child4.setAlignSelf(Yoga.ALIGN_BASELINE); - child4.setWidth(25); - child4.setHeight(10); - child2.insertChild(child4, 1); - - const child5 = Yoga.Node.create(); - child5.setWidth(25); - child5.setHeight(20); - child2.insertChild(child5, 2); - - const child6 = Yoga.Node.create(); - child6.setAlignSelf(Yoga.ALIGN_BASELINE); - child6.setWidth(25); - child6.setHeight(10); - child2.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(25); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(25); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(25); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(25); - expect(child4.getComputedLayout().height).toBe(10); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(20); - expect(child5.getComputedLayout().width).toBe(25); - expect(child5.getComputedLayout().height).toBe(20); - - expect(child6.getComputedLayout().left).toBe(25); - expect(child6.getComputedLayout().top).toBe(20); - expect(child6.getComputedLayout().width).toBe(25); - expect(child6.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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(25); - - expect(child3.getComputedLayout().left).toBe(25); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(25); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(25); - expect(child4.getComputedLayout().height).toBe(10); - - expect(child5.getComputedLayout().left).toBe(25); - expect(child5.getComputedLayout().top).toBe(20); - expect(child5.getComputedLayout().width).toBe(25); - expect(child5.getComputedLayout().height).toBe(20); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(20); - expect(child6.getComputedLayout().width).toBe(25); - expect(child6.getComputedLayout().height).toBe(10); - }); - - test('align baseline child multiline no override on secondline', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(60); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child2.setFlexWrap(Yoga.WRAP_WRAP); - child2.setWidth(50); - child2.setHeight(25); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setWidth(25); - child3.setHeight(20); - child2.insertChild(child3, 0); - - const child4 = Yoga.Node.create(); - child4.setWidth(25); - child4.setHeight(10); - child2.insertChild(child4, 1); - - const child5 = Yoga.Node.create(); - child5.setWidth(25); - child5.setHeight(20); - child2.insertChild(child5, 2); - - const child6 = Yoga.Node.create(); - child6.setAlignSelf(Yoga.ALIGN_BASELINE); - child6.setWidth(25); - child6.setHeight(10); - child2.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(25); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(25); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(25); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(25); - expect(child4.getComputedLayout().height).toBe(10); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(20); - expect(child5.getComputedLayout().width).toBe(25); - expect(child5.getComputedLayout().height).toBe(20); - - expect(child6.getComputedLayout().left).toBe(25); - expect(child6.getComputedLayout().top).toBe(20); - expect(child6.getComputedLayout().width).toBe(25); - expect(child6.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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(60); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(25); - - expect(child3.getComputedLayout().left).toBe(25); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(25); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(25); - expect(child4.getComputedLayout().height).toBe(10); - - expect(child5.getComputedLayout().left).toBe(25); - expect(child5.getComputedLayout().top).toBe(20); - expect(child5.getComputedLayout().width).toBe(25); - expect(child5.getComputedLayout().height).toBe(20); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(20); - expect(child6.getComputedLayout().width).toBe(25); - expect(child6.getComputedLayout().height).toBe(10); - }); - - test('align baseline child top', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setPosition(Yoga.EDGE_TOP, 10); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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); - }); - - test('align baseline child top2', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setPosition(Yoga.EDGE_TOP, 5); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(45); - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(45); - 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); - }); - - test('align baseline double nested child', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(20); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(20); - root.insertChild(child3, 1); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(15); - child3.insertChild(child4, 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(5); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(15); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(5); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(15); - }); - - test('align baseline column', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(20); - root.insertChild(child2, 1); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(50); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - }); - - test('align_baseline_child_margin', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setMargin(Yoga.EDGE_LEFT, 5); - child1.setMargin(Yoga.EDGE_TOP, 5); - child1.setMargin(Yoga.EDGE_RIGHT, 5); - child1.setMargin(Yoga.EDGE_BOTTOM, 5); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(20); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setMargin(Yoga.EDGE_LEFT, 1); - child3.setMargin(Yoga.EDGE_TOP, 1); - child3.setMargin(Yoga.EDGE_RIGHT, 1); - child3.setMargin(Yoga.EDGE_BOTTOM, 1); - 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(child1.getComputedLayout().left).toBe(5); - expect(child1.getComputedLayout().top).toBe(5); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(44); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(1); - expect(child3.getComputedLayout().top).toBe(1); - 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(child1.getComputedLayout().left).toBe(45); - expect(child1.getComputedLayout().top).toBe(5); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(-10); - expect(child2.getComputedLayout().top).toBe(44); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(-1); - expect(child3.getComputedLayout().top).toBe(1); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - }); - - test('align baseline child padding', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setPadding(Yoga.EDGE_LEFT, 5); - root.setPadding(Yoga.EDGE_TOP, 5); - root.setPadding(Yoga.EDGE_RIGHT, 5); - root.setPadding(Yoga.EDGE_BOTTOM, 5); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setPadding(Yoga.EDGE_LEFT, 5); - child2.setPadding(Yoga.EDGE_TOP, 5); - child2.setPadding(Yoga.EDGE_RIGHT, 5); - child2.setPadding(Yoga.EDGE_BOTTOM, 5); - 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(child1.getComputedLayout().left).toBe(5); - expect(child1.getComputedLayout().top).toBe(5); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(55); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(5); - expect(child3.getComputedLayout().top).toBe(5); - 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(child1.getComputedLayout().left).toBe(45); - expect(child1.getComputedLayout().top).toBe(5); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(-5); - expect(child2.getComputedLayout().top).toBe(40); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(-5); - expect(child3.getComputedLayout().top).toBe(5); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - }); - - test('align baseline multiline', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - 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); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(20); - root.insertChild(child4, 2); - - const child5 = Yoga.Node.create(); - child5.setWidth(50); - child5.setHeight(10); - child4.insertChild(child5, 0); - - const child6 = Yoga.Node.create(); - child6.setWidth(50); - child6.setHeight(50); - root.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(100); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(50); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(50); - expect(child6.getComputedLayout().top).toBe(60); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(50); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(100); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(50); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(60); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(50); - }); - - test('align baseline multiline column', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(50); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setWidth(20); - child3.setHeight(20); - child2.insertChild(child3, 0); - - const child4 = Yoga.Node.create(); - child4.setWidth(40); - child4.setHeight(70); - root.insertChild(child4, 2); - - const child5 = Yoga.Node.create(); - child5.setWidth(10); - child5.setHeight(10); - child4.insertChild(child5, 0); - - const child6 = Yoga.Node.create(); - child6.setWidth(50); - child6.setHeight(20); - root.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(70); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(10); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(50); - expect(child6.getComputedLayout().top).toBe(70); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(20); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(70); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(10); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(10); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(70); - - expect(child5.getComputedLayout().left).toBe(30); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(10); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(70); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(20); - }); - - test('align baseline multiline column2', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(50); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setWidth(20); - child3.setHeight(20); - child2.insertChild(child3, 0); - - const child4 = Yoga.Node.create(); - child4.setWidth(40); - child4.setHeight(70); - root.insertChild(child4, 2); - - const child5 = Yoga.Node.create(); - child5.setWidth(10); - child5.setHeight(10); - child4.insertChild(child5, 0); - - const child6 = Yoga.Node.create(); - child6.setWidth(50); - child6.setHeight(20); - root.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(70); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(10); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(50); - expect(child6.getComputedLayout().top).toBe(70); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(20); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(70); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(50); - - expect(child3.getComputedLayout().left).toBe(10); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - - expect(child4.getComputedLayout().left).toBe(10); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(70); - - expect(child5.getComputedLayout().left).toBe(30); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(10); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(70); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(20); - }); - - test('align baseline multiline row and column', () => { - const root = Yoga.Node.create(); - - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_BASELINE); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(50); - root.insertChild(child2, 1); - - const child3 = Yoga.Node.create(); - child3.setWidth(50); - child3.setHeight(10); - child2.insertChild(child3, 0); - - const child4 = Yoga.Node.create(); - child4.setWidth(50); - child4.setHeight(20); - root.insertChild(child4, 2); - - const child5 = Yoga.Node.create(); - child5.setWidth(50); - child5.setHeight(10); - child4.insertChild(child5, 0); - - const child6 = Yoga.Node.create(); - child6.setWidth(50); - child6.setHeight(20); - root.insertChild(child6, 3); - 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(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(100); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(50); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(50); - expect(child6.getComputedLayout().top).toBe(90); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(20); - - 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(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.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(50); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(10); - - expect(child4.getComputedLayout().left).toBe(50); - expect(child4.getComputedLayout().top).toBe(100); - expect(child4.getComputedLayout().width).toBe(50); - expect(child4.getComputedLayout().height).toBe(20); - - expect(child5.getComputedLayout().left).toBe(0); - expect(child5.getComputedLayout().top).toBe(0); - expect(child5.getComputedLayout().width).toBe(50); - expect(child5.getComputedLayout().height).toBe(10); - - expect(child6.getComputedLayout().left).toBe(0); - expect(child6.getComputedLayout().top).toBe(90); - expect(child6.getComputedLayout().width).toBe(50); - expect(child6.getComputedLayout().height).toBe(20); - }); - - test('align items center child with margin bigger than parent', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child1 = Yoga.Node.create(); - child1.setAlignItems(Yoga.ALIGN_CENTER); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setMargin(Yoga.EDGE_LEFT, 10); - child2.setMargin(Yoga.EDGE_RIGHT, 10); - child2.setWidth(52); - child2.setHeight(52); - child1.insertChild(child2, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(52); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(52); - expect(child2.getComputedLayout().height).toBe(52); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(52); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(52); - expect(child2.getComputedLayout().height).toBe(52); - }); - - test('align items flex end child with margin bigger than parent', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child1 = Yoga.Node.create(); - child1.setAlignItems(Yoga.ALIGN_FLEX_END); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setMargin(Yoga.EDGE_LEFT, 10); - child2.setMargin(Yoga.EDGE_RIGHT, 10); - child2.setWidth(52); - child2.setHeight(52); - child1.insertChild(child2, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(52); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(52); - expect(child2.getComputedLayout().height).toBe(52); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(52); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(52); - expect(child2.getComputedLayout().height).toBe(52); - }); - - test('align items center child without margin bigger than parent', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child1 = Yoga.Node.create(); - child1.setAlignItems(Yoga.ALIGN_CENTER); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(72); - child2.setHeight(72); - child1.insertChild(child2, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(-10); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(72); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(72); - expect(child2.getComputedLayout().height).toBe(72); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(-10); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(72); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(72); - expect(child2.getComputedLayout().height).toBe(72); - }); - - test('align items flex end child without margin bigger than parent', () => { - const root = Yoga.Node.create(); - - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child1 = Yoga.Node.create(); - child1.setAlignItems(Yoga.ALIGN_FLEX_END); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(72); - child2.setHeight(72); - child1.insertChild(child2, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(-10); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(72); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(72); - expect(child2.getComputedLayout().height).toBe(72); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child1.getComputedLayout().left).toBe(-10); - expect(child1.getComputedLayout().top).toBe(-10); - expect(child1.getComputedLayout().width).toBe(72); - expect(child1.getComputedLayout().height).toBe(72); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(72); - expect(child2.getComputedLayout().height).toBe(72); - }); - - test('align center should size based on content', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setMargin(Yoga.EDGE_TOP, 20); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setJustifyContent(Yoga.JUSTIFY_CENTER); - child1.setFlexShrink(1); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setFlexShrink(1); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setWidth(20); - child3.setHeight(20); - child2.insertChild(child3, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(20); - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(20); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(20); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(20); - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(20); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(20); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - }); - - test('align strech should size based on parent', () => { - const root = Yoga.Node.create(); - - root.setMargin(Yoga.EDGE_TOP, 20); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setJustifyContent(Yoga.JUSTIFY_CENTER); - child1.setFlexShrink(1); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setFlexShrink(1); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setWidth(20); - child3.setHeight(20); - child2.insertChild(child3, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(20); - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(20); - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(20); - - expect(child3.getComputedLayout().left).toBe(80); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(20); - expect(child3.getComputedLayout().height).toBe(20); - }); - - test('align flex start with shrinking children', () => { - const root = Yoga.Node.create(); - - root.setWidth(500); - root.setHeight(500); - - const child1 = Yoga.Node.create(); - child1.setAlignItems(Yoga.ALIGN_FLEX_START); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setFlexShrink(1); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexShrink(1); - 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(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(500); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(500); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(500); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(0); - }); - - test('align flex start with stretching children', () => { - const root = Yoga.Node.create(); - - root.setWidth(500); - root.setHeight(500); - - const child1 = Yoga.Node.create(); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setFlexShrink(1); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexShrink(1); - 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(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(500); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(500); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(500); - expect(child3.getComputedLayout().height).toBe(0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(500); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(500); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(500); - expect(child3.getComputedLayout().height).toBe(0); - }); - - test('align flex start with shrinking children with stretch', () => { - const root = Yoga.Node.create(); - - root.setWidth(500); - root.setHeight(500); - - const child1 = Yoga.Node.create(); - child1.setAlignItems(Yoga.ALIGN_FLEX_START); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setFlexShrink(1); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexShrink(1); - 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(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(500); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(500); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(500); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(0); - expect(child3.getComputedLayout().height).toBe(0); - }); -}); diff --git a/packages/yoga/tests/alignSelf.test.js b/packages/yoga/tests/alignSelf.test.js deleted file mode 100644 index 3fe551647..000000000 --- a/packages/yoga/tests/alignSelf.test.js +++ /dev/null @@ -1,216 +0,0 @@ -const Yoga = require('..'); - -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); - }); -}); diff --git a/packages/yoga/tests/aspectRatio.test.js b/packages/yoga/tests/aspectRatio.test.js deleted file mode 100644 index 7c258a61e..000000000 --- a/packages/yoga/tests/aspectRatio.test.js +++ /dev/null @@ -1,731 +0,0 @@ -const Yoga = require('..'); - -describe('Aspect ratio', () => { - const measure = (node, width, widthMode, height, heightMode) => { - return { - width: widthMode === Yoga.MEASURE_MODE_EXACTLY ? width : 50, - height: heightMode === Yoga.MEASURE_MODE_EXACTLY ? height : 50, - }; - }; - - test('aspect_ratio_cross_defined', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setAspectRatio(1); - - root.insertChild(child1, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_main_defined', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_both_dimensions_defined_row', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(100); - child1.setHeight(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_both_dimensions_defined_column', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(100); - child1.setHeight(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_align_stretch', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_flex_grow', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setFlexGrow(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_flex_shrink', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(150); - child1.setFlexShrink(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_flex_shrink_2', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeightPercent(100); - child1.setFlexShrink(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setHeightPercent(100); - child2.setFlexShrink(1); - child2.setAspectRatio(1); - root.insertChild(child2, 1); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_basis', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setFlexBasis(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_absolute_layout_width_defined', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child1.setPosition(Yoga.EDGE_LEFT, 0); - child1.setPosition(Yoga.EDGE_TOP, 0); - child1.setWidth(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_absolute_layout_height_defined', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child1.setPosition(Yoga.EDGE_LEFT, 0); - child1.setPosition(Yoga.EDGE_TOP, 0); - child1.setHeight(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_with_max_cross_defined', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setMaxWidth(40); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_with_max_main_defined', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setMaxHeight(40); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(40); - }); - - test('aspect_ratio_with_min_cross_defined', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(30); - child1.setMinWidth(40); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(30); - }); - - test('aspect_ratio_with_min_main_defined', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setMinHeight(40); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(40); - }); - - test('aspect_ratio_double_cross', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setAspectRatio(2); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_half_cross', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(100); - child1.setAspectRatio(0.5); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_double_main', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setAspectRatio(0.5); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_half_main', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(100); - child1.setAspectRatio(2); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_with_measure_func', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setMeasureFunc(measure); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_width_height_flex_grow_row', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(200); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - child1.setFlexGrow(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(200); - }); - - test('aspect_ratio_width_height_flex_grow_column', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(200); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - child1.setFlexGrow(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_height_as_flex_basis', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(200); - root.setHeight(200); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setFlexGrow(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setHeight(100); - child2.setFlexGrow(1); - child2.setAspectRatio(1); - root.insertChild(child2, 1); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(75); - expect(child1.getComputedLayout().height).toBe(75); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(75); - expect(child2.getComputedLayout().width).toBe(125); - expect(child2.getComputedLayout().height).toBe(125); - }); - - test('aspect_ratio_width_as_flex_basis', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(200); - root.setHeight(200); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setFlexGrow(1); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(100); - child2.setFlexGrow(1); - child2.setAspectRatio(1); - root.insertChild(child2, 1); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(75); - expect(child1.getComputedLayout().height).toBe(75); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(75); - expect(child2.getComputedLayout().width).toBe(125); - expect(child2.getComputedLayout().height).toBe(125); - }); - - test('aspect_ratio_overrides_flex_grow_row', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setFlexGrow(1); - child1.setAspectRatio(0.5); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_overrides_flex_grow_column', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setFlexGrow(1); - child1.setAspectRatio(2); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('aspect_ratio_left_right_absolute', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child1.setPosition(Yoga.EDGE_LEFT, 10); - child1.setPosition(Yoga.EDGE_TOP, 10); - child1.setPosition(Yoga.EDGE_RIGHT, 10); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(80); - expect(child1.getComputedLayout().height).toBe(80); - }); - - test('aspect_ratio_top_bottom_absolute', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child1.setPosition(Yoga.EDGE_LEFT, 10); - child1.setPosition(Yoga.EDGE_TOP, 10); - child1.setPosition(Yoga.EDGE_BOTTOM, 10); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(80); - expect(child1.getComputedLayout().height).toBe(80); - }); - - test('aspect_ratio_width_overrides_align_stretch_row', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_height_overrides_align_stretch_column', () => { - const root = Yoga.Node.create(); - - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setAspectRatio(1); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_allow_child_overflow_parent_size', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setAspectRatio(4); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_defined_main_with_margin', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setHeight(50); - child1.setAspectRatio(1); - child1.setMargin(Yoga.EDGE_LEFT, 10); - child1.setMargin(Yoga.EDGE_RIGHT, 10); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('aspect_ratio_defined_cross_with_margin', () => { - const root = Yoga.Node.create(); - - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(100); - root.setHeight(100); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setAspectRatio(1); - child1.setMargin(Yoga.EDGE_LEFT, 10); - child1.setMargin(Yoga.EDGE_RIGHT, 10); - root.insertChild(child1, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().width).toBe(100); - expect(root.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); -}); diff --git a/packages/yoga/tests/border.test.js b/packages/yoga/tests/border.test.js deleted file mode 100644 index 675fa68c6..000000000 --- a/packages/yoga/tests/border.test.js +++ /dev/null @@ -1,317 +0,0 @@ -const Yoga = require('..'); - -describe('Borders', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - }); - - test('should have same top border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_TOP), - ); - }); - - test('should have same left border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_LEFT), - ); - }); - - test('should have same bottom border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_BOTTOM), - ); - }); - - test('should have same right border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_RIGHT), - ); - }); - - test('should have same vertical border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_VERTICAL), - ); - }); - - test('should have same horizontal border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should have same start border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_START)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_START), - ); - }); - - test('should have same end border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_END)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_END), - ); - }); - - test('should have same all border by default', () => { - expect(yogaNode.getBorder(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_ALL), - ); - }); - - test('should set top border', () => { - yogaNode.setBorder(Yoga.EDGE_TOP, 5); - flexboxNode.setBorder(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_TOP), - ); - }); - - test('should set left border', () => { - yogaNode.setBorder(Yoga.EDGE_LEFT, 5); - flexboxNode.setBorder(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom border', () => { - yogaNode.setBorder(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setBorder(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right border', () => { - yogaNode.setBorder(Yoga.EDGE_RIGHT, 5); - flexboxNode.setBorder(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical border', () => { - yogaNode.setBorder(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setBorder(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal border', () => { - yogaNode.setBorder(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setBorder(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start border', () => { - yogaNode.setBorder(Yoga.EDGE_START, 5); - flexboxNode.setBorder(Yoga.EDGE_START, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_START)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_START), - ); - }); - - test('should set end border', () => { - yogaNode.setBorder(Yoga.EDGE_END, 5); - flexboxNode.setBorder(Yoga.EDGE_END, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_END)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_END), - ); - }); - - test('should set all border', () => { - yogaNode.setBorder(Yoga.EDGE_ALL, 5); - flexboxNode.setBorder(Yoga.EDGE_ALL, 5); - - expect(yogaNode.getBorder(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getBorder(Yoga.EDGE_ALL), - ); - }); - - test('border_no_size', () => { - const root = Yoga.Node.create(); - root.setBorder(Yoga.EDGE_LEFT, 10); - root.setBorder(Yoga.EDGE_TOP, 10); - root.setBorder(Yoga.EDGE_RIGHT, 10); - root.setBorder(Yoga.EDGE_BOTTOM, 10); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(20); - }); - - test('border_container_match_child', () => { - const root = Yoga.Node.create(); - root.setBorder(Yoga.EDGE_LEFT, 10); - root.setBorder(Yoga.EDGE_TOP, 10); - root.setBorder(Yoga.EDGE_RIGHT, 10); - root.setBorder(Yoga.EDGE_BOTTOM, 10); - - const child = Yoga.Node.create(); - 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(30); - expect(root.getComputedLayout().height).toBe(30); - - expect(child.getComputedLayout().left).toBe(10); - expect(child.getComputedLayout().top).toBe(10); - 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(30); - expect(root.getComputedLayout().height).toBe(30); - - expect(child.getComputedLayout().left).toBe(10); - expect(child.getComputedLayout().top).toBe(10); - expect(child.getComputedLayout().width).toBe(10); - expect(child.getComputedLayout().height).toBe(10); - }); - - test('border_flex_child', () => { - const root = Yoga.Node.create(); - root.setBorder(Yoga.EDGE_LEFT, 10); - root.setBorder(Yoga.EDGE_TOP, 10); - root.setBorder(Yoga.EDGE_RIGHT, 10); - root.setBorder(Yoga.EDGE_BOTTOM, 10); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - child.setFlexGrow(1); - child.setWidth(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(10); - expect(child.getComputedLayout().top).toBe(10); - expect(child.getComputedLayout().width).toBe(10); - expect(child.getComputedLayout().height).toBe(80); - - 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(80); - expect(child.getComputedLayout().top).toBe(10); - expect(child.getComputedLayout().width).toBe(10); - expect(child.getComputedLayout().height).toBe(80); - }); - - test('border_stretch_child', () => { - const root = Yoga.Node.create(); - root.setBorder(Yoga.EDGE_LEFT, 10); - root.setBorder(Yoga.EDGE_TOP, 10); - root.setBorder(Yoga.EDGE_RIGHT, 10); - root.setBorder(Yoga.EDGE_BOTTOM, 10); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - 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(10); - expect(child.getComputedLayout().top).toBe(10); - expect(child.getComputedLayout().width).toBe(80); - 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(10); - expect(child.getComputedLayout().top).toBe(10); - expect(child.getComputedLayout().width).toBe(80); - expect(child.getComputedLayout().height).toBe(10); - }); - - test('border_center_child', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setBorder(Yoga.EDGE_START, 10); - root.setBorder(Yoga.EDGE_END, 20); - root.setBorder(Yoga.EDGE_BOTTOM, 20); - root.setWidth(100); - root.setHeight(100); - - const child = Yoga.Node.create(); - 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(40); - expect(child.getComputedLayout().top).toBe(35); - 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(50); - expect(child.getComputedLayout().top).toBe(35); - expect(child.getComputedLayout().width).toBe(10); - expect(child.getComputedLayout().height).toBe(10); - }); -}); diff --git a/packages/yoga/tests/computedMargin.test.js b/packages/yoga/tests/computedMargin.test.js deleted file mode 100644 index cc5f20e5e..000000000 --- a/packages/yoga/tests/computedMargin.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const Yoga = require('..'); - -describe('Computed margin', () => { - test('computed layout margin', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - root.setMarginPercent(Yoga.EDGE_START, 10); - - root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); - - expect(root.getComputedMargin(Yoga.EDGE_LEFT)).toBe(10); - expect(root.getComputedMargin(Yoga.EDGE_RIGHT)).toBe(0); - - root.calculateLayout(100, 100, Yoga.DIRECTION_RTL); - - expect(root.getComputedMargin(Yoga.EDGE_LEFT)).toBe(0); - expect(root.getComputedMargin(Yoga.EDGE_RIGHT)).toBe(10); - }); -}); diff --git a/packages/yoga/tests/computedPadding.test.js b/packages/yoga/tests/computedPadding.test.js deleted file mode 100644 index 04ae353ab..000000000 --- a/packages/yoga/tests/computedPadding.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const Yoga = require('..'); - -describe('Computed padding', () => { - test('computed layout padding', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - root.setPaddingPercent(Yoga.EDGE_START, 10); - - root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); - - expect(root.getComputedPadding(Yoga.EDGE_LEFT)).toBe(10); - expect(root.getComputedPadding(Yoga.EDGE_RIGHT)).toBe(0); - - root.calculateLayout(100, 100, Yoga.DIRECTION_RTL); - - expect(root.getComputedPadding(Yoga.EDGE_LEFT)).toBe(0); - expect(root.getComputedPadding(Yoga.EDGE_RIGHT)).toBe(10); - }); -}); diff --git a/packages/yoga/tests/defaultValues.test.js b/packages/yoga/tests/defaultValues.test.js deleted file mode 100644 index 64fc39b3b..000000000 --- a/packages/yoga/tests/defaultValues.test.js +++ /dev/null @@ -1,106 +0,0 @@ -const Yoga = require('..'); - -describe('Default values', () => { - test('assert default values', () => { - const root = Yoga.Node.create(); - - expect(root.getChildCount()).toBe(0); - expect(root.getChild(1)).toBe(null); - - expect(root.getFlexDirection()).toBe(Yoga.FLEX_DIRECTION_COLUMN); - expect(root.getJustifyContent()).toBe(Yoga.JUSTIFY_FLEX_START); - expect(root.getAlignContent()).toBe(Yoga.ALIGN_FLEX_START); - expect(root.getAlignItems()).toBe(Yoga.ALIGN_STRETCH); - expect(root.getAlignSelf()).toBe(Yoga.ALIGN_AUTO); - expect(root.getPositionType()).toBe(Yoga.POSITION_TYPE_STATIC); - expect(root.getFlexWrap()).toBe(Yoga.WRAP_NO_WRAP); - expect(root.getOverflow()).toBe(Yoga.OVERFLOW_VISIBLE); - expect(root.getFlexGrow()).toBe(0); - expect(root.getFlexShrink()).toBe(0); - expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_AUTO); - - expect(root.getPosition(Yoga.EDGE_LEFT).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPosition(Yoga.EDGE_TOP).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPosition(Yoga.EDGE_RIGHT).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPosition(Yoga.EDGE_BOTTOM).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPosition(Yoga.EDGE_START).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPosition(Yoga.EDGE_END).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - - expect(root.getMargin(Yoga.EDGE_LEFT).unit).toBe(Yoga.UNIT_UNDEFINED); - expect(root.getMargin(Yoga.EDGE_TOP).unit).toBe(Yoga.UNIT_UNDEFINED); - expect(root.getMargin(Yoga.EDGE_RIGHT).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getMargin(Yoga.EDGE_BOTTOM).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getMargin(Yoga.EDGE_START).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getMargin(Yoga.EDGE_END).unit).toBe(Yoga.UNIT_UNDEFINED); - - expect(root.getPadding(Yoga.EDGE_LEFT).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPadding(Yoga.EDGE_TOP).unit).toBe(Yoga.UNIT_UNDEFINED); - expect(root.getPadding(Yoga.EDGE_RIGHT).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPadding(Yoga.EDGE_BOTTOM).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPadding(Yoga.EDGE_START).unit).toBe( - Yoga.UNIT_UNDEFINED, - ); - expect(root.getPadding(Yoga.EDGE_END).unit).toBe(Yoga.UNIT_UNDEFINED); - - expect(root.getBorder(Yoga.EDGE_LEFT)).toBeFalsy(); - expect(root.getBorder(Yoga.EDGE_TOP)).toBeFalsy(); - expect(root.getBorder(Yoga.EDGE_RIGHT)).toBeFalsy(); - expect(root.getBorder(Yoga.EDGE_BOTTOM)).toBeFalsy(); - expect(root.getBorder(Yoga.EDGE_START)).toBeFalsy(); - expect(root.getBorder(Yoga.EDGE_END)).toBeFalsy(); - - expect(root.getWidth().unit).toBe(Yoga.UNIT_AUTO); - expect(root.getHeight().unit).toBe(Yoga.UNIT_AUTO); - expect(root.getMinWidth().unit).toBe(Yoga.UNIT_UNDEFINED); - expect(root.getMinHeight().unit).toBe(Yoga.UNIT_UNDEFINED); - expect(root.getMaxWidth().unit).toBe(Yoga.UNIT_UNDEFINED); - expect(root.getMaxHeight().unit).toBe(Yoga.UNIT_UNDEFINED); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedRight()).toBe(0); - expect(root.getComputedBottom()).toBe(0); - - expect(root.getComputedMargin(Yoga.EDGE_LEFT)).toBe(0); - expect(root.getComputedMargin(Yoga.EDGE_TOP)).toBe(0); - expect(root.getComputedMargin(Yoga.EDGE_RIGHT)).toBe(0); - expect(root.getComputedMargin(Yoga.EDGE_BOTTOM)).toBe(0); - - expect(root.getComputedPadding(Yoga.EDGE_LEFT)).toBe(0); - expect(root.getComputedPadding(Yoga.EDGE_TOP)).toBe(0); - expect(root.getComputedPadding(Yoga.EDGE_RIGHT)).toBe(0); - expect(root.getComputedPadding(Yoga.EDGE_BOTTOM)).toBe(0); - - expect(root.getComputedBorder(Yoga.EDGE_LEFT)).toBe(0); - expect(root.getComputedBorder(Yoga.EDGE_TOP)).toBe(0); - expect(root.getComputedBorder(Yoga.EDGE_RIGHT)).toBe(0); - expect(root.getComputedBorder(Yoga.EDGE_BOTTOM)).toBe(0); - - expect(root.getComputedWidth()).toBeFalsy(); - expect(root.getComputedHeight()).toBeFalsy(); - }); -}); diff --git a/packages/yoga/tests/dimention.test.js b/packages/yoga/tests/dimention.test.js deleted file mode 100644 index 209417e91..000000000 --- a/packages/yoga/tests/dimention.test.js +++ /dev/null @@ -1,245 +0,0 @@ -const Yoga = require('..'); - -describe('Dimensions', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - - // Set inital width - yogaNode.setWidth(100); - flexboxNode.setWidth(100); - - // Set inital height - yogaNode.setHeight(100); - flexboxNode.setHeight(100); - - // Set inital maxWidth - yogaNode.setMaxWidth(100); - flexboxNode.setMaxWidth(100); - - // Set inital maxHeight - yogaNode.setMaxHeight(100); - flexboxNode.setMaxHeight(100); - - // Set inital minWidth - yogaNode.setMinWidth(100); - flexboxNode.setMinWidth(100); - - // Set inital minHeight - yogaNode.setMinHeight(100); - flexboxNode.setMinHeight(100); - }); - - test('should have same width by default', () => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - - expect(yogaNode.getWidth()).toEqual(flexboxNode.getWidth()); - }); - - test('should have same height by default', () => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - - expect(yogaNode.getHeight()).toEqual(flexboxNode.getHeight()); - }); - - test('should have same maxWidth by default', () => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - - expect(yogaNode.getMaxWidth()).toEqual(flexboxNode.getMaxWidth()); - }); - - test('should have same maxHeight by default', () => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - - expect(yogaNode.getMaxHeight()).toEqual(flexboxNode.getMaxHeight()); - }); - - test('should setWidth', () => { - yogaNode.setWidth(200); - flexboxNode.setWidth(200); - - expect(yogaNode.getWidth()).toEqual(flexboxNode.getWidth()); - }); - - test('should setWidthAuto', () => { - yogaNode.setWidthAuto(); - flexboxNode.setWidthAuto(); - - expect(yogaNode.getWidth()).toEqual(flexboxNode.getWidth()); - }); - - test('should setWidthPercent', () => { - yogaNode.setWidthPercent(50); - flexboxNode.setWidthPercent(50); - - expect(yogaNode.getWidth()).toEqual(flexboxNode.getWidth()); - }); - - test('should setHeight', () => { - yogaNode.setHeight(200); - flexboxNode.setHeight(200); - - expect(yogaNode.getHeight()).toEqual(flexboxNode.getHeight()); - }); - - test('should setHeightAuto', () => { - yogaNode.setHeightAuto(); - flexboxNode.setHeightAuto(); - - expect(yogaNode.getHeight()).toEqual(flexboxNode.getHeight()); - }); - - test('should setHeightPercent', () => { - yogaNode.setHeightPercent(50); - flexboxNode.setHeightPercent(50); - - expect(yogaNode.getHeight()).toEqual(flexboxNode.getHeight()); - }); - - test('should setMaxWidth', () => { - yogaNode.setMaxWidth(200); - flexboxNode.setMaxWidth(200); - - expect(yogaNode.getMaxWidth()).toEqual(flexboxNode.getMaxWidth()); - }); - - test('should setMaxWidthPercent', () => { - yogaNode.setMaxWidthPercent(200); - flexboxNode.setMaxWidthPercent(200); - - expect(yogaNode.getMaxWidth()).toEqual(flexboxNode.getMaxWidth()); - }); - - test('should setMaxHeight', () => { - yogaNode.setMaxHeight(200); - flexboxNode.setMaxHeight(200); - - expect(yogaNode.getMaxHeight()).toEqual(flexboxNode.getMaxHeight()); - }); - - test('should setMaxHeightPercent', () => { - yogaNode.setMaxHeightPercent(200); - flexboxNode.setMaxHeightPercent(200); - - expect(yogaNode.getMaxHeight()).toEqual(flexboxNode.getMaxHeight()); - }); - - test('should setMinWidth', () => { - yogaNode.setMinWidth(200); - flexboxNode.setMinWidth(200); - - expect(yogaNode.getMinWidth()).toEqual(flexboxNode.getMinWidth()); - }); - - test('should setMinWidthPercent', () => { - yogaNode.setMinWidthPercent(200); - flexboxNode.setMinWidthPercent(200); - - expect(yogaNode.getMinWidth()).toEqual(flexboxNode.getMinWidth()); - }); - - test('should setMinHeight', () => { - yogaNode.setMinHeight(200); - flexboxNode.setMinHeight(200); - - expect(yogaNode.getMinHeight()).toEqual(flexboxNode.getMinHeight()); - }); - - test('should setMinHeightPercent', () => { - yogaNode.setMinHeightPercent(200); - flexboxNode.setMinHeightPercent(200); - - expect(yogaNode.getMinHeight()).toEqual(flexboxNode.getMinHeight()); - }); - - test('should setAspectRatio', () => { - yogaNode.setAspectRatio(200); - flexboxNode.setAspectRatio(200); - - expect(yogaNode.getAspectRatio()).toEqual(flexboxNode.getAspectRatio()); - }); - - test('wrap child', () => { - const root = Yoga.Node.create(); - - const child = Yoga.Node.create(); - child.setWidth(100); - child.setHeight(100); - 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(100); - expect(child.getComputedLayout().height).toBe(100); - - 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(100); - expect(child.getComputedLayout().height).toBe(100); - }); - - test('wrap grandchild', () => { - const root = Yoga.Node.create(); - - const child = Yoga.Node.create(); - root.insertChild(child, 0); - - const grandchild = Yoga.Node.create(); - grandchild.setWidth(100); - grandchild.setHeight(100); - child.insertChild(grandchild, 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(100); - expect(child.getComputedLayout().height).toBe(100); - - expect(grandchild.getComputedLayout().left).toBe(0); - expect(grandchild.getComputedLayout().top).toBe(0); - expect(grandchild.getComputedLayout().width).toBe(100); - expect(grandchild.getComputedLayout().height).toBe(100); - - 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(100); - expect(child.getComputedLayout().height).toBe(100); - - expect(grandchild.getComputedLayout().left).toBe(0); - expect(grandchild.getComputedLayout().top).toBe(0); - expect(grandchild.getComputedLayout().width).toBe(100); - expect(grandchild.getComputedLayout().height).toBe(100); - }); -}); diff --git a/packages/yoga/tests/display.test.js b/packages/yoga/tests/display.test.js deleted file mode 100644 index e1f7b5f12..000000000 --- a/packages/yoga/tests/display.test.js +++ /dev/null @@ -1,294 +0,0 @@ -const Yoga = require('..'); - -describe('Display', () => { - test('display_none', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setDisplay(Yoga.DISPLAY_NONE); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - }); - - test('display_none_fixed_size', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(20); - child1.setHeight(20); - child1.setDisplay(Yoga.DISPLAY_NONE); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - }); - - test('display_none_with_margin', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_LEFT, 10); - child0.setMargin(Yoga.EDGE_TOP, 10); - child0.setMargin(Yoga.EDGE_RIGHT, 10); - child0.setMargin(Yoga.EDGE_BOTTOM, 10); - child0.setWidth(20); - child0.setHeight(20); - child0.setDisplay(Yoga.DISPLAY_NONE); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('display_none_with_child', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexShrink(1); - child0.setFlexBasisPercent(0); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexShrink(1); - child1.setFlexBasisPercent(0); - child1.setDisplay(Yoga.DISPLAY_NONE); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setFlexShrink(1); - child2.setFlexBasisPercent(0); - child2.setWidth(20); - child2.setMinWidth(0); - child2.setMinHeight(0); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setFlexGrow(1); - child3.setFlexShrink(1); - child3.setFlexBasisPercent(0); - root.insertChild(child3, 2); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(50); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(0); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(50); - expect(child3.getComputedLayout().height).toBe(100); - }); - - test('display_none_with_position', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setPosition(Yoga.EDGE_TOP, 10); - child1.setDisplay(Yoga.DISPLAY_NONE); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(0); - }); -}); diff --git a/packages/yoga/tests/edge.test.js b/packages/yoga/tests/edge.test.js deleted file mode 100644 index f1ba56ee5..000000000 --- a/packages/yoga/tests/edge.test.js +++ /dev/null @@ -1,141 +0,0 @@ -const Yoga = require('..'); - -describe('Edge', () => { - test('start_overrides', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_START, 10); - child0.setMargin(Yoga.EDGE_LEFT, 20); - child0.setMargin(Yoga.EDGE_RIGHT, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().right).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().right).toBe(10); - }); - - test('end_overrides', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_END, 10); - child0.setMargin(Yoga.EDGE_LEFT, 20); - child0.setMargin(Yoga.EDGE_RIGHT, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().right).toBe(10); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - expect(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().right).toBe(20); - }); - - test('horizontal_overridden', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_HORIZONTAL, 10); - child0.setMargin(Yoga.EDGE_LEFT, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().right).toBe(10); - }); - - test('vertical_overridden', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_VERTICAL, 10); - child0.setMargin(Yoga.EDGE_TOP, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().top).toBe(20); - expect(child0.getComputedLayout().bottom).toBe(10); - }); - - test('horizontal_overrides_all', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_HORIZONTAL, 10); - child0.setMargin(Yoga.EDGE_ALL, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(20); - expect(child0.getComputedLayout().right).toBe(10); - expect(child0.getComputedLayout().bottom).toBe(20); - }); - - test('vertical_overrides_all', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_VERTICAL, 10); - child0.setMargin(Yoga.EDGE_ALL, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().right).toBe(20); - expect(child0.getComputedLayout().bottom).toBe(10); - }); - - test('all_overridden', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_LEFT, 10); - child0.setMargin(Yoga.EDGE_TOP, 10); - child0.setMargin(Yoga.EDGE_RIGHT, 10); - child0.setMargin(Yoga.EDGE_BOTTOM, 10); - child0.setMargin(Yoga.EDGE_ALL, 20); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - expect(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().right).toBe(10); - expect(child0.getComputedLayout().bottom).toBe(10); - }); -}); diff --git a/packages/yoga/tests/flexDirection.test.js b/packages/yoga/tests/flexDirection.test.js deleted file mode 100644 index 72ad7f08d..000000000 --- a/packages/yoga/tests/flexDirection.test.js +++ /dev/null @@ -1,371 +0,0 @@ -const Yoga = require('..'); - -describe('Flex direction', () => { - test('flex_direction_column_no_height', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - 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(30); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.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(30); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('flex_direction_row_no_width', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(30); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(20); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(30); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(100); - }); - - test('flex_direction_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('flex_direction_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(20); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(90); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(80); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(70); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(100); - }); - - test('flex_direction_column_reverse', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN_REVERSE); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(90); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(80); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(70); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(90); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(80); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(70); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('flex_direction_row_reverse', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW_REVERSE); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - 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(child0.getComputedLayout().left).toBe(90); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(80); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(70); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(20); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(100); - }); -}); diff --git a/packages/yoga/tests/flexSpec.test.js b/packages/yoga/tests/flexSpec.test.js deleted file mode 100644 index 5c023dfc5..000000000 --- a/packages/yoga/tests/flexSpec.test.js +++ /dev/null @@ -1,435 +0,0 @@ -const Yoga = require('..'); - -describe('Flex', () => { - test('flex_basis_flex_grow_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexBasis(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(75); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(25); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(75); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(25); - }); - - test('flex_basis_flex_grow_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexBasis(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(75); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(25); - expect(child1.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(25); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(75); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(25); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('flex_basis_flex_shrink_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexShrink(1); - child0.setFlexBasis(100); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexBasis(50); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(50); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('flex_basis_flex_shrink_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexShrink(1); - child0.setFlexBasis(100); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexBasis(50); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('flex_shrink_to_zero', () => { - const root = Yoga.Node.create(); - root.setHeight(75); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexShrink(1); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(50); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(50); - expect(root.getComputedLayout().height).toBe(75); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(50); - expect(root.getComputedLayout().height).toBe(75); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - }); - - test('flex_basis_overrides_main_size', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexBasis(50); - child0.setHeight(20); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(1); - child2.setHeight(10); - root.insertChild(child2, 2); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(60); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(20); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(60); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(20); - }); - - test('flex_grow_shrink_at_most', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexShrink(1); - child0.insertChild(child1, 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(0); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(0); - }); - - test('flex_grow_less_than_factor_one', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(500); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(0.2); - child0.setFlexBasis(40); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(0.2); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setFlexGrow(0.4); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(132); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(132); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(92); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(224); - expect(child2.getComputedLayout().width).toBe(200); - expect(child2.getComputedLayout().height).toBe(184); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(132); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(132); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(92); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(224); - expect(child2.getComputedLayout().width).toBe(200); - expect(child2.getComputedLayout().height).toBe(184); - }); -}); diff --git a/packages/yoga/tests/flexWrap.test.js b/packages/yoga/tests/flexWrap.test.js deleted file mode 100644 index 1dccb619e..000000000 --- a/packages/yoga/tests/flexWrap.test.js +++ /dev/null @@ -1,1607 +0,0 @@ -const Yoga = require('..'); - -describe('Flex wrap', () => { - test('wrap_column', () => { - const root = Yoga.Node.create(); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(30); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(30); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(30); - root.insertChild(child3, 3); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(60); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(30); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(30); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(30); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(60); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(30); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(60); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(30); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(30); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(30); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(30); - - expect(child2.getComputedLayout().left).toBe(30); - expect(child2.getComputedLayout().top).toBe(60); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(0); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - }); - - test('wrap_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(30); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(30); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(30); - root.insertChild(child3, 3); - 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(60); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(30); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(30); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - - 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(60); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(30); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(30); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - }); - - test('wrap_row_align_items_flex_end', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_FLEX_END); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(30); - root.insertChild(child3, 3); - 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(60); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(20); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - - 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(60); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(20); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - }); - - test('wrap_row_align_items_center', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(30); - root.insertChild(child3, 3); - 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(60); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(5); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - - 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(60); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(5); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(30); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(30); - }); - - test('flex_wrap_children_with_min_main_overriding_flex_basis', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setFlexBasis(50); - child0.setMinWidth(55); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexBasis(50); - child1.setMinWidth(55); - child1.setHeight(50); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(55); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(55); - expect(child1.getComputedLayout().height).toBe(50); - - 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(child0.getComputedLayout().left).toBe(45); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(55); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(45); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(55); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('flex_wrap_wrap_to_child_height', () => { - const root = Yoga.Node.create(); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setAlignItems(Yoga.ALIGN_FLEX_START); - child0.setFlexWrap(Yoga.WRAP_WRAP); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(100); - child0.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(100); - child2.setHeight(100); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setWidth(100); - child3.setHeight(100); - root.insertChild(child3, 1); - 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(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(100); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(100); - expect(child3.getComputedLayout().width).toBe(100); - expect(child3.getComputedLayout().height).toBe(100); - - 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(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(100); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(100); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(100); - expect(child3.getComputedLayout().width).toBe(100); - expect(child3.getComputedLayout().height).toBe(100); - }); - - test('flex_wrap_align_stretch_fits_one_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(150); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(0); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(0); - }); - - test('wrap_reverse_row_align_content_flex_start', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(40); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(30); - child4.setHeight(50); - root.insertChild(child4, 4); - 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(80); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(30); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - - 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(80); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(40); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('wrap_reverse_row_align_content_center', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_CENTER); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(40); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(30); - child4.setHeight(50); - root.insertChild(child4, 4); - 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(80); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(30); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - - 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(80); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(40); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('wrap_reverse_row_single_line_different_size', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(300); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(40); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(30); - child4.setHeight(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(300); - expect(root.getComputedLayout().height).toBe(50); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(40); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(30); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(90); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(120); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(300); - expect(root.getComputedLayout().height).toBe(50); - - expect(child0.getComputedLayout().left).toBe(270); - expect(child0.getComputedLayout().top).toBe(40); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(240); - expect(child1.getComputedLayout().top).toBe(30); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(210); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(180); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(150); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('wrap_reverse_row_align_content_stretch', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(40); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(30); - child4.setHeight(50); - root.insertChild(child4, 4); - 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(80); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(30); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - - 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(80); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(40); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('wrap_reverse_row_align_content_space_around', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_SPACE_AROUND); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(40); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(30); - child4.setHeight(50); - root.insertChild(child4, 4); - 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(80); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(60); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(30); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - - 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(80); - - expect(child0.getComputedLayout().left).toBe(70); - expect(child0.getComputedLayout().top).toBe(70); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(40); - expect(child1.getComputedLayout().top).toBe(60); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(10); - expect(child2.getComputedLayout().top).toBe(50); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(70); - expect(child3.getComputedLayout().top).toBe(10); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(40); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('wrap_reverse_column_fixed_size', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - root.setWidth(200); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setWidth(30); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(30); - child1.setHeight(20); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(30); - child2.setHeight(30); - root.insertChild(child2, 2); - - const child3 = Yoga.Node.create(); - child3.setWidth(30); - child3.setHeight(40); - root.insertChild(child3, 3); - - const child4 = Yoga.Node.create(); - child4.setWidth(30); - child4.setHeight(50); - root.insertChild(child4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(170); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(170); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(170); - expect(child2.getComputedLayout().top).toBe(30); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(170); - expect(child3.getComputedLayout().top).toBe(60); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(140); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(30); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(30); - expect(child1.getComputedLayout().height).toBe(20); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(30); - expect(child2.getComputedLayout().width).toBe(30); - expect(child2.getComputedLayout().height).toBe(30); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(60); - expect(child3.getComputedLayout().width).toBe(30); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(30); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(30); - expect(child4.getComputedLayout().height).toBe(50); - }); - - test('wrapped_row_within_align_items_center', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setFlexWrap(Yoga.WRAP_WRAP); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(150); - child1.setHeight(80); - child0.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(80); - child2.setHeight(80); - child0.insertChild(child2, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(160); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(150); - expect(child1.getComputedLayout().height).toBe(80); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(80); - expect(child2.getComputedLayout().height).toBe(80); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(160); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(150); - expect(child1.getComputedLayout().height).toBe(80); - - expect(child2.getComputedLayout().left).toBe(120); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(80); - expect(child2.getComputedLayout().height).toBe(80); - }); - - test('wrapped_row_within_align_items_flex_start', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setFlexWrap(Yoga.WRAP_WRAP); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(150); - child1.setHeight(80); - child0.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(80); - child2.setHeight(80); - child0.insertChild(child2, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(160); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(150); - expect(child1.getComputedLayout().height).toBe(80); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(80); - expect(child2.getComputedLayout().height).toBe(80); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(160); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(150); - expect(child1.getComputedLayout().height).toBe(80); - - expect(child2.getComputedLayout().left).toBe(120); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(80); - expect(child2.getComputedLayout().height).toBe(80); - }); - - test('wrapped_row_within_align_items_flex_end', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_FLEX_END); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setFlexWrap(Yoga.WRAP_WRAP); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(150); - child1.setHeight(80); - child0.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(80); - child2.setHeight(80); - child0.insertChild(child2, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(160); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(150); - expect(child1.getComputedLayout().height).toBe(80); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(80); - expect(child2.getComputedLayout().height).toBe(80); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(200); - expect(child0.getComputedLayout().height).toBe(160); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(150); - expect(child1.getComputedLayout().height).toBe(80); - - expect(child2.getComputedLayout().left).toBe(120); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(80); - expect(child2.getComputedLayout().height).toBe(80); - }); - - test('wrapped_column_max_height', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignContent(Yoga.ALIGN_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(700); - root.setHeight(500); - - const child0 = Yoga.Node.create(); - child0.setWidth(100); - child0.setHeight(500); - child0.setMaxHeight(200); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setMargin(Yoga.EDGE_LEFT, 20); - child1.setMargin(Yoga.EDGE_TOP, 20); - child1.setMargin(Yoga.EDGE_RIGHT, 20); - child1.setMargin(Yoga.EDGE_BOTTOM, 20); - child1.setWidth(200); - child1.setHeight(200); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(100); - child2.setHeight(100); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(700); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(250); - expect(child0.getComputedLayout().top).toBe(30); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(200); - - expect(child1.getComputedLayout().left).toBe(200); - expect(child1.getComputedLayout().top).toBe(250); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(200); - - expect(child2.getComputedLayout().left).toBe(420); - expect(child2.getComputedLayout().top).toBe(200); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(700); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(350); - expect(child0.getComputedLayout().top).toBe(30); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(200); - - expect(child1.getComputedLayout().left).toBe(300); - expect(child1.getComputedLayout().top).toBe(250); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(200); - - expect(child2.getComputedLayout().left).toBe(180); - expect(child2.getComputedLayout().top).toBe(200); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(100); - }); - - test('wrapped_column_max_height_flex', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignContent(Yoga.ALIGN_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(700); - root.setHeight(500); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexShrink(1); - child0.setFlexBasisPercent(0); - child0.setWidth(100); - child0.setHeight(500); - child0.setMaxHeight(200); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - child1.setFlexShrink(1); - child1.setFlexBasisPercent(0); - child1.setMargin(Yoga.EDGE_LEFT, 20); - child1.setMargin(Yoga.EDGE_TOP, 20); - child1.setMargin(Yoga.EDGE_RIGHT, 20); - child1.setMargin(Yoga.EDGE_BOTTOM, 20); - child1.setWidth(200); - child1.setHeight(200); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(100); - child2.setHeight(100); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(700); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(300); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(180); - - expect(child1.getComputedLayout().left).toBe(250); - expect(child1.getComputedLayout().top).toBe(200); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(180); - - expect(child2.getComputedLayout().left).toBe(300); - expect(child2.getComputedLayout().top).toBe(400); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(700); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(300); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(180); - - expect(child1.getComputedLayout().left).toBe(250); - expect(child1.getComputedLayout().top).toBe(200); - expect(child1.getComputedLayout().width).toBe(200); - expect(child1.getComputedLayout().height).toBe(180); - - expect(child2.getComputedLayout().left).toBe(300); - expect(child2.getComputedLayout().top).toBe(400); - expect(child2.getComputedLayout().width).toBe(100); - expect(child2.getComputedLayout().height).toBe(100); - }); - - test('wrap_nodes_with_content_sizing_overflowing_margin', () => { - const root = Yoga.Node.create(); - root.setWidth(500); - root.setHeight(500); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setFlexWrap(Yoga.WRAP_WRAP); - child0.setWidth(85); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child0.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(40); - child2.setHeight(40); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setMargin(Yoga.EDGE_RIGHT, 10); - child0.insertChild(child3, 1); - - const child4 = Yoga.Node.create(); - child4.setWidth(40); - child4.setHeight(40); - child3.insertChild(child4, 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(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(85); - expect(child0.getComputedLayout().height).toBe(80); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(40); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(40); - expect(child2.getComputedLayout().height).toBe(40); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(40); - expect(child3.getComputedLayout().width).toBe(40); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(415); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(85); - expect(child0.getComputedLayout().height).toBe(80); - - expect(child1.getComputedLayout().left).toBe(45); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(40); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(40); - expect(child2.getComputedLayout().height).toBe(40); - - expect(child3.getComputedLayout().left).toBe(35); - expect(child3.getComputedLayout().top).toBe(40); - expect(child3.getComputedLayout().width).toBe(40); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(40); - }); - - test('wrap_nodes_with_content_sizing_margin_cross', () => { - const root = Yoga.Node.create(); - root.setWidth(500); - root.setHeight(500); - - const child0 = Yoga.Node.create(); - child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - child0.setFlexWrap(Yoga.WRAP_WRAP); - child0.setWidth(70); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child0.insertChild(child1, 0); - - const child2 = Yoga.Node.create(); - child2.setWidth(40); - child2.setHeight(40); - child1.insertChild(child2, 0); - - const child3 = Yoga.Node.create(); - child3.setMargin(Yoga.EDGE_TOP, 10); - child0.insertChild(child3, 1); - - const child4 = Yoga.Node.create(); - child4.setWidth(40); - child4.setHeight(40); - child3.insertChild(child4, 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(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(70); - expect(child0.getComputedLayout().height).toBe(90); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(40); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(40); - expect(child2.getComputedLayout().height).toBe(40); - - expect(child3.getComputedLayout().left).toBe(0); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(40); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(child0.getComputedLayout().left).toBe(430); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(70); - expect(child0.getComputedLayout().height).toBe(90); - - expect(child1.getComputedLayout().left).toBe(30); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(40); - expect(child1.getComputedLayout().height).toBe(40); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(40); - expect(child2.getComputedLayout().height).toBe(40); - - expect(child3.getComputedLayout().left).toBe(30); - expect(child3.getComputedLayout().top).toBe(50); - expect(child3.getComputedLayout().width).toBe(40); - expect(child3.getComputedLayout().height).toBe(40); - - expect(child4.getComputedLayout().left).toBe(0); - expect(child4.getComputedLayout().top).toBe(0); - expect(child4.getComputedLayout().width).toBe(40); - expect(child4.getComputedLayout().height).toBe(40); - }); -}); diff --git a/packages/yoga/tests/flexbox.test.js b/packages/yoga/tests/flexbox.test.js deleted file mode 100644 index 67a22f8d3..000000000 --- a/packages/yoga/tests/flexbox.test.js +++ /dev/null @@ -1,143 +0,0 @@ -const Yoga = require('..'); - -describe('Flexbox', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - }); - - test('Should have the same flexDirection by default', () => { - expect(yogaNode.getFlexDirection()).toEqual(flexboxNode.getFlexDirection()); - }); - - test('Should have the same justifyContent by default', () => { - expect(yogaNode.getJustifyContent()).toEqual( - flexboxNode.getJustifyContent(), - ); - }); - - test('Should have the same alignContent by default', () => { - expect(yogaNode.getAlignContent()).toEqual(flexboxNode.getAlignContent()); - }); - - test('Should have the same alignItems by default', () => { - expect(yogaNode.getAlignItems()).toEqual(flexboxNode.getAlignItems()); - }); - - test('Should have the same alignSelf by default', () => { - expect(yogaNode.getAlignSelf()).toEqual(flexboxNode.getAlignSelf()); - }); - - test('Should have the same flexWrap by default', () => { - expect(yogaNode.getFlexWrap()).toEqual(flexboxNode.getFlexWrap()); - }); - - test('Should have the same display by default', () => { - expect(yogaNode.getDisplay()).toEqual(flexboxNode.getDisplay()); - }); - - test('Should have the same flexGrow by default', () => { - expect(yogaNode.getFlexGrow()).toEqual(flexboxNode.getFlexGrow()); - }); - - test('Should have the same flexShrink by default', () => { - expect(yogaNode.getFlexShrink()).toEqual(flexboxNode.getFlexShrink()); - }); - - test('Should have the same flexBasis by default', () => { - expect(yogaNode.getFlexBasis()).toEqual(flexboxNode.getFlexBasis()); - }); - - test('Should setFlexDirection', () => { - yogaNode.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - flexboxNode.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - - expect(yogaNode.getFlexDirection()).toEqual(flexboxNode.getFlexDirection()); - }); - - test('Should setJustifyContent', () => { - yogaNode.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - flexboxNode.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - - expect(yogaNode.getJustifyContent()).toEqual( - flexboxNode.getJustifyContent(), - ); - }); - - test('Should setAlignContent', () => { - yogaNode.setAlignContent(Yoga.ALIGN_CENTER); - flexboxNode.setAlignContent(Yoga.ALIGN_CENTER); - - expect(yogaNode.getAlignContent()).toEqual(flexboxNode.getAlignContent()); - }); - - test('Should setAlignItems', () => { - yogaNode.setAlignItems(Yoga.ALIGN_CENTER); - flexboxNode.setAlignItems(Yoga.ALIGN_CENTER); - - expect(yogaNode.getAlignItems()).toEqual(flexboxNode.getAlignItems()); - }); - - test('Should setAlignSelf', () => { - yogaNode.setAlignSelf(Yoga.ALIGN_CENTER); - flexboxNode.setAlignSelf(Yoga.ALIGN_CENTER); - - expect(yogaNode.getAlignSelf()).toEqual(flexboxNode.getAlignSelf()); - }); - - test('Should setFlexWrap', () => { - yogaNode.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - flexboxNode.setFlexWrap(Yoga.WRAP_WRAP_REVERSE); - - expect(yogaNode.getFlexWrap()).toEqual(flexboxNode.getFlexWrap()); - }); - - test('Should setDisplay', () => { - yogaNode.setDisplay(Yoga.DISPLAY_NONE); - flexboxNode.setDisplay(Yoga.DISPLAY_NONE); - - expect(yogaNode.getDisplay()).toEqual(flexboxNode.getDisplay()); - }); - - test('Should setFlexGrow', () => { - yogaNode.setFlexGrow(1); - flexboxNode.setFlexGrow(1); - - expect(yogaNode.getFlexGrow()).toEqual(flexboxNode.getFlexGrow()); - }); - - test('Should setFlexShrink', () => { - yogaNode.setFlexShrink(1); - flexboxNode.setFlexShrink(1); - - expect(yogaNode.getFlexShrink()).toEqual(flexboxNode.getFlexShrink()); - }); - - test('Should setFlexBasis', () => { - yogaNode.setFlexBasis(1); - flexboxNode.setFlexBasis(1); - - expect(yogaNode.getFlexBasis()).toEqual(flexboxNode.getFlexBasis()); - }); - - test('Should setFlexBasisPercent', () => { - yogaNode.setFlexBasisPercent(1); - flexboxNode.setFlexBasisPercent(1); - - expect(yogaNode.getFlexBasis()).toEqual(flexboxNode.getFlexBasis()); - }); - - test('Should setFlex', () => { - yogaNode.setFlex(1); - flexboxNode.setFlex(1); - - expect(yogaNode.getFlexDirection()).toEqual(flexboxNode.getFlexDirection()); - expect(yogaNode.getFlexWrap()).toEqual(flexboxNode.getFlexWrap()); - expect(yogaNode.getFlexGrow()).toEqual(flexboxNode.getFlexGrow()); - expect(yogaNode.getFlexShrink()).toEqual(flexboxNode.getFlexShrink()); - expect(yogaNode.getFlexBasis()).toEqual(flexboxNode.getFlexBasis()); - }); -}); diff --git a/packages/yoga/tests/index.test.js b/packages/yoga/tests/index.test.js deleted file mode 100644 index 2de358b8b..000000000 --- a/packages/yoga/tests/index.test.js +++ /dev/null @@ -1,53 +0,0 @@ -const Yoga = require('..'); - -describe('yoga-layout', () => { - test('layout works', () => { - const config = Yoga.Config.create(); - - const root = Yoga.Node.create(config); - root.setWidth(100); - root.setHeight(100); - - const firstChild = Yoga.Node.create(config); - firstChild.setFlexGrow(1); - firstChild.setFlexBasis(50); - root.insertChild(firstChild, 0); - - const secondChild = Yoga.Node.create(config); - secondChild.setFlexGrow(1); - root.insertChild(secondChild, 1); - root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(firstChild.getComputedLeft()).toBe(0); - expect(firstChild.getComputedTop()).toBe(0); - expect(firstChild.getComputedWidth()).toBe(100); - expect(firstChild.getComputedHeight()).toBe(75); - - expect(secondChild.getComputedLeft()).toBe(0); - expect(secondChild.getComputedTop()).toBe(75); - expect(secondChild.getComputedWidth()).toBe(100); - expect(secondChild.getComputedHeight()).toBe(25); - - root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(firstChild.getComputedLeft()).toBe(0); - expect(firstChild.getComputedTop()).toBe(0); - expect(firstChild.getComputedWidth()).toBe(100); - expect(firstChild.getComputedHeight()).toBe(75); - - expect(secondChild.getComputedLeft()).toBe(0); - expect(secondChild.getComputedTop()).toBe(75); - expect(secondChild.getComputedWidth()).toBe(100); - expect(secondChild.getComputedHeight()).toBe(25); - }); -}); diff --git a/packages/yoga/tests/infiniteHeight.test.js b/packages/yoga/tests/infiniteHeight.test.js deleted file mode 100644 index 8954e902e..000000000 --- a/packages/yoga/tests/infiniteHeight.test.js +++ /dev/null @@ -1,38 +0,0 @@ -const Yoga = require('..'); - -describe('Infinite height', () => { - test('percent_absolute_position_infinite_height', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(300); - - const child0 = Yoga.Node.create(); - child0.setWidth(300); - child0.setHeight(300); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - child1.setPositionPercent(Yoga.EDGE_LEFT, 20); - child1.setPositionPercent(Yoga.EDGE_TOP, 20); - child1.setWidthPercent(20); - child1.setHeightPercent(20); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(300); - expect(root.getComputedLayout().height).toBe(300); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(300); - expect(child0.getComputedLayout().height).toBe(300); - - expect(child1.getComputedLayout().left).toBe(60); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(60); - expect(child1.getComputedLayout().height).toBe(0); - }); -}); diff --git a/packages/yoga/tests/justifyContent.test.js b/packages/yoga/tests/justifyContent.test.js deleted file mode 100644 index 44ac0f53d..000000000 --- a/packages/yoga/tests/justifyContent.test.js +++ /dev/null @@ -1,895 +0,0 @@ -const Yoga = require('..'); - -describe('Justify content', () => { - test('justify_content_row_flex_start', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(20); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(92); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(82); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(72); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - }); - - test('justify_content_row_flex_end', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(72); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(82); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(92); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(10); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - }); - - test('justify_content_row_center', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(36); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(46); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(56); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(56); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(46); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(36); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - }); - - test('justify_content_row_space_between', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_SPACE_BETWEEN); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(46); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(92); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(92); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(46); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - }); - - test('justify_content_row_space_around', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setWidth(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(12); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(46); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(80); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(80); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(102); - - expect(child1.getComputedLayout().left).toBe(46); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(10); - expect(child1.getComputedLayout().height).toBe(102); - - expect(child2.getComputedLayout().left).toBe(12); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(10); - expect(child2.getComputedLayout().height).toBe(102); - }); - - test('justify_content_column_flex_start', () => { - const root = Yoga.Node.create(); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(10); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(20); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('justify_content_column_flex_end', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(72); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(82); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(92); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(72); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(82); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(92); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('justify_content_column_center', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(36); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(56); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(36); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(56); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('justify_content_column_space_between', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_SPACE_BETWEEN); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(92); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(92); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('justify_content_column_space_around', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(12); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(12); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(80); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('justify_content_row_min_width_and_margin', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setMargin(Yoga.EDGE_LEFT, 100); - root.setMinWidth(50); - - const child0 = Yoga.Node.create(); - child0.setWidth(20); - child0.setHeight(20); - root.insertChild(child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(100); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(50); - expect(root.getComputedLayout().height).toBe(20); - - expect(child0.getComputedLayout().left).toBe(15); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(100); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(50); - expect(root.getComputedLayout().height).toBe(20); - - expect(child0.getComputedLayout().left).toBe(15); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - }); - - test('justify_content_row_max_width_and_margin', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setMargin(Yoga.EDGE_LEFT, 100); - root.setWidth(100); - root.setMaxWidth(80); - - const child0 = Yoga.Node.create(); - child0.setWidth(20); - child0.setHeight(20); - root.insertChild(child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(100); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(80); - expect(root.getComputedLayout().height).toBe(20); - - expect(child0.getComputedLayout().left).toBe(30); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(100); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(80); - expect(root.getComputedLayout().height).toBe(20); - - expect(child0.getComputedLayout().left).toBe(30); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - }); - - test('justify_content_column_min_height_and_margin', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setMargin(Yoga.EDGE_TOP, 100); - root.setMinHeight(50); - - const child0 = Yoga.Node.create(); - child0.setWidth(20); - child0.setHeight(20); - root.insertChild(child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(100); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(50); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(15); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(100); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(50); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(15); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - }); - - test('justify_content_colunn_max_height_and_margin', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setMargin(Yoga.EDGE_TOP, 100); - root.setHeight(100); - root.setMaxHeight(80); - - const child0 = Yoga.Node.create(); - child0.setWidth(20); - child0.setHeight(20); - root.insertChild(child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(100); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(80); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(30); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(100); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(80); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(30); - expect(child0.getComputedLayout().width).toBe(20); - expect(child0.getComputedLayout().height).toBe(20); - }); - - test('justify_content_column_space_evenly', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_SPACE_EVENLY); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(18); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(74); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(18); - expect(child0.getComputedLayout().width).toBe(102); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(46); - expect(child1.getComputedLayout().width).toBe(102); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(74); - expect(child2.getComputedLayout().width).toBe(102); - expect(child2.getComputedLayout().height).toBe(10); - }); - - test('justify_content_row_space_evenly', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_SPACE_EVENLY); - root.setWidth(102); - root.setHeight(102); - - const child0 = Yoga.Node.create(); - child0.setHeight(10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setHeight(10); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setHeight(10); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(26); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(51); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(77); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.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(102); - expect(root.getComputedLayout().height).toBe(102); - - expect(child0.getComputedLayout().left).toBe(77); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(10); - - expect(child1.getComputedLayout().left).toBe(51); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(0); - expect(child1.getComputedLayout().height).toBe(10); - - expect(child2.getComputedLayout().left).toBe(26); - expect(child2.getComputedLayout().top).toBe(0); - expect(child2.getComputedLayout().width).toBe(0); - expect(child2.getComputedLayout().height).toBe(10); - }); -}); diff --git a/packages/yoga/tests/margin.test.js b/packages/yoga/tests/margin.test.js deleted file mode 100644 index 021f0fdf3..000000000 --- a/packages/yoga/tests/margin.test.js +++ /dev/null @@ -1,1741 +0,0 @@ -const Yoga = require('..'); - -describe('Margins', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - }); - - test('should have same top margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_TOP), - ); - }); - - test('should have same left margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_LEFT), - ); - }); - - test('should have same bottom margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_BOTTOM), - ); - }); - - test('should have same right margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_RIGHT), - ); - }); - - test('should have same vertical margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_VERTICAL), - ); - }); - - test('should have same horizontal margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should have same start margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_START)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_START), - ); - }); - - test('should have same end margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_END)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_END), - ); - }); - - test('should have same all margin by default', () => { - expect(yogaNode.getMargin(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_ALL), - ); - }); - - test('should set top margin', () => { - yogaNode.setMargin(Yoga.EDGE_TOP, 5); - flexboxNode.setMargin(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_TOP), - ); - }); - - test('should set left margin', () => { - yogaNode.setMargin(Yoga.EDGE_LEFT, 5); - flexboxNode.setMargin(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom margin', () => { - yogaNode.setMargin(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setMargin(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right margin', () => { - yogaNode.setMargin(Yoga.EDGE_RIGHT, 5); - flexboxNode.setMargin(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical margin', () => { - yogaNode.setMargin(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setMargin(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal margin', () => { - yogaNode.setMargin(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setMargin(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start margin', () => { - yogaNode.setMargin(Yoga.EDGE_START, 5); - flexboxNode.setMargin(Yoga.EDGE_START, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_START)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_START), - ); - }); - - test('should set end margin', () => { - yogaNode.setMargin(Yoga.EDGE_END, 5); - flexboxNode.setMargin(Yoga.EDGE_END, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_END)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_END), - ); - }); - - test('should set all margin', () => { - yogaNode.setMargin(Yoga.EDGE_ALL, 5); - flexboxNode.setMargin(Yoga.EDGE_ALL, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_ALL), - ); - }); - - test('should set margin auto', () => { - yogaNode.setMarginAuto(Yoga.EDGE_ALL); - flexboxNode.setMarginAuto(Yoga.EDGE_ALL); - - expect(yogaNode.getMargin(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_ALL), - ); - }); - - test('should set top percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_TOP, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_TOP), - ); - }); - - test('should set left percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_LEFT, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_RIGHT, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_START, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_START, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_START)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_START), - ); - - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - root.setMarginPercent(Yoga.EDGE_START, 10); - root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); - }); - - test('should set end percent margin', () => { - yogaNode.setMarginPercent(Yoga.EDGE_END, 5); - flexboxNode.setMarginPercent(Yoga.EDGE_END, 5); - - expect(yogaNode.getMargin(Yoga.EDGE_END)).toEqual( - flexboxNode.getMargin(Yoga.EDGE_END), - ); - }); - - test('margin_start', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_START, 10); - child0.setWidth(10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(80); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - }); - - test('margin_top', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_TOP, 10); - child0.setHeight(10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - }); - - test('margin_end', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_END, 10); - child0.setWidth(10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(80); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(10); - expect(child0.getComputedLayout().height).toBe(100); - }); - - test('margin_bottom', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_BOTTOM, 10); - child0.setHeight(10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(80); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(80); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(10); - }); - - test('margin_and_flex_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_START, 10); - child0.setMargin(Yoga.EDGE_END, 10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(80); - expect(child0.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(80); - expect(child0.getComputedLayout().height).toBe(100); - }); - - test('margin_and_flex_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_TOP, 10); - child0.setMargin(Yoga.EDGE_BOTTOM, 10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(80); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(80); - }); - - test('margin_and_stretch_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_TOP, 10); - child0.setMargin(Yoga.EDGE_BOTTOM, 10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(80); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(10); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(80); - }); - - test('margin_and_stretch_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_START, 10); - child0.setMargin(Yoga.EDGE_END, 10); - root.insertChild(child0, 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(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(80); - expect(child0.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(80); - expect(child0.getComputedLayout().height).toBe(100); - }); - - test('margin_with_sibling_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_END, 10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(45); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(55); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(45); - expect(child1.getComputedLayout().height).toBe(100); - - 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(child0.getComputedLayout().left).toBe(55); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(45); - expect(child0.getComputedLayout().height).toBe(100); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(45); - expect(child1.getComputedLayout().height).toBe(100); - }); - - test('margin_with_sibling_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setMargin(Yoga.EDGE_BOTTOM, 10); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setFlexGrow(1); - root.insertChild(child1, 1); - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(45); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(55); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(45); - - 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(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(45); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(55); - expect(child1.getComputedLayout().width).toBe(100); - expect(child1.getComputedLayout().height).toBe(45); - }); - - test('margin_auto_bottom', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_BOTTOM); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_top', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_TOP); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(100); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(100); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_bottom_and_top', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_TOP); - child0.setMarginAuto(Yoga.EDGE_BOTTOM); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(50); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(50); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_bottom_and_top_justify_center', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_TOP); - child0.setMarginAuto(Yoga.EDGE_BOTTOM); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(50); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(150); - expect(child0.getComputedLayout().top).toBe(50); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_mutiple_children_column', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_TOP); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setMarginAuto(Yoga.EDGE_TOP); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(50); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(25); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(100); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(75); - expect(child2.getComputedLayout().top).toBe(150); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(25); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(100); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(75); - expect(child2.getComputedLayout().top).toBe(150); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_mutiple_children_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setMarginAuto(Yoga.EDGE_RIGHT); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - - const child2 = Yoga.Node.create(); - child2.setWidth(50); - child2.setHeight(50); - root.insertChild(child2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(75); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(150); - expect(child2.getComputedLayout().top).toBe(75); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(125); - expect(child0.getComputedLayout().top).toBe(75); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(50); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - expect(child2.getComputedLayout().left).toBe(0); - expect(child2.getComputedLayout().top).toBe(75); - expect(child2.getComputedLayout().width).toBe(50); - expect(child2.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_left_and_right_column', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(75); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(75); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_left_and_right', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_start_and_end_column', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_START); - child0.setMarginAuto(Yoga.EDGE_END); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(75); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(75); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(75); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_start_and_end', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_START); - child0.setMarginAuto(Yoga.EDGE_END); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_left_and_right_column_and_center', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(75); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_left', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(150); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(150); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_right', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(50); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_left_and_right_strech', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(50); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(0); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_top_and_bottom_strech', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_TOP); - child0.setMarginAuto(Yoga.EDGE_BOTTOM); - child0.setWidth(50); - child0.setHeight(50); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(50); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(0); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(150); - expect(child0.getComputedLayout().top).toBe(50); - expect(child0.getComputedLayout().width).toBe(50); - expect(child0.getComputedLayout().height).toBe(50); - - expect(child1.getComputedLayout().left).toBe(150); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_should_not_be_part_of_max_height', () => { - const root = Yoga.Node.create(); - root.setWidth(250); - root.setHeight(250); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_TOP, 20); - child0.setWidth(100); - child0.setHeight(100); - child0.setMaxHeight(100); - root.insertChild(child0, 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(250); - expect(root.getComputedLayout().height).toBe(250); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(20); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(250); - expect(root.getComputedLayout().height).toBe(250); - - expect(child0.getComputedLayout().left).toBe(150); - expect(child0.getComputedLayout().top).toBe(20); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - }); - - test('margin_should_not_be_part_of_max_width', () => { - const root = Yoga.Node.create(); - root.setWidth(250); - root.setHeight(250); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_LEFT, 20); - child0.setWidth(100); - child0.setMaxWidth(100); - child0.setHeight(100); - root.insertChild(child0, 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(250); - expect(root.getComputedLayout().height).toBe(250); - - expect(child0.getComputedLayout().left).toBe(20); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(250); - expect(root.getComputedLayout().height).toBe(250); - - expect(child0.getComputedLayout().left).toBe(150); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - }); - - test('margin_auto_left_right_child_bigger_than_parent', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(72); - child0.setHeight(72); - root.insertChild(child0, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(-20); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - }); - - test('margin_auto_left_child_bigger_than_parent', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setWidth(72); - child0.setHeight(72); - root.insertChild(child0, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(-20); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - }); - - test('margin_fix_left_auto_right_child_bigger_than_parent', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child0 = Yoga.Node.create(); - child0.setMargin(Yoga.EDGE_LEFT, 10); - child0.setMarginAuto(Yoga.EDGE_RIGHT); - child0.setWidth(72); - child0.setHeight(72); - root.insertChild(child0, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(10); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(-20); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - }); - - test('margin_auto_left_fix_right_child_bigger_than_parent', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(52); - root.setHeight(52); - - const child0 = Yoga.Node.create(); - child0.setMarginAuto(Yoga.EDGE_LEFT); - child0.setMargin(Yoga.EDGE_RIGHT, 10); - child0.setWidth(72); - child0.setHeight(72); - root.insertChild(child0, 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(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(52); - expect(root.getComputedLayout().height).toBe(52); - - expect(child0.getComputedLayout().left).toBe(-30); - expect(child0.getComputedLayout().top).toBe(-10); - expect(child0.getComputedLayout().width).toBe(72); - expect(child0.getComputedLayout().height).toBe(72); - }); - - test('margin_auto_top_stretching_child', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexShrink(1); - child0.setFlexBasisPercent(0); - child0.setMarginAuto(Yoga.EDGE_TOP); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(150); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(100); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(150); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); - - test('margin_auto_left_stretching_child', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const child0 = Yoga.Node.create(); - child0.setFlexGrow(1); - child0.setFlexShrink(1); - child0.setFlexBasisPercent(0); - child0.setMarginAuto(Yoga.EDGE_LEFT); - root.insertChild(child0, 0); - - const child1 = Yoga.Node.create(); - child1.setWidth(50); - child1.setHeight(50); - root.insertChild(child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(200); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(150); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(child0.getComputedLayout().left).toBe(200); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(0); - expect(child0.getComputedLayout().height).toBe(150); - - expect(child1.getComputedLayout().left).toBe(75); - expect(child1.getComputedLayout().top).toBe(150); - expect(child1.getComputedLayout().width).toBe(50); - expect(child1.getComputedLayout().height).toBe(50); - }); -}); diff --git a/packages/yoga/tests/minMaxDimension.test.js b/packages/yoga/tests/minMaxDimension.test.js deleted file mode 100644 index 3fd862844..000000000 --- a/packages/yoga/tests/minMaxDimension.test.js +++ /dev/null @@ -1,1133 +0,0 @@ -const Yoga = require('..'); - -describe('Min max dimensions', () => { - test('max_width', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setMaxWidth(50); - rootChild0.setHeight(10); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(50); - expect(rootChild0.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(rootChild0.getComputedLayout().left).toBe(50); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(50); - expect(rootChild0.getComputedLayout().height).toBe(10); - }); - - test('max_height', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(10); - rootChild0.setMaxHeight(50); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(50); - - 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(rootChild0.getComputedLayout().left).toBe(90); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(50); - }); - - test('min_height', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setMinHeight(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - root.insertChild(rootChild1, 1); - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(80); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(80); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(20); - - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(80); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(80); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(20); - }); - - test('min_width', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setMinWidth(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - root.insertChild(rootChild1, 1); - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(80); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild1.getComputedLayout().left).toBe(80); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(20); - expect(rootChild1.getComputedLayout().height).toBe(100); - - 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(rootChild0.getComputedLayout().left).toBe(20); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(80); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(20); - expect(rootChild1.getComputedLayout().height).toBe(100); - }); - - test('justify_content_min_max', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setWidth(100); - root.setMinHeight(100); - root.setMaxHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(60); - rootChild0.setHeight(60); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(20); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(60); - - 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(rootChild0.getComputedLayout().left).toBe(40); - expect(rootChild0.getComputedLayout().top).toBe(20); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(60); - }); - - test('align_items_min_max', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setMinWidth(100); - root.setMaxWidth(200); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(60); - rootChild0.setHeight(60); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(20); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(60); - - 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(rootChild0.getComputedLayout().left).toBe(20); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(60); - }); - - test('justify_content_overflow_min_max', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setMinHeight(100); - root.setMaxHeight(110); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(50); - rootChild0.setHeight(50); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setWidth(50); - rootChild1.setHeight(50); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setWidth(50); - rootChild2.setHeight(50); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(50); - expect(root.getComputedLayout().height).toBe(110); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(-20); - expect(rootChild0.getComputedLayout().width).toBe(50); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(30); - expect(rootChild1.getComputedLayout().width).toBe(50); - expect(rootChild1.getComputedLayout().height).toBe(50); - - expect(rootChild2.getComputedLayout().left).toBe(0); - expect(rootChild2.getComputedLayout().top).toBe(80); - expect(rootChild2.getComputedLayout().width).toBe(50); - expect(rootChild2.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(50); - expect(root.getComputedLayout().height).toBe(110); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(-20); - expect(rootChild0.getComputedLayout().width).toBe(50); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(30); - expect(rootChild1.getComputedLayout().width).toBe(50); - expect(rootChild1.getComputedLayout().height).toBe(50); - - expect(rootChild2.getComputedLayout().left).toBe(0); - expect(rootChild2.getComputedLayout().top).toBe(80); - expect(rootChild2.getComputedLayout().width).toBe(50); - expect(rootChild2.getComputedLayout().height).toBe(50); - }); - - test('flex_grow_to_min', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setMinHeight(100); - root.setMaxHeight(500); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexShrink(1); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setHeight(50); - root.insertChild(rootChild1, 1); - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(50); - - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(50); - }); - - test('flex_grow_in_at_most_container', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexGrow(1); - rootChild0Child0.setFlexBasis(0); - rootChild0.insertChild(rootChild0Child0, 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(0); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(0); - expect(rootChild0Child0.getComputedLayout().height).toBe(0); - - 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(rootChild0.getComputedLayout().left).toBe(100); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(0); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(0); - expect(rootChild0Child0.getComputedLayout().height).toBe(0); - }); - - test('flex_grow_child', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(0); - rootChild0.setHeight(100); - root.insertChild(rootChild0, 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(0); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(100); - }); - - test('flex_grow_within_constrained_min_max_column', () => { - const root = Yoga.Node.create(); - root.setMinHeight(100); - root.setMaxHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setHeight(50); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(0); - expect(rootChild1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(0); - expect(rootChild1.getComputedLayout().height).toBe(50); - }); - - test('flex_grow_within_max_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - rootChild0.setMaxWidth(100); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexGrow(1); - rootChild0Child0.setHeight(20); - rootChild0.insertChild(rootChild0Child0, 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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(20); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(100); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(20); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(20); - }); - - test('flex_grow_within_constrained_max_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - rootChild0.setMaxWidth(300); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexGrow(1); - rootChild0Child0.setHeight(20); - rootChild0.insertChild(rootChild0Child0, 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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(20); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(200); - expect(rootChild0Child0.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(20); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(200); - expect(rootChild0Child0.getComputedLayout().height).toBe(20); - }); - - test('flex_root_ignored', () => { - const root = Yoga.Node.create(); - root.setFlexGrow(1); - root.setWidth(100); - root.setMinHeight(100); - root.setMaxHeight(500); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(200); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setHeight(100); - root.insertChild(rootChild1, 1); - 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(300); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(200); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(100); - - 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(300); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(200); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(100); - }); - - test('flex_grow_root_minimized', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setMinHeight(100); - root.setMaxHeight(500); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setMinHeight(100); - rootChild0.setMaxHeight(500); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexGrow(1); - rootChild0Child0.setFlexBasis(200); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child1 = Yoga.Node.create(); - rootChild0Child1.setHeight(100); - rootChild0.insertChild(rootChild0Child1, 1); - 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(300); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(300); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(200); - - expect(rootChild0Child1.getComputedLayout().left).toBe(0); - expect(rootChild0Child1.getComputedLayout().top).toBe(200); - expect(rootChild0Child1.getComputedLayout().width).toBe(100); - expect(rootChild0Child1.getComputedLayout().height).toBe(100); - - 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(300); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(300); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(200); - - expect(rootChild0Child1.getComputedLayout().left).toBe(0); - expect(rootChild0Child1.getComputedLayout().top).toBe(200); - expect(rootChild0Child1.getComputedLayout().width).toBe(100); - expect(rootChild0Child1.getComputedLayout().height).toBe(100); - }); - - test('flex_grow_height_maximized', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(500); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setMinHeight(100); - rootChild0.setMaxHeight(500); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexGrow(1); - rootChild0Child0.setFlexBasis(200); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child1 = Yoga.Node.create(); - rootChild0Child1.setHeight(100); - rootChild0.insertChild(rootChild0Child1, 1); - 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(500); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(500); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(400); - - expect(rootChild0Child1.getComputedLayout().left).toBe(0); - expect(rootChild0Child1.getComputedLayout().top).toBe(400); - expect(rootChild0Child1.getComputedLayout().width).toBe(100); - expect(rootChild0Child1.getComputedLayout().height).toBe(100); - - 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(500); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(500); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(400); - - expect(rootChild0Child1.getComputedLayout().left).toBe(0); - expect(rootChild0Child1.getComputedLayout().top).toBe(400); - expect(rootChild0Child1.getComputedLayout().width).toBe(100); - expect(rootChild0Child1.getComputedLayout().height).toBe(100); - }); - - test('flex_grow_within_constrained_min_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setMinWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setWidth(50); - root.insertChild(rootChild1, 1); - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(50); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild1.getComputedLayout().left).toBe(50); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(50); - expect(rootChild1.getComputedLayout().height).toBe(100); - - 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(rootChild0.getComputedLayout().left).toBe(50); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(50); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(50); - expect(rootChild1.getComputedLayout().height).toBe(100); - }); - - test('flex_grow_within_constrained_min_column', () => { - const root = Yoga.Node.create(); - root.setMinHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setHeight(50); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(0); - expect(rootChild1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(0); - expect(rootChild1.getComputedLayout().height).toBe(50); - }); - - test('flex_grow_within_constrained_max_row', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - rootChild0.setMaxWidth(100); - rootChild0.setHeight(100); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexShrink(1); - rootChild0Child0.setFlexBasis(100); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child1 = Yoga.Node.create(); - rootChild0Child1.setWidth(50); - rootChild0.insertChild(rootChild0Child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(50); - expect(rootChild0Child0.getComputedLayout().height).toBe(100); - - expect(rootChild0Child1.getComputedLayout().left).toBe(50); - expect(rootChild0Child1.getComputedLayout().top).toBe(0); - expect(rootChild0Child1.getComputedLayout().width).toBe(50); - expect(rootChild0Child1.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(100); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild0Child0.getComputedLayout().left).toBe(50); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(50); - expect(rootChild0Child0.getComputedLayout().height).toBe(100); - - expect(rootChild0Child1.getComputedLayout().left).toBe(0); - expect(rootChild0Child1.getComputedLayout().top).toBe(0); - expect(rootChild0Child1.getComputedLayout().width).toBe(50); - expect(rootChild0Child1.getComputedLayout().height).toBe(100); - }); - - test('flex_grow_within_constrained_max_column', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setMaxHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexShrink(1); - rootChild0.setFlexBasis(100); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setHeight(50); - root.insertChild(rootChild1, 1); - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(50); - - 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(100); - expect(rootChild1.getComputedLayout().height).toBe(50); - }); - - test('child_min_max_width_flexing', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(120); - root.setHeight(50); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(0); - rootChild0.setMinWidth(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setFlexBasisPercent(50); - rootChild1.setMaxWidth(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(120); - expect(root.getComputedLayout().height).toBe(50); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(100); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(20); - expect(rootChild1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(120); - expect(root.getComputedLayout().height).toBe(50); - - expect(rootChild0.getComputedLayout().left).toBe(20); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(20); - expect(rootChild1.getComputedLayout().height).toBe(50); - }); - - test('min_width_overrides_width', () => { - const root = Yoga.Node.create(); - root.setWidth(50); - root.setMinWidth(100); - 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(0); - - 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(0); - }); - - test('max_width_overrides_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setMaxWidth(100); - 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(0); - - 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(0); - }); - - test('min_height_overrides_height', () => { - const root = Yoga.Node.create(); - root.setHeight(50); - root.setMinHeight(100); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - }); - - test('max_height_overrides_height', () => { - const root = Yoga.Node.create(); - root.setHeight(200); - root.setMaxHeight(100); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(100); - }); - - test('min_max_percent_no_width_height', () => { - const root = Yoga.Node.create(); - root.setAlignItems(Yoga.ALIGN_FLEX_START); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setMinWidthPercent(10); - rootChild0.setMaxWidthPercent(10); - rootChild0.setMinHeightPercent(10); - rootChild0.setMaxHeightPercent(10); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.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(rootChild0.getComputedLayout().left).toBe(90); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(10); - }); -}); diff --git a/packages/yoga/tests/misc.test.js b/packages/yoga/tests/misc.test.js deleted file mode 100644 index 350c4319a..000000000 --- a/packages/yoga/tests/misc.test.js +++ /dev/null @@ -1,54 +0,0 @@ -const Yoga = require('..'); - -describe('Misc', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - }); - - test('should have same display by default', () => { - expect(yogaNode.getDisplay()).toEqual(flexboxNode.getDisplay()); - }); - - test('should have same overflow by default', () => { - expect(yogaNode.getOverflow()).toEqual(flexboxNode.getOverflow()); - }); - - test('should set display flex', () => { - yogaNode.setDisplay(Yoga.DISPLAY_FLEX); - flexboxNode.setDisplay(Yoga.DISPLAY_FLEX); - - expect(yogaNode.getDisplay()).toEqual(flexboxNode.getDisplay()); - }); - - test('should set display none', () => { - yogaNode.setDisplay(Yoga.DISPLAY_NONE); - flexboxNode.setDisplay(Yoga.DISPLAY_NONE); - - expect(yogaNode.getDisplay()).toEqual(flexboxNode.getDisplay()); - }); - - test('should set overflow visible', () => { - yogaNode.setOverflow(Yoga.OVERFLOW_VISIBLE); - flexboxNode.setOverflow(Yoga.OVERFLOW_VISIBLE); - - expect(yogaNode.getOverflow()).toEqual(flexboxNode.getOverflow()); - }); - - test('should set overflow hidden', () => { - yogaNode.setOverflow(Yoga.OVERFLOW_HIDDEN); - flexboxNode.setOverflow(Yoga.OVERFLOW_HIDDEN); - - expect(yogaNode.getOverflow()).toEqual(flexboxNode.getOverflow()); - }); - - test('should set overflow scroll', () => { - yogaNode.setOverflow(Yoga.OVERFLOW_SCROLL); - flexboxNode.setOverflow(Yoga.OVERFLOW_SCROLL); - - expect(yogaNode.getOverflow()).toEqual(flexboxNode.getOverflow()); - }); -}); diff --git a/packages/yoga/tests/nodeChild.test.js b/packages/yoga/tests/nodeChild.test.js deleted file mode 100644 index 259de5fc0..000000000 --- a/packages/yoga/tests/nodeChild.test.js +++ /dev/null @@ -1,26 +0,0 @@ -const Yoga = require('..'); - -describe('Node child', () => { - test('reset_layout_when_child_removed', () => { - const root = Yoga.Node.create(); - - const child0 = Yoga.Node.create(); - child0.setWidth(100); - child0.setHeight(100); - root.insertChild(child0, 0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBe(100); - expect(child0.getComputedLayout().height).toBe(100); - - root.removeChild(child0); - - expect(child0.getComputedLayout().left).toBe(0); - expect(child0.getComputedLayout().top).toBe(0); - expect(child0.getComputedLayout().width).toBeFalsy(); - expect(child0.getComputedLayout().height).toBeFalsy(); - }); -}); diff --git a/packages/yoga/tests/padding.test.js b/packages/yoga/tests/padding.test.js deleted file mode 100644 index 0d6a056c7..000000000 --- a/packages/yoga/tests/padding.test.js +++ /dev/null @@ -1,429 +0,0 @@ -const Yoga = require('..'); - -describe('Paddings', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - }); - - test('should have same top padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_TOP), - ); - }); - - test('should have same left padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_LEFT), - ); - }); - - test('should have same bottom padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_BOTTOM), - ); - }); - - test('should have same right padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_RIGHT), - ); - }); - - test('should have same vertical padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_VERTICAL), - ); - }); - - test('should have same horizontal padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should have same start padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_START)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_START), - ); - }); - - test('should have same end padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_END)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_END), - ); - }); - - test('should have same all padding by default', () => { - expect(yogaNode.getPadding(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_ALL), - ); - }); - - test('should set top padding', () => { - yogaNode.setPadding(Yoga.EDGE_TOP, 5); - flexboxNode.setPadding(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_TOP), - ); - }); - - test('should set left padding', () => { - yogaNode.setPadding(Yoga.EDGE_LEFT, 5); - flexboxNode.setPadding(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom padding', () => { - yogaNode.setPadding(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setPadding(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right padding', () => { - yogaNode.setPadding(Yoga.EDGE_RIGHT, 5); - flexboxNode.setPadding(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical padding', () => { - yogaNode.setPadding(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setPadding(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal padding', () => { - yogaNode.setPadding(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setPadding(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start padding', () => { - yogaNode.setPadding(Yoga.EDGE_START, 5); - flexboxNode.setPadding(Yoga.EDGE_START, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_START)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_START), - ); - }); - - test('should set end padding', () => { - yogaNode.setPadding(Yoga.EDGE_END, 5); - flexboxNode.setPadding(Yoga.EDGE_END, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_END)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_END), - ); - }); - - test('should set all padding', () => { - yogaNode.setPadding(Yoga.EDGE_ALL, 5); - flexboxNode.setPadding(Yoga.EDGE_ALL, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_ALL), - ); - }); - - test('should set top percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_TOP, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_TOP), - ); - }); - - test('should set left percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_LEFT, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_RIGHT, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_START, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_START, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_START)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_START), - ); - }); - - test('should set end percent padding', () => { - yogaNode.setPaddingPercent(Yoga.EDGE_END, 5); - flexboxNode.setPaddingPercent(Yoga.EDGE_END, 5); - - expect(yogaNode.getPadding(Yoga.EDGE_END)).toEqual( - flexboxNode.getPadding(Yoga.EDGE_END), - ); - }); - - test('padding_no_size', () => { - const root = Yoga.Node.create() - root.setPadding(Yoga.EDGE_LEFT, 10); - root.setPadding(Yoga.EDGE_TOP, 10); - root.setPadding(Yoga.EDGE_RIGHT, 10); - root.setPadding(Yoga.EDGE_BOTTOM, 10); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(20); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(20); - expect(root.getComputedLayout().height).toBe(20); - }); - - test('padding_container_match_child', () => { - const root = Yoga.Node.create() - root.setPadding(Yoga.EDGE_LEFT, 10); - root.setPadding(Yoga.EDGE_TOP, 10); - root.setPadding(Yoga.EDGE_RIGHT, 10); - root.setPadding(Yoga.EDGE_BOTTOM, 10); - - const rootChild0 = Yoga.Node.create() - rootChild0.setWidth(10); - rootChild0.setHeight(10); - root.insertChild(rootChild0, 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(30); - expect(root.getComputedLayout().height).toBe(30); - - expect(rootChild0.getComputedLayout().left).toBe(10); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.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(30); - expect(root.getComputedLayout().height).toBe(30); - - expect(rootChild0.getComputedLayout().left).toBe(10); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(10); - }); - - test('padding_flex_child', () => { - const root = Yoga.Node.create() - root.setPadding(Yoga.EDGE_LEFT, 10); - root.setPadding(Yoga.EDGE_TOP, 10); - root.setPadding(Yoga.EDGE_RIGHT, 10); - root.setPadding(Yoga.EDGE_BOTTOM, 10); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create() - rootChild0.setFlexGrow(1); - rootChild0.setWidth(10); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(10); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(80); - - 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(rootChild0.getComputedLayout().left).toBe(80); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(80); - }); - - test('padding_stretch_child', () => { - const root = Yoga.Node.create() - root.setPadding(Yoga.EDGE_LEFT, 10); - root.setPadding(Yoga.EDGE_TOP, 10); - root.setPadding(Yoga.EDGE_RIGHT, 10); - root.setPadding(Yoga.EDGE_BOTTOM, 10); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create() - rootChild0.setHeight(10); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(10); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(80); - expect(rootChild0.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(rootChild0.getComputedLayout().left).toBe(10); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(80); - expect(rootChild0.getComputedLayout().height).toBe(10); - }); - - test('padding_center_child', () => { - const root = Yoga.Node.create() - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setPadding(Yoga.EDGE_START, 10); - root.setPadding(Yoga.EDGE_END, 20); - root.setPadding(Yoga.EDGE_BOTTOM, 20); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create() - rootChild0.setWidth(10); - rootChild0.setHeight(10); - root.insertChild(rootChild0, 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(rootChild0.getComputedLayout().left).toBe(40); - expect(rootChild0.getComputedLayout().top).toBe(35); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.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(rootChild0.getComputedLayout().left).toBe(50); - expect(rootChild0.getComputedLayout().top).toBe(35); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(10); - }); - - test('child_with_padding_align_end', () => { - const root = Yoga.Node.create() - root.setJustifyContent(Yoga.JUSTIFY_FLEX_END); - root.setAlignItems(Yoga.ALIGN_FLEX_END); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create() - rootChild0.setPadding(Yoga.EDGE_LEFT, 20); - rootChild0.setPadding(Yoga.EDGE_TOP, 20); - rootChild0.setPadding(Yoga.EDGE_RIGHT, 20); - rootChild0.setPadding(Yoga.EDGE_BOTTOM, 20); - rootChild0.setWidth(100); - rootChild0.setHeight(100); - root.insertChild(rootChild0, 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(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(100); - expect(rootChild0.getComputedLayout().top).toBe(100); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(100); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(100); - }); -}); diff --git a/packages/yoga/tests/percentage.test.js b/packages/yoga/tests/percentage.test.js deleted file mode 100644 index 9fea066ba..000000000 --- a/packages/yoga/tests/percentage.test.js +++ /dev/null @@ -1,1066 +0,0 @@ -const Yoga = require('..'); - -describe('Percentage', () => { - test('percentage_width_height', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidthPercent(30); - rootChild0.setHeightPercent(30); - root.insertChild(rootChild0, 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(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(60); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(140); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(60); - }); - - test('percentage_position_left_top', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(400); - root.setHeight(400); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setPositionPercent(Yoga.EDGE_LEFT, 10); - rootChild0.setPositionPercent(Yoga.EDGE_TOP, 20); - rootChild0.setWidthPercent(45); - rootChild0.setHeightPercent(55); - root.insertChild(rootChild0, 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(400); - expect(root.getComputedLayout().height).toBe(400); - - expect(rootChild0.getComputedLayout().left).toBe(40); - expect(rootChild0.getComputedLayout().top).toBe(80); - expect(rootChild0.getComputedLayout().width).toBe(180); - expect(rootChild0.getComputedLayout().height).toBe(220); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(400); - expect(root.getComputedLayout().height).toBe(400); - - expect(rootChild0.getComputedLayout().left).toBe(260); - expect(rootChild0.getComputedLayout().top).toBe(80); - expect(rootChild0.getComputedLayout().width).toBe(180); - expect(rootChild0.getComputedLayout().height).toBe(220); - }); - - test('percentage_position_bottom_right', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(500); - root.setHeight(500); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setPositionPercent(Yoga.EDGE_RIGHT, 20); - rootChild0.setPositionPercent(Yoga.EDGE_BOTTOM, 10); - rootChild0.setWidthPercent(55); - rootChild0.setHeightPercent(15); - root.insertChild(rootChild0, 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(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(rootChild0.getComputedLayout().left).toBe(-100); - expect(rootChild0.getComputedLayout().top).toBe(-50); - expect(rootChild0.getComputedLayout().width).toBe(275); - expect(rootChild0.getComputedLayout().height).toBe(75); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(500); - expect(root.getComputedLayout().height).toBe(500); - - expect(rootChild0.getComputedLayout().left).toBe(125); - expect(rootChild0.getComputedLayout().top).toBe(-50); - expect(rootChild0.getComputedLayout().width).toBe(275); - expect(rootChild0.getComputedLayout().height).toBe(75); - }); - - test('percentage_flex_basis', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(50); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setFlexBasisPercent(25); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(125); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(125); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(75); - expect(rootChild1.getComputedLayout().height).toBe(200); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(75); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(125); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(75); - expect(rootChild1.getComputedLayout().height).toBe(200); - }); - - test('percentage_flex_basis_cross', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(50); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setFlexBasisPercent(25); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(125); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(125); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(75); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(125); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(125); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(75); - }); - - test('percentage_flex_basis_cross_min_height', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setMinHeightPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(2); - rootChild1.setMinHeightPercent(10); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(140); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(140); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(60); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(140); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(140); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(60); - }); - - test('percentage_flex_basis_main_max_height', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(10); - rootChild0.setMaxHeightPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(10); - rootChild1.setMaxHeightPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(52); - expect(rootChild0.getComputedLayout().height).toBe(120); - - expect(rootChild1.getComputedLayout().left).toBe(52); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(148); - expect(rootChild1.getComputedLayout().height).toBe(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(148); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(52); - expect(rootChild0.getComputedLayout().height).toBe(120); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(148); - expect(rootChild1.getComputedLayout().height).toBe(40); - }); - - test('percentage_flex_basis_cross_max_height', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(10); - rootChild0.setMaxHeightPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(10); - rootChild1.setMaxHeightPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(120); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(120); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(40); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(120); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(120); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(40); - }); - - test('percentage_flex_basis_main_max_width', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(15); - rootChild0.setMaxWidthPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(10); - rootChild1.setMaxWidthPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(120); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(120); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(40); - expect(rootChild1.getComputedLayout().height).toBe(200); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(80); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(120); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(40); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(40); - expect(rootChild1.getComputedLayout().height).toBe(200); - }); - - test('percentage_flex_basis_cross_max_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(10); - rootChild0.setMaxWidthPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(15); - rootChild1.setMaxWidthPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(120); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(40); - expect(rootChild1.getComputedLayout().height).toBe(150); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(80); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(120); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(160); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(40); - expect(rootChild1.getComputedLayout().height).toBe(150); - }); - - test('percentage_flex_basis_main_min_width', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(15); - rootChild0.setMinWidthPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(10); - rootChild1.setMinWidthPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(120); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(120); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(80); - expect(rootChild1.getComputedLayout().height).toBe(200); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(80); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(120); - expect(rootChild0.getComputedLayout().height).toBe(200); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(80); - expect(rootChild1.getComputedLayout().height).toBe(200); - }); - - test('percentage_flex_basis_cross_min_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(10); - rootChild0.setMinWidthPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(15); - rootChild1.setMinWidthPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(150); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(50); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(150); - }); - - test('percentage_multiple_nested_with_padding_margin_and_percentage_values', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasisPercent(10); - rootChild0.setMargin(Yoga.EDGE_LEFT, 5); - rootChild0.setMargin(Yoga.EDGE_TOP, 5); - rootChild0.setMargin(Yoga.EDGE_RIGHT, 5); - rootChild0.setMargin(Yoga.EDGE_BOTTOM, 5); - rootChild0.setPadding(Yoga.EDGE_LEFT, 3); - rootChild0.setPadding(Yoga.EDGE_TOP, 3); - rootChild0.setPadding(Yoga.EDGE_RIGHT, 3); - rootChild0.setPadding(Yoga.EDGE_BOTTOM, 3); - rootChild0.setMinWidthPercent(60); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setMargin(Yoga.EDGE_LEFT, 5); - rootChild0Child0.setMargin(Yoga.EDGE_TOP, 5); - rootChild0Child0.setMargin(Yoga.EDGE_RIGHT, 5); - rootChild0Child0.setMargin(Yoga.EDGE_BOTTOM, 5); - rootChild0Child0.setPaddingPercent(Yoga.EDGE_LEFT, 3); - rootChild0Child0.setPaddingPercent(Yoga.EDGE_TOP, 3); - rootChild0Child0.setPaddingPercent(Yoga.EDGE_RIGHT, 3); - rootChild0Child0.setPaddingPercent(Yoga.EDGE_BOTTOM, 3); - rootChild0Child0.setWidthPercent(50); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child0Child0 = Yoga.Node.create(); - rootChild0Child0Child0.setMarginPercent(Yoga.EDGE_LEFT, 5); - rootChild0Child0Child0.setMarginPercent(Yoga.EDGE_TOP, 5); - rootChild0Child0Child0.setMarginPercent(Yoga.EDGE_RIGHT, 5); - rootChild0Child0Child0.setMarginPercent(Yoga.EDGE_BOTTOM, 5); - rootChild0Child0Child0.setPadding(Yoga.EDGE_LEFT, 3); - rootChild0Child0Child0.setPadding(Yoga.EDGE_TOP, 3); - rootChild0Child0Child0.setPadding(Yoga.EDGE_RIGHT, 3); - rootChild0Child0Child0.setPadding(Yoga.EDGE_BOTTOM, 3); - rootChild0Child0Child0.setWidthPercent(45); - rootChild0Child0.insertChild(rootChild0Child0Child0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(4); - rootChild1.setFlexBasisPercent(15); - rootChild1.setMinWidthPercent(20); - root.insertChild(rootChild1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(5); - expect(rootChild0.getComputedLayout().top).toBe(5); - expect(rootChild0.getComputedLayout().width).toBe(190); - expect(rootChild0.getComputedLayout().height).toBe(48); - - expect(rootChild0Child0.getComputedLayout().left).toBe(8); - expect(rootChild0Child0.getComputedLayout().top).toBe(8); - expect(rootChild0Child0.getComputedLayout().width).toBe(92); - expect(rootChild0Child0.getComputedLayout().height).toBe(25); - - expect(rootChild0Child0Child0.getComputedLayout().left).toBe(10); - expect(rootChild0Child0Child0.getComputedLayout().top).toBe(10); - expect(rootChild0Child0Child0.getComputedLayout().width).toBe(36); - expect(rootChild0Child0Child0.getComputedLayout().height).toBe(6); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(58); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(142); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(5); - expect(rootChild0.getComputedLayout().top).toBe(5); - expect(rootChild0.getComputedLayout().width).toBe(190); - expect(rootChild0.getComputedLayout().height).toBe(48); - - expect(rootChild0Child0.getComputedLayout().left).toBe(90); - expect(rootChild0Child0.getComputedLayout().top).toBe(8); - expect(rootChild0Child0.getComputedLayout().width).toBe(92); - expect(rootChild0Child0.getComputedLayout().height).toBe(25); - - expect(rootChild0Child0Child0.getComputedLayout().left).toBe(46); - expect(rootChild0Child0Child0.getComputedLayout().top).toBe(10); - expect(rootChild0Child0Child0.getComputedLayout().width).toBe(36); - expect(rootChild0Child0Child0.getComputedLayout().height).toBe(6); - - expect(rootChild1.getComputedLayout().left).toBe(0); - expect(rootChild1.getComputedLayout().top).toBe(58); - expect(rootChild1.getComputedLayout().width).toBe(200); - expect(rootChild1.getComputedLayout().height).toBe(142); - }); - - test('percentage_margin_should_calculate_based_only_on_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setMarginPercent(Yoga.EDGE_LEFT, 10); - rootChild0.setMarginPercent(Yoga.EDGE_TOP, 10); - rootChild0.setMarginPercent(Yoga.EDGE_RIGHT, 10); - rootChild0.setMarginPercent(Yoga.EDGE_BOTTOM, 10); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setWidth(10); - rootChild0Child0.setHeight(10); - rootChild0.insertChild(rootChild0Child0, 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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(20); - expect(rootChild0.getComputedLayout().top).toBe(20); - expect(rootChild0.getComputedLayout().width).toBe(160); - expect(rootChild0.getComputedLayout().height).toBe(60); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(10); - expect(rootChild0Child0.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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(20); - expect(rootChild0.getComputedLayout().top).toBe(20); - expect(rootChild0.getComputedLayout().width).toBe(160); - expect(rootChild0.getComputedLayout().height).toBe(60); - - expect(rootChild0Child0.getComputedLayout().left).toBe(150); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(10); - expect(rootChild0Child0.getComputedLayout().height).toBe(10); - }); - - test('percentage_padding_should_calculate_based_only_on_width', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setPaddingPercent(Yoga.EDGE_LEFT, 10); - rootChild0.setPaddingPercent(Yoga.EDGE_TOP, 10); - rootChild0.setPaddingPercent(Yoga.EDGE_RIGHT, 10); - rootChild0.setPaddingPercent(Yoga.EDGE_BOTTOM, 10); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setWidth(10); - rootChild0Child0.setHeight(10); - rootChild0.insertChild(rootChild0Child0, 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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild0Child0.getComputedLayout().left).toBe(20); - expect(rootChild0Child0.getComputedLayout().top).toBe(20); - expect(rootChild0Child0.getComputedLayout().width).toBe(10); - expect(rootChild0Child0.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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(200); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild0Child0.getComputedLayout().left).toBe(170); - expect(rootChild0Child0.getComputedLayout().top).toBe(20); - expect(rootChild0Child0.getComputedLayout().width).toBe(10); - expect(rootChild0Child0.getComputedLayout().height).toBe(10); - }); - - test('percentage_absolute_position', () => { - const root = Yoga.Node.create(); - root.setWidth(200); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - rootChild0.setPositionPercent(Yoga.EDGE_LEFT, 30); - rootChild0.setPositionPercent(Yoga.EDGE_TOP, 10); - rootChild0.setWidth(10); - rootChild0.setHeight(10); - root.insertChild(rootChild0, 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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(60); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.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(200); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(60); - expect(rootChild0.getComputedLayout().top).toBe(10); - expect(rootChild0.getComputedLayout().width).toBe(10); - expect(rootChild0.getComputedLayout().height).toBe(10); - }); - - test('percentage_width_height_undefined_parent_size', () => { - const root = Yoga.Node.create(); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidthPercent(50); - rootChild0.setHeightPercent(50); - root.insertChild(rootChild0, 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(0); - expect(root.getComputedLayout().height).toBe(0); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(0); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(0); - expect(root.getComputedLayout().height).toBe(0); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(0); - expect(rootChild0.getComputedLayout().height).toBe(0); - }); - - test('percent_within_flex_grow', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(350); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(100); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - root.insertChild(rootChild1, 1); - - const rootChild1Child0 = Yoga.Node.create(); - rootChild1Child0.setWidthPercent(100); - rootChild1.insertChild(rootChild1Child0, 0); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setWidth(100); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(350); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(0); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild1.getComputedLayout().left).toBe(100); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(150); - expect(rootChild1.getComputedLayout().height).toBe(100); - - expect(rootChild1Child0.getComputedLayout().left).toBe(0); - expect(rootChild1Child0.getComputedLayout().top).toBe(0); - expect(rootChild1Child0.getComputedLayout().width).toBe(150); - expect(rootChild1Child0.getComputedLayout().height).toBe(0); - - expect(rootChild2.getComputedLayout().left).toBe(250); - expect(rootChild2.getComputedLayout().top).toBe(0); - expect(rootChild2.getComputedLayout().width).toBe(100); - expect(rootChild2.getComputedLayout().height).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(350); - expect(root.getComputedLayout().height).toBe(100); - - expect(rootChild0.getComputedLayout().left).toBe(250); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(100); - - expect(rootChild1.getComputedLayout().left).toBe(100); - expect(rootChild1.getComputedLayout().top).toBe(0); - expect(rootChild1.getComputedLayout().width).toBe(150); - expect(rootChild1.getComputedLayout().height).toBe(100); - - expect(rootChild1Child0.getComputedLayout().left).toBe(0); - expect(rootChild1Child0.getComputedLayout().top).toBe(0); - expect(rootChild1Child0.getComputedLayout().width).toBe(150); - expect(rootChild1Child0.getComputedLayout().height).toBe(0); - - expect(rootChild2.getComputedLayout().left).toBe(0); - expect(rootChild2.getComputedLayout().top).toBe(0); - expect(rootChild2.getComputedLayout().width).toBe(100); - expect(rootChild2.getComputedLayout().height).toBe(100); - }); - - test('percentage_container_in_wrapping_container', () => { - const root = Yoga.Node.create(); - root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setAlignItems(Yoga.ALIGN_CENTER); - root.setWidth(200); - root.setHeight(200); - - const rootChild0 = Yoga.Node.create(); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - rootChild0Child0.setJustifyContent(Yoga.JUSTIFY_CENTER); - rootChild0Child0.setWidthPercent(100); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child0Child0 = Yoga.Node.create(); - rootChild0Child0Child0.setWidth(50); - rootChild0Child0Child0.setHeight(50); - rootChild0Child0.insertChild(rootChild0Child0Child0, 0); - - const rootChild0Child0Child1 = Yoga.Node.create(); - rootChild0Child0Child1.setWidth(50); - rootChild0Child0Child1.setHeight(50); - rootChild0Child0.insertChild(rootChild0Child0Child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(50); - expect(rootChild0.getComputedLayout().top).toBe(75); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0Child0.getComputedLayout().width).toBe(50); - expect(rootChild0Child0Child0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0Child1.getComputedLayout().left).toBe(50); - expect(rootChild0Child0Child1.getComputedLayout().top).toBe(0); - expect(rootChild0Child0Child1.getComputedLayout().width).toBe(50); - expect(rootChild0Child0Child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(200); - expect(root.getComputedLayout().height).toBe(200); - - expect(rootChild0.getComputedLayout().left).toBe(50); - expect(rootChild0.getComputedLayout().top).toBe(75); - expect(rootChild0.getComputedLayout().width).toBe(100); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(100); - expect(rootChild0Child0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0Child0.getComputedLayout().left).toBe(50); - expect(rootChild0Child0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0Child0.getComputedLayout().width).toBe(50); - expect(rootChild0Child0Child0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0Child1.getComputedLayout().left).toBe(0); - expect(rootChild0Child0Child1.getComputedLayout().top).toBe(0); - expect(rootChild0Child0Child1.getComputedLayout().width).toBe(50); - expect(rootChild0Child0Child1.getComputedLayout().height).toBe(50); - }); - - test('percent_absolute_position', () => { - const root = Yoga.Node.create(); - root.setWidth(60); - root.setHeight(50); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - rootChild0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - rootChild0.setPositionPercent(Yoga.EDGE_LEFT, 50); - rootChild0.setWidthPercent(100); - rootChild0.setHeight(50); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setWidthPercent(100); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child1 = Yoga.Node.create(); - rootChild0Child1.setWidthPercent(100); - rootChild0.insertChild(rootChild0Child1, 1); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(60); - expect(root.getComputedLayout().height).toBe(50); - - expect(rootChild0.getComputedLayout().left).toBe(30); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(60); - expect(rootChild0Child0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child1.getComputedLayout().left).toBe(60); - expect(rootChild0Child1.getComputedLayout().top).toBe(0); - expect(rootChild0Child1.getComputedLayout().width).toBe(60); - expect(rootChild0Child1.getComputedLayout().height).toBe(50); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLayout().left).toBe(0); - expect(root.getComputedLayout().top).toBe(0); - expect(root.getComputedLayout().width).toBe(60); - expect(root.getComputedLayout().height).toBe(50); - - expect(rootChild0.getComputedLayout().left).toBe(30); - expect(rootChild0.getComputedLayout().top).toBe(0); - expect(rootChild0.getComputedLayout().width).toBe(60); - expect(rootChild0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child0.getComputedLayout().left).toBe(0); - expect(rootChild0Child0.getComputedLayout().top).toBe(0); - expect(rootChild0Child0.getComputedLayout().width).toBe(60); - expect(rootChild0Child0.getComputedLayout().height).toBe(50); - - expect(rootChild0Child1.getComputedLayout().left).toBe(-60); - expect(rootChild0Child1.getComputedLayout().top).toBe(0); - expect(rootChild0Child1.getComputedLayout().width).toBe(60); - expect(rootChild0Child1.getComputedLayout().height).toBe(50); - }); -}); diff --git a/packages/yoga/tests/position.test.js b/packages/yoga/tests/position.test.js deleted file mode 100644 index 2b7865575..000000000 --- a/packages/yoga/tests/position.test.js +++ /dev/null @@ -1,232 +0,0 @@ -const Yoga = require('..'); - -describe('Position', () => { - let yogaNode; - let flexboxNode; - - beforeEach(() => { - yogaNode = Yoga.Node.createDefault(); - flexboxNode = Yoga.Node.createDefault(); - }); - - test('should have same top position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_TOP), - ); - }); - - test('should have same left position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_LEFT), - ); - }); - - test('should have same bottom position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_BOTTOM), - ); - }); - - test('should have same right position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_RIGHT), - ); - }); - - test('should have same vertical position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_VERTICAL), - ); - }); - - test('should have same horizontal position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should have same start position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_START)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_START), - ); - }); - - test('should have same end position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_END)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_END), - ); - }); - - test('should have same all position by default', () => { - expect(yogaNode.getPosition(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_ALL), - ); - }); - - test('should set top position', () => { - yogaNode.setPosition(Yoga.EDGE_TOP, 5); - flexboxNode.setPosition(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_TOP), - ); - }); - - test('should set left position', () => { - yogaNode.setPosition(Yoga.EDGE_LEFT, 5); - flexboxNode.setPosition(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom position', () => { - yogaNode.setPosition(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setPosition(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right position', () => { - yogaNode.setPosition(Yoga.EDGE_RIGHT, 5); - flexboxNode.setPosition(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical position', () => { - yogaNode.setPosition(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setPosition(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal position', () => { - yogaNode.setPosition(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setPosition(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start position', () => { - yogaNode.setPosition(Yoga.EDGE_START, 5); - flexboxNode.setPosition(Yoga.EDGE_START, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_START)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_START), - ); - }); - - test('should set end position', () => { - yogaNode.setPosition(Yoga.EDGE_END, 5); - flexboxNode.setPosition(Yoga.EDGE_END, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_END)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_END), - ); - }); - - test('should set all position', () => { - yogaNode.setPosition(Yoga.EDGE_ALL, 5); - flexboxNode.setPosition(Yoga.EDGE_ALL, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_ALL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_ALL), - ); - }); - - test('should set top percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_TOP, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_TOP, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_TOP)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_TOP), - ); - }); - - test('should set left percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_LEFT, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_LEFT, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_LEFT)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_LEFT), - ); - }); - - test('should set bottom percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_BOTTOM, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_BOTTOM, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_BOTTOM)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_BOTTOM), - ); - }); - - test('should set right percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_RIGHT, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_RIGHT, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_RIGHT)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_RIGHT), - ); - }); - - test('should set vertical percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_VERTICAL, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_VERTICAL, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_VERTICAL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_VERTICAL), - ); - }); - - test('should set horizontal percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_HORIZONTAL, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_HORIZONTAL, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_HORIZONTAL)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_HORIZONTAL), - ); - }); - - test('should set start percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_START, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_START, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_START)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_START), - ); - }); - - test('should set end percent position', () => { - yogaNode.setPositionPercent(Yoga.EDGE_END, 5); - flexboxNode.setPositionPercent(Yoga.EDGE_END, 5); - - expect(yogaNode.getPosition(Yoga.EDGE_END)).toEqual( - flexboxNode.getPosition(Yoga.EDGE_END), - ); - }); - - test('should set position type relative', () => { - yogaNode.setPositionType(Yoga.POSITION_TYPE_RELATIVE); - flexboxNode.setPositionType(Yoga.POSITION_TYPE_RELATIVE); - - expect(yogaNode.getPositionType()).toEqual(flexboxNode.getPositionType()); - }); - - test('should set position type absolute', () => { - yogaNode.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - flexboxNode.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); - - expect(yogaNode.getPositionType()).toEqual(flexboxNode.getPositionType()); - }); -}); diff --git a/packages/yoga/tests/rounding.test.js b/packages/yoga/tests/rounding.test.js deleted file mode 100644 index cfec297ea..000000000 --- a/packages/yoga/tests/rounding.test.js +++ /dev/null @@ -1,991 +0,0 @@ -const Yoga = require('..'); - -describe('Rounding', () => { - test('rounding_flex_basis_flex_grow_row_width_of_100', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(33); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild1.getComputedLeft()).toBe(33); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(34); - expect(rootChild1.getComputedHeight()).toBe(100); - - expect(rootChild2.getComputedLeft()).toBe(67); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(33); - expect(rootChild2.getComputedHeight()).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(67); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(33); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild1.getComputedLeft()).toBe(33); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(34); - expect(rootChild1.getComputedHeight()).toBe(100); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(33); - expect(rootChild2.getComputedHeight()).toBe(100); - }); - - test('rounding_flex_basis_flex_grow_row_prime_number_width', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(113); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - root.insertChild(rootChild2, 2); - - const rootChild3 = Yoga.Node.create(); - rootChild3.setFlexGrow(1); - root.insertChild(rootChild3, 3); - - const rootChild4 = Yoga.Node.create(); - rootChild4.setFlexGrow(1); - root.insertChild(rootChild4, 4); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(113); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(23); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild1.getComputedLeft()).toBe(23); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(22); - expect(rootChild1.getComputedHeight()).toBe(100); - - expect(rootChild2.getComputedLeft()).toBe(45); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(23); - expect(rootChild2.getComputedHeight()).toBe(100); - - expect(rootChild3.getComputedLeft()).toBe(68); - expect(rootChild3.getComputedTop()).toBe(0); - expect(rootChild3.getComputedWidth()).toBe(22); - expect(rootChild3.getComputedHeight()).toBe(100); - - expect(rootChild4.getComputedLeft()).toBe(90); - expect(rootChild4.getComputedTop()).toBe(0); - expect(rootChild4.getComputedWidth()).toBe(23); - expect(rootChild4.getComputedHeight()).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(113); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(90); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(23); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild1.getComputedLeft()).toBe(68); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(22); - expect(rootChild1.getComputedHeight()).toBe(100); - - expect(rootChild2.getComputedLeft()).toBe(45); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(23); - expect(rootChild2.getComputedHeight()).toBe(100); - - expect(rootChild3.getComputedLeft()).toBe(23); - expect(rootChild3.getComputedTop()).toBe(0); - expect(rootChild3.getComputedWidth()).toBe(22); - expect(rootChild3.getComputedHeight()).toBe(100); - - expect(rootChild4.getComputedLeft()).toBe(0); - expect(rootChild4.getComputedTop()).toBe(0); - expect(rootChild4.getComputedWidth()).toBe(23); - expect(rootChild4.getComputedHeight()).toBe(100); - }); - - test('rounding_flex_basis_flex_shrink_row', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(101); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexShrink(1); - rootChild0.setFlexBasis(100); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexBasis(25); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexBasis(25); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(101); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(51); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild1.getComputedLeft()).toBe(51); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(25); - expect(rootChild1.getComputedHeight()).toBe(100); - - expect(rootChild2.getComputedLeft()).toBe(76); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(25); - expect(rootChild2.getComputedHeight()).toBe(100); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(101); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(50); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(51); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild1.getComputedLeft()).toBe(25); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(25); - expect(rootChild1.getComputedHeight()).toBe(100); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(25); - expect(rootChild2.getComputedHeight()).toBe(100); - }); - - test('rounding_flex_basis_overrides_main_size', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(113); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(50); - rootChild0.setHeight(20); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeight(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(64); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(25); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(24); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(64); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(25); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(24); - }); - - test('rounding_total_fractial', () => { - const root = Yoga.Node.create(); - root.setWidth(87.4); - root.setHeight(113.4); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(0.7); - rootChild0.setFlexBasis(50.3); - rootChild0.setHeight(20.3); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1.6); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1.1); - rootChild2.setHeight(10.7); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(87); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(87); - expect(rootChild0.getComputedHeight()).toBe(59); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(59); - expect(rootChild1.getComputedWidth()).toBe(87); - expect(rootChild1.getComputedHeight()).toBe(30); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(87); - expect(rootChild2.getComputedHeight()).toBe(24); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(87); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(87); - expect(rootChild0.getComputedHeight()).toBe(59); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(59); - expect(rootChild1.getComputedWidth()).toBe(87); - expect(rootChild1.getComputedHeight()).toBe(30); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(87); - expect(rootChild2.getComputedHeight()).toBe(24); - }); - - test('rounding_total_fractial_nested', () => { - const root = Yoga.Node.create(); - root.setWidth(87.4); - root.setHeight(113.4); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(0.7); - rootChild0.setFlexBasis(50.3); - rootChild0.setHeight(20.3); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setFlexGrow(1); - rootChild0Child0.setFlexBasis(0.3); - rootChild0Child0.setPosition(Yoga.EDGE_BOTTOM, 13.3); - rootChild0Child0.setHeight(9.9); - rootChild0.insertChild(rootChild0Child0, 0); - - const rootChild0Child1 = Yoga.Node.create(); - rootChild0Child1.setFlexGrow(4); - rootChild0Child1.setFlexBasis(0.3); - rootChild0Child1.setPosition(Yoga.EDGE_TOP, 13.3); - rootChild0Child1.setHeight(1.1); - rootChild0.insertChild(rootChild0Child1, 1); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1.6); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1.1); - rootChild2.setHeight(10.7); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(87); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(87); - expect(rootChild0.getComputedHeight()).toBe(59); - - expect(rootChild0Child0.getComputedLeft()).toBe(0); - expect(rootChild0Child0.getComputedTop()).toBe(-13); - expect(rootChild0Child0.getComputedWidth()).toBe(87); - expect(rootChild0Child0.getComputedHeight()).toBe(12); - - expect(rootChild0Child1.getComputedLeft()).toBe(0); - expect(rootChild0Child1.getComputedTop()).toBe(25); - expect(rootChild0Child1.getComputedWidth()).toBe(87); - expect(rootChild0Child1.getComputedHeight()).toBe(47); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(59); - expect(rootChild1.getComputedWidth()).toBe(87); - expect(rootChild1.getComputedHeight()).toBe(30); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(87); - expect(rootChild2.getComputedHeight()).toBe(24); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(87); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(87); - expect(rootChild0.getComputedHeight()).toBe(59); - - expect(rootChild0Child0.getComputedLeft()).toBe(0); - expect(rootChild0Child0.getComputedTop()).toBe(-13); - expect(rootChild0Child0.getComputedWidth()).toBe(87); - expect(rootChild0Child0.getComputedHeight()).toBe(12); - - expect(rootChild0Child1.getComputedLeft()).toBe(0); - expect(rootChild0Child1.getComputedTop()).toBe(25); - expect(rootChild0Child1.getComputedWidth()).toBe(87); - expect(rootChild0Child1.getComputedHeight()).toBe(47); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(59); - expect(rootChild1.getComputedWidth()).toBe(87); - expect(rootChild1.getComputedHeight()).toBe(30); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(87); - expect(rootChild2.getComputedHeight()).toBe(24); - }); - - test('rounding_fractial_input_1', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(113.4); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(50); - rootChild0.setHeight(20); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeight(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(64); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(25); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(24); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(64); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(25); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(24); - }); - - test('rounding_fractial_input_2', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(113.6); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(50); - rootChild0.setHeight(20); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeight(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(114); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(65); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(65); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(24); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(25); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(114); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(65); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(65); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(24); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(25); - }); - - test('rounding_fractial_input_3', () => { - const root = Yoga.Node.create(); - root.setPosition(Yoga.EDGE_TOP, 0.3); - root.setWidth(100); - root.setHeight(113.4); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(50); - rootChild0.setHeight(20); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeight(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(114); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(65); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(24); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(25); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(114); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(65); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(24); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(25); - }); - - test('rounding_fractial_input_4', () => { - const root = Yoga.Node.create(); - root.setPosition(Yoga.EDGE_TOP, 0.7); - root.setWidth(100); - root.setHeight(113.4); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setFlexBasis(50); - rootChild0.setHeight(20); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeight(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(1); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(64); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(25); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(24); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(1); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(113); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(64); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(64); - expect(rootChild1.getComputedWidth()).toBe(100); - expect(rootChild1.getComputedHeight()).toBe(25); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(89); - expect(rootChild2.getComputedWidth()).toBe(100); - expect(rootChild2.getComputedHeight()).toBe(24); - }); - - test('rounding_inner_node_controversy_horizontal', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(320); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setHeight(10); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeight(10); - root.insertChild(rootChild1, 1); - - const rootChild1Child0 = Yoga.Node.create(); - rootChild1Child0.setFlexGrow(1); - rootChild1Child0.setHeight(10); - rootChild1.insertChild(rootChild1Child0, 0); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeight(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(320); - expect(root.getComputedHeight()).toBe(10); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(107); - expect(rootChild0.getComputedHeight()).toBe(10); - - expect(rootChild1.getComputedLeft()).toBe(107); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(106); - expect(rootChild1.getComputedHeight()).toBe(10); - - expect(rootChild1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child0.getComputedWidth()).toBe(106); - expect(rootChild1Child0.getComputedHeight()).toBe(10); - - expect(rootChild2.getComputedLeft()).toBe(213); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(107); - expect(rootChild2.getComputedHeight()).toBe(10); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(320); - expect(root.getComputedHeight()).toBe(10); - - expect(rootChild0.getComputedLeft()).toBe(213); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(107); - expect(rootChild0.getComputedHeight()).toBe(10); - - expect(rootChild1.getComputedLeft()).toBe(107); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(106); - expect(rootChild1.getComputedHeight()).toBe(10); - - expect(rootChild1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child0.getComputedWidth()).toBe(106); - expect(rootChild1Child0.getComputedHeight()).toBe(10); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(107); - expect(rootChild2.getComputedHeight()).toBe(10); - }); - - test('rounding_inner_node_controversy_vertical', () => { - const root = Yoga.Node.create(); - root.setHeight(320); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setWidth(10); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setWidth(10); - root.insertChild(rootChild1, 1); - - const rootChild1Child0 = Yoga.Node.create(); - rootChild1Child0.setFlexGrow(1); - rootChild1Child0.setWidth(10); - rootChild1.insertChild(rootChild1Child0, 0); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setWidth(10); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(10); - expect(root.getComputedHeight()).toBe(320); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(10); - expect(rootChild0.getComputedHeight()).toBe(107); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(107); - expect(rootChild1.getComputedWidth()).toBe(10); - expect(rootChild1.getComputedHeight()).toBe(106); - - expect(rootChild1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child0.getComputedWidth()).toBe(10); - expect(rootChild1Child0.getComputedHeight()).toBe(106); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(213); - expect(rootChild2.getComputedWidth()).toBe(10); - expect(rootChild2.getComputedHeight()).toBe(107); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(10); - expect(root.getComputedHeight()).toBe(320); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(10); - expect(rootChild0.getComputedHeight()).toBe(107); - - expect(rootChild1.getComputedLeft()).toBe(0); - expect(rootChild1.getComputedTop()).toBe(107); - expect(rootChild1.getComputedWidth()).toBe(10); - expect(rootChild1.getComputedHeight()).toBe(106); - - expect(rootChild1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child0.getComputedWidth()).toBe(10); - expect(rootChild1Child0.getComputedHeight()).toBe(106); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(213); - expect(rootChild2.getComputedWidth()).toBe(10); - expect(rootChild2.getComputedHeight()).toBe(107); - }); - - test('rounding_inner_node_controversy_combined', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(640); - root.setHeight(320); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setFlexGrow(1); - rootChild0.setHeightPercent(100); - root.insertChild(rootChild0, 0); - - const rootChild1 = Yoga.Node.create(); - rootChild1.setFlexGrow(1); - rootChild1.setHeightPercent(100); - root.insertChild(rootChild1, 1); - - const rootChild1Child0 = Yoga.Node.create(); - rootChild1Child0.setFlexGrow(1); - rootChild1Child0.setWidthPercent(100); - rootChild1.insertChild(rootChild1Child0, 0); - - const rootChild1Child1 = Yoga.Node.create(); - rootChild1Child1.setFlexGrow(1); - rootChild1Child1.setWidthPercent(100); - rootChild1.insertChild(rootChild1Child1, 1); - - const rootChild1Child1Child0 = Yoga.Node.create(); - rootChild1Child1Child0.setFlexGrow(1); - rootChild1Child1Child0.setWidthPercent(100); - rootChild1Child1.insertChild(rootChild1Child1Child0, 0); - - const rootChild1Child2 = Yoga.Node.create(); - rootChild1Child2.setFlexGrow(1); - rootChild1Child2.setWidthPercent(100); - rootChild1.insertChild(rootChild1Child2, 2); - - const rootChild2 = Yoga.Node.create(); - rootChild2.setFlexGrow(1); - rootChild2.setHeightPercent(100); - root.insertChild(rootChild2, 2); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(640); - expect(root.getComputedHeight()).toBe(320); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(213); - expect(rootChild0.getComputedHeight()).toBe(320); - - expect(rootChild1.getComputedLeft()).toBe(213); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(214); - expect(rootChild1.getComputedHeight()).toBe(320); - - expect(rootChild1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child0.getComputedWidth()).toBe(214); - expect(rootChild1Child0.getComputedHeight()).toBe(107); - - expect(rootChild1Child1.getComputedLeft()).toBe(0); - expect(rootChild1Child1.getComputedTop()).toBe(107); - expect(rootChild1Child1.getComputedWidth()).toBe(214); - expect(rootChild1Child1.getComputedHeight()).toBe(106); - - expect(rootChild1Child1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child1Child0.getComputedWidth()).toBe(214); - expect(rootChild1Child1Child0.getComputedHeight()).toBe(106); - - expect(rootChild1Child2.getComputedLeft()).toBe(0); - expect(rootChild1Child2.getComputedTop()).toBe(213); - expect(rootChild1Child2.getComputedWidth()).toBe(214); - expect(rootChild1Child2.getComputedHeight()).toBe(107); - - expect(rootChild2.getComputedLeft()).toBe(427); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(213); - expect(rootChild2.getComputedHeight()).toBe(320); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(640); - expect(root.getComputedHeight()).toBe(320); - - expect(rootChild0.getComputedLeft()).toBe(427); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(213); - expect(rootChild0.getComputedHeight()).toBe(320); - - expect(rootChild1.getComputedLeft()).toBe(213); - expect(rootChild1.getComputedTop()).toBe(0); - expect(rootChild1.getComputedWidth()).toBe(214); - expect(rootChild1.getComputedHeight()).toBe(320); - - expect(rootChild1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child0.getComputedWidth()).toBe(214); - expect(rootChild1Child0.getComputedHeight()).toBe(107); - - expect(rootChild1Child1.getComputedLeft()).toBe(0); - expect(rootChild1Child1.getComputedTop()).toBe(107); - expect(rootChild1Child1.getComputedWidth()).toBe(214); - expect(rootChild1Child1.getComputedHeight()).toBe(106); - - expect(rootChild1Child1Child0.getComputedLeft()).toBe(0); - expect(rootChild1Child1Child0.getComputedTop()).toBe(0); - expect(rootChild1Child1Child0.getComputedWidth()).toBe(214); - expect(rootChild1Child1Child0.getComputedHeight()).toBe(106); - - expect(rootChild1Child2.getComputedLeft()).toBe(0); - expect(rootChild1Child2.getComputedTop()).toBe(213); - expect(rootChild1Child2.getComputedWidth()).toBe(214); - expect(rootChild1Child2.getComputedHeight()).toBe(107); - - expect(rootChild2.getComputedLeft()).toBe(0); - expect(rootChild2.getComputedTop()).toBe(0); - expect(rootChild2.getComputedWidth()).toBe(213); - expect(rootChild2.getComputedHeight()).toBe(320); - }); -}); diff --git a/packages/yoga/tests/sizeOverflow.test.js b/packages/yoga/tests/sizeOverflow.test.js deleted file mode 100644 index 42009bd78..000000000 --- a/packages/yoga/tests/sizeOverflow.test.js +++ /dev/null @@ -1,147 +0,0 @@ -const Yoga = require('..'); - -describe('Size overflow', () => { - test('nested_overflowing_child', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setWidth(200); - rootChild0Child0.setHeight(200); - rootChild0.insertChild(rootChild0Child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(200); - - expect(rootChild0Child0.getComputedLeft()).toBe(0); - expect(rootChild0Child0.getComputedTop()).toBe(0); - expect(rootChild0Child0.getComputedWidth()).toBe(200); - expect(rootChild0Child0.getComputedHeight()).toBe(200); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(200); - - expect(rootChild0Child0.getComputedLeft()).toBe(-100); - expect(rootChild0Child0.getComputedTop()).toBe(0); - expect(rootChild0Child0.getComputedWidth()).toBe(200); - expect(rootChild0Child0.getComputedHeight()).toBe(200); - }); - - test('nested_overflowing_child_in_constraint_parent', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(100); - rootChild0.setHeight(100); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setWidth(200); - rootChild0Child0.setHeight(200); - rootChild0.insertChild(rootChild0Child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild0Child0.getComputedLeft()).toBe(0); - expect(rootChild0Child0.getComputedTop()).toBe(0); - expect(rootChild0Child0.getComputedWidth()).toBe(200); - expect(rootChild0Child0.getComputedHeight()).toBe(200); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(100); - - expect(rootChild0Child0.getComputedLeft()).toBe(-100); - expect(rootChild0Child0.getComputedTop()).toBe(0); - expect(rootChild0Child0.getComputedWidth()).toBe(200); - expect(rootChild0Child0.getComputedHeight()).toBe(200); - }); - - test('parent_wrap_child_size_overflowing_parent', () => { - const root = Yoga.Node.create(); - root.setWidth(100); - root.setHeight(100); - - const rootChild0 = Yoga.Node.create(); - rootChild0.setWidth(100); - root.insertChild(rootChild0, 0); - - const rootChild0Child0 = Yoga.Node.create(); - rootChild0Child0.setWidth(100); - rootChild0Child0.setHeight(200); - rootChild0.insertChild(rootChild0Child0, 0); - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(200); - - expect(rootChild0Child0.getComputedLeft()).toBe(0); - expect(rootChild0Child0.getComputedTop()).toBe(0); - expect(rootChild0Child0.getComputedWidth()).toBe(100); - expect(rootChild0Child0.getComputedHeight()).toBe(200); - - root.calculateLayout(undefined, undefined, Yoga.DIRECTION_RTL); - - expect(root.getComputedLeft()).toBe(0); - expect(root.getComputedTop()).toBe(0); - expect(root.getComputedWidth()).toBe(100); - expect(root.getComputedHeight()).toBe(100); - - expect(rootChild0.getComputedLeft()).toBe(0); - expect(rootChild0.getComputedTop()).toBe(0); - expect(rootChild0.getComputedWidth()).toBe(100); - expect(rootChild0.getComputedHeight()).toBe(200); - - expect(rootChild0Child0.getComputedLeft()).toBe(0); - expect(rootChild0Child0.getComputedTop()).toBe(0); - expect(rootChild0Child0.getComputedWidth()).toBe(100); - expect(rootChild0Child0.getComputedHeight()).toBe(200); - }); -}); diff --git a/packages/yoga/tests/zeroOutLayoutRecursivly.test.js b/packages/yoga/tests/zeroOutLayoutRecursivly.test.js deleted file mode 100644 index c794a8a16..000000000 --- a/packages/yoga/tests/zeroOutLayoutRecursivly.test.js +++ /dev/null @@ -1,29 +0,0 @@ -const Yoga = require('..'); - -describe('Zero out layout recursivly', () => { - test('zero_out_layout', () => { - const root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setWidth(200); - root.setHeight(200); - - const child = Yoga.Node.create(); - root.insertChild(child, 0); - child.setWidth(100); - child.setHeight(100); - child.setMargin(Yoga.EDGE_TOP, 10); - child.setPadding(Yoga.EDGE_TOP, 10); - - root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); - - expect(child.getComputedMargin(Yoga.EDGE_TOP)).toBe(10); - expect(child.getComputedPadding(Yoga.EDGE_TOP)).toBe(10); - - child.setDisplay(Yoga.DISPLAY_NONE); - - root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); - - expect(child.getComputedMargin(Yoga.EDGE_TOP)).toBe(0); - expect(child.getComputedPadding(Yoga.EDGE_TOP)).toBe(0); - }); -}); diff --git a/yarn.lock b/yarn.lock index 21557f88b..34f721003 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10384,7 +10384,7 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -yoga-wasm-web@~0.3.2: - version "0.3.2" - resolved "https://registry.yarnpkg.com/yoga-wasm-web/-/yoga-wasm-web-0.3.2.tgz#8f3bb23ca959d92d86047d209853737eb99c7dda" - integrity sha512-X//8P6RHzkO4E1ba/wXwKOybeArNDQJI2vwzFLJxz5bfT9K8fB798ZVYvq+Z+hjRA0Wy2iUlOUch4n2+ddqbDQ== +yoga-layout@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/yoga-layout/-/yoga-layout-2.0.1.tgz#4bc686abe2464f977866650ddccc1dbcf9f0d03c" + integrity sha512-tT/oChyDXelLo2A+UVnlW9GU7CsvFMaEnd9kVFsaiCQonFAXd3xrHhkLYu+suwwosrAEQ746xBU+HvYtm1Zs2Q==