Skip to content

Commit 3e3ad5a

Browse files
feat: Added test coverage for getBoundingRect; Added drawbacks to getBoundingRect
1 parent 8a98af4 commit 3e3ad5a

File tree

3 files changed

+65
-11860
lines changed

3 files changed

+65
-11860
lines changed

__tests__/getBoundingRect.test.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { set } from 'lodash'
2+
import { createFigma } from 'figma-api-stub'
3+
import { getBoundingRect } from '../src'
4+
5+
const figma = createFigma({})
6+
const pageNode = figma.createPage()
7+
const frameNode1 = figma.createFrame()
8+
const frameNode2 = figma.createFrame()
9+
pageNode.appendChild(frameNode1)
10+
pageNode.appendChild(frameNode2)
11+
12+
describe('getRelativePosition negative tests', () => {
13+
test("shouldn't fail if node haven't required properties", () => {
14+
expect(getBoundingRect([frameNode1, frameNode2])).toEqual({
15+
height: -Infinity,
16+
width: -Infinity,
17+
x: Infinity,
18+
x2: -Infinity,
19+
y: Infinity,
20+
y2: -Infinity
21+
})
22+
})
23+
})
24+
25+
describe('getRelativePosition positive tests', () => {
26+
beforeEach(() => {
27+
set(frameNode1, 'absoluteTransform', [
28+
[0, 0, 0],
29+
[0, 0, 0]
30+
])
31+
set(frameNode1, 'height', 100)
32+
set(frameNode1, 'width', 100)
33+
set(frameNode2, 'absoluteTransform', [
34+
[0, 0, 10],
35+
[0, 0, 20]
36+
])
37+
set(frameNode2, 'height', 200)
38+
set(frameNode2, 'width', 200)
39+
})
40+
41+
test("shouldn't fail if node have all required properties", () => {
42+
expect(getBoundingRect([frameNode1, frameNode2])).toEqual({
43+
height: 20,
44+
width: 10,
45+
x: 0,
46+
x2: 10,
47+
y: 0,
48+
y2: 20
49+
})
50+
})
51+
})

0 commit comments

Comments
 (0)