1
0
Fork 0
freesewing/plugins/plugin-gore/tests/plugin.test.mjs

148 lines
4.1 KiB
JavaScript
Raw Normal View History

import { expect } from 'chai'
2022-09-14 15:02:39 +02:00
import { round, Design } from '@freesewing/core'
2022-09-12 09:32:12 +02:00
import { plugin } from '../src/index.mjs'
describe('Gore Plugin Tests', () => {
2022-01-27 20:52:55 +01:00
it('Should create a default gore', () => {
2022-09-12 09:32:12 +02:00
const part = {
name: 'test',
draft: ({ Point, points, macro, part }) => {
2022-09-12 09:32:12 +02:00
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
radius: 25,
gores: 4,
extraLength: 0,
prefix: 'gore',
})
return part
2022-09-12 09:32:12 +02:00
},
plugins: [plugin],
2022-09-12 09:32:12 +02:00
}
const Test = new Design({ parts: [part] })
2022-09-12 09:32:12 +02:00
const pattern = new Test()
pattern.draft()
let c = pattern.parts[0].test.points
2022-01-27 20:52:55 +01:00
expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(50)
expect(round(c.gorep2.y)).to.equal(30.37)
expect(round(c.gorep3.x)).to.equal(50)
expect(round(c.gorep3.y)).to.equal(30.37)
})
it('Should use a configurable number of gores', () => {
2022-09-12 09:32:12 +02:00
const part = {
name: 'test',
draft: ({ Point, points, macro, part }) => {
2022-09-12 09:32:12 +02:00
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
radius: 25,
gores: 8,
extraLength: 0,
prefix: 'gore',
})
return part
2022-09-12 09:32:12 +02:00
},
plugins: [plugin],
2022-09-12 09:32:12 +02:00
}
const Test = new Design({ parts: [part] })
2022-09-12 09:32:12 +02:00
const pattern = new Test()
pattern.draft()
let c = pattern.parts[0].test.points
2022-01-27 20:52:55 +01:00
expect(round(c.gorep1.x)).to.equal(89.27)
expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(50)
expect(round(c.gorep2.y)).to.equal(40.18)
expect(round(c.gorep3.x)).to.equal(50)
expect(round(c.gorep3.y)).to.equal(40.18)
})
it('Should use a configurable extra length', () => {
2022-09-12 09:32:12 +02:00
const part = {
name: 'test',
draft: ({ Point, points, macro, part }) => {
2022-09-12 09:32:12 +02:00
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
radius: 25,
gores: 4,
extraLength: 20,
prefix: 'gore',
})
return part
2022-09-12 09:32:12 +02:00
},
plugins: [plugin],
2022-09-12 09:32:12 +02:00
}
const Test = new Design({ parts: [part] })
2022-09-12 09:32:12 +02:00
const pattern = new Test()
pattern.draft()
let c = pattern.parts[0].test.points
2022-01-27 20:52:55 +01:00
expect(round(c.gorep1.x)).to.equal(109.27)
expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(70)
expect(round(c.gorep2.y)).to.equal(30.37)
expect(round(c.gorep3.x)).to.equal(50)
expect(round(c.gorep3.y)).to.equal(30.37)
})
it('Should use a configurable radius', () => {
2022-09-12 09:32:12 +02:00
const part = {
name: 'test',
draft: ({ Point, points, macro, part }) => {
2022-09-12 09:32:12 +02:00
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
radius: 30,
gores: 4,
extraLength: 0,
prefix: 'gore',
})
return part
2022-09-12 09:32:12 +02:00
},
plugins: [plugin],
2022-09-12 09:32:12 +02:00
}
const Test = new Design({ parts: [part] })
2022-09-12 09:32:12 +02:00
const pattern = new Test()
pattern.draft()
let c = pattern.parts[0].test.points
2022-01-27 20:52:55 +01:00
expect(round(c.gorep1.x)).to.equal(97.12)
expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(50)
expect(round(c.gorep2.y)).to.equal(26.44)
expect(round(c.gorep3.x)).to.equal(50)
expect(round(c.gorep3.y)).to.equal(26.44)
})
it('Should generate a seam path', () => {
2022-09-12 09:32:12 +02:00
const part = {
name: 'test',
draft: ({ Point, points, macro, part }) => {
2022-09-12 09:32:12 +02:00
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
radius: 25,
gores: 4,
extraLength: 0,
prefix: 'gore',
})
return part
2022-09-12 09:32:12 +02:00
},
plugins: [plugin],
2022-09-12 09:32:12 +02:00
}
const Test = new Design({ parts: [part] })
2022-09-12 09:32:12 +02:00
const pattern = new Test()
pattern.draft()
let c = pattern.parts[0].test.paths.goreseam.ops
2022-01-27 20:52:55 +01:00
expect(round(c[1].to.x)).to.equal(89.27)
expect(round(c[1].to.y)).to.equal(50)
expect(round(c[2].to.x)).to.equal(50)
expect(round(c[2].to.y)).to.equal(30.37)
})
})