1
0
Fork 0

[vercel skip] chore (core) document and test Stack.home

This commit is contained in:
Enoch Riese 2023-04-14 23:49:45 -04:00
parent 444d82c527
commit 042d4e71a9
2 changed files with 58 additions and 14 deletions

View file

@ -1,5 +1,6 @@
import chai from 'chai'
import { Design } from '../src/index.mjs'
import { Design, Point, Attributes } from '../src/index.mjs'
import { Stack } from '../src/stack.mjs'
const expect = chai.expect
@ -173,6 +174,52 @@ describe('Stacks', () => {
})
})
describe('Stack.prototype.home()', () => {
function dummyPart(tl, br) {
return {
__boundary: () => null,
topLeft: new Point(tl.x, tl.y),
bottomRight: new Point(br.x, br.y),
attributes: new Attributes(),
}
}
it('Should calculate the bounds using all part bounds', () => {
const stack = new Stack('test')
stack.context = { settings: [{ margin: 0 }] }
const expectedTlX = -1
const expectedTlY = -2
const expectedBrX = 20
const expectedBrY = 20
stack.addPart(dummyPart({ x: 0, y: expectedTlY }, { x: expectedBrX, y: 10 }))
stack.addPart(dummyPart({ x: expectedTlX, y: 0 }, { x: expectedBrX, y: expectedBrY }))
stack.home()
expect(stack.topLeft.x).to.equal(expectedTlX)
expect(stack.topLeft.y).to.equal(expectedTlY)
expect(stack.bottomRight.x).to.equal(expectedBrX)
expect(stack.bottomRight.y).to.equal(expectedBrY)
})
it('Should calculate the bounds using all transformed part bounds', () => {
const stack = new Stack('test')
stack.context = { settings: [{ margin: 0 }] }
const part1 = dummyPart({ x: 0, y: 0 }, { x: 10, y: 10 })
part1.attributes.add('transform', 'scale(1, -1)')
part1.attributes.add('transform', 'rotate(45)')
stack.addPart(part1)
stack.home()
expect(stack.topLeft.x).to.equal(-7.071067811865475)
expect(stack.topLeft.y).to.equal(-14.142135623730951)
expect(stack.bottomRight.x).to.equal(7.0710678118654755)
expect(stack.bottomRight.y).to.equal(0)
})
})
it('Should get the anchor for the stack', () => {
const part = {
name: 'test',