2021-11-27 13:11:01 +01:00
|
|
|
import chai from 'chai'
|
2022-09-14 15:02:39 +02:00
|
|
|
import { Design, round } from '@freesewing/core'
|
2023-04-10 15:20:32 +02:00
|
|
|
import { annotationsPlugin } from '../src/index.mjs'
|
2018-12-08 14:49:54 +01:00
|
|
|
|
2021-11-27 13:11:01 +01:00
|
|
|
const expect = chai.expect
|
2018-12-08 14:49:54 +01:00
|
|
|
|
2021-11-27 16:42:58 +01:00
|
|
|
describe('Cutonfold Plugin Tests', () => {
|
2021-11-21 17:01:18 +01:00
|
|
|
it('Should run the default cutonfold macro', () => {
|
2022-09-11 21:44:28 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-25 15:32:57 +02:00
|
|
|
draft: ({ Point, points, macro, part }) => {
|
2022-09-11 21:44:28 +02:00
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.to = new Point(10, 220)
|
|
|
|
macro('cutonfold', {
|
|
|
|
from: points.from,
|
|
|
|
to: points.to,
|
|
|
|
})
|
2022-09-25 15:32:57 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:44:28 +02:00
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-11 21:44:28 +02:00
|
|
|
}
|
2023-09-08 09:37:35 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part] }, true)
|
2022-09-11 21:44:28 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-09-08 09:37:35 +02:00
|
|
|
const c = pattern.parts[0].test.paths.__macro_cutonfold_cutonfold_line
|
2021-11-21 17:01:18 +01:00
|
|
|
expect(c.attributes.get('class')).to.equal('note')
|
|
|
|
expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)')
|
|
|
|
expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)')
|
2023-09-08 09:37:35 +02:00
|
|
|
expect(c.attributes.get('data-text')).to.equal('plugin-annotations:cutOnFold')
|
2021-11-21 17:01:18 +01:00
|
|
|
expect(c.attributes.get('data-text-class')).to.equal('center fill-note')
|
|
|
|
expect(c.ops[0].type).to.equal('move')
|
|
|
|
expect(c.ops[1].type).to.equal('line')
|
|
|
|
expect(c.ops[2].type).to.equal('line')
|
|
|
|
expect(c.ops[3].type).to.equal('line')
|
|
|
|
expect(round(c.ops[0].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[0].to.y)).to.equal(30)
|
|
|
|
expect(round(c.ops[1].to.x)).to.equal(25)
|
|
|
|
expect(round(c.ops[1].to.y)).to.equal(30)
|
|
|
|
expect(round(c.ops[2].to.x)).to.equal(25)
|
|
|
|
expect(round(c.ops[2].to.y)).to.equal(210)
|
|
|
|
expect(round(c.ops[3].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[3].to.y)).to.equal(210)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run the cutonfold/grainline macro', () => {
|
2022-09-11 21:44:28 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-25 15:32:57 +02:00
|
|
|
draft: ({ Point, points, macro, part }) => {
|
2022-09-11 21:44:28 +02:00
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.to = new Point(10, 220)
|
|
|
|
macro('cutonfold', {
|
|
|
|
from: points.from,
|
|
|
|
to: points.to,
|
|
|
|
grainline: true,
|
|
|
|
})
|
2022-09-25 15:32:57 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:44:28 +02:00
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-11 21:44:28 +02:00
|
|
|
}
|
2023-09-08 09:37:35 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part] }, true)
|
2022-09-11 21:44:28 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-09-08 09:37:35 +02:00
|
|
|
expect(
|
|
|
|
pattern.parts[0].test.paths.__macro_cutonfold_cutonfold_line.attributes.get('data-text')
|
|
|
|
).to.equal('plugin-annotations:cutOnFoldAndGrainline')
|
2021-11-21 17:01:18 +01:00
|
|
|
})
|
2022-01-27 20:52:55 +01:00
|
|
|
|
|
|
|
it('Should run the cutonfold macro with configurable offset', () => {
|
2022-09-11 21:44:28 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-25 15:32:57 +02:00
|
|
|
draft: ({ Point, points, macro, part }) => {
|
2022-09-11 21:44:28 +02:00
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.to = new Point(10, 220)
|
|
|
|
macro('cutonfold', {
|
|
|
|
from: points.from,
|
|
|
|
to: points.to,
|
|
|
|
offset: 30,
|
|
|
|
})
|
2022-09-25 15:32:57 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:44:28 +02:00
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-11 21:44:28 +02:00
|
|
|
}
|
2023-09-08 09:37:35 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part] }, true)
|
2022-09-11 21:44:28 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-09-08 09:37:35 +02:00
|
|
|
let c = pattern.parts[0].test.paths.__macro_cutonfold_cutonfold_line
|
2022-01-27 20:52:55 +01:00
|
|
|
expect(c.attributes.get('class')).to.equal('note')
|
|
|
|
expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)')
|
|
|
|
expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)')
|
2023-09-08 09:37:35 +02:00
|
|
|
expect(c.attributes.get('data-text')).to.equal('plugin-annotations:cutOnFold')
|
2022-01-27 20:52:55 +01:00
|
|
|
expect(c.attributes.get('data-text-class')).to.equal('center fill-note')
|
|
|
|
expect(c.ops[0].type).to.equal('move')
|
|
|
|
expect(c.ops[1].type).to.equal('line')
|
|
|
|
expect(c.ops[2].type).to.equal('line')
|
|
|
|
expect(c.ops[3].type).to.equal('line')
|
|
|
|
expect(round(c.ops[0].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[0].to.y)).to.equal(30)
|
|
|
|
expect(round(c.ops[1].to.x)).to.equal(40)
|
|
|
|
expect(round(c.ops[1].to.y)).to.equal(30)
|
|
|
|
expect(round(c.ops[2].to.x)).to.equal(40)
|
|
|
|
expect(round(c.ops[2].to.y)).to.equal(210)
|
|
|
|
expect(round(c.ops[3].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[3].to.y)).to.equal(210)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run the cutonfold macro with configurable margin', () => {
|
2022-09-11 21:44:28 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-25 15:32:57 +02:00
|
|
|
draft: ({ Point, points, macro, part }) => {
|
2022-09-11 21:44:28 +02:00
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.to = new Point(10, 220)
|
|
|
|
macro('cutonfold', {
|
|
|
|
from: points.from,
|
|
|
|
to: points.to,
|
2023-09-08 09:37:35 +02:00
|
|
|
margin: 0.2,
|
2022-09-11 21:44:28 +02:00
|
|
|
})
|
2022-09-25 15:32:57 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:44:28 +02:00
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-11 21:44:28 +02:00
|
|
|
}
|
2023-09-08 09:37:35 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part] }, true)
|
2022-09-11 21:44:28 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-09-08 09:37:35 +02:00
|
|
|
let c = pattern.parts[0].test.paths.__macro_cutonfold_cutonfold_line
|
2022-01-27 20:52:55 +01:00
|
|
|
expect(c.attributes.get('class')).to.equal('note')
|
|
|
|
expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)')
|
|
|
|
expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)')
|
2023-09-08 09:37:35 +02:00
|
|
|
expect(c.attributes.get('data-text')).to.equal('plugin-annotations:cutOnFold')
|
2022-01-27 20:52:55 +01:00
|
|
|
expect(c.attributes.get('data-text-class')).to.equal('center fill-note')
|
|
|
|
expect(c.ops[0].type).to.equal('move')
|
|
|
|
expect(c.ops[1].type).to.equal('line')
|
|
|
|
expect(c.ops[2].type).to.equal('line')
|
|
|
|
expect(c.ops[3].type).to.equal('line')
|
|
|
|
expect(round(c.ops[0].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[0].to.y)).to.equal(60)
|
|
|
|
expect(round(c.ops[1].to.x)).to.equal(25)
|
|
|
|
expect(round(c.ops[1].to.y)).to.equal(60)
|
|
|
|
expect(round(c.ops[2].to.x)).to.equal(25)
|
|
|
|
expect(round(c.ops[2].to.y)).to.equal(180)
|
|
|
|
expect(round(c.ops[3].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[3].to.y)).to.equal(180)
|
|
|
|
})
|
2021-11-21 17:01:18 +01:00
|
|
|
})
|