2024-02-04 12:14:42 +01:00
|
|
|
import { expect } from 'chai'
|
2023-03-10 03:05:33 +00:00
|
|
|
import { Design, round } from '@freesewing/core'
|
2023-04-10 15:20:32 +02:00
|
|
|
import { annotationsPlugin } from '../src/index.mjs'
|
2023-03-10 03:05:33 +00:00
|
|
|
|
|
|
|
describe('Sewtogether Plugin Tests', () => {
|
|
|
|
it('Should run the default sewtogether macro', () => {
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ Point, points, macro, part }) => {
|
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.to = new Point(10, 220)
|
2023-04-15 15:58:06 +02:00
|
|
|
macro('sewTogether', {
|
2023-03-10 03:05:33 +00:00
|
|
|
from: points.from,
|
|
|
|
to: points.to,
|
|
|
|
})
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2023-03-10 03:05:33 +00:00
|
|
|
}
|
2023-09-08 10:18:57 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
2023-09-08 10:50:03 +02:00
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part], noCorePlugins: true })
|
2023-03-10 03:05:33 +00:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-09-08 10:18:57 +02:00
|
|
|
const c = pattern.parts[0].test.paths.__macro_sewtogether_sewtogether_curve
|
2023-03-10 03:05:33 +00:00
|
|
|
expect(c.attributes.get('class')).to.equal('dotted note stroke-sm')
|
|
|
|
expect(c.attributes.get('marker-start')).to.equal('url(#sewTogetherStart)')
|
|
|
|
expect(c.attributes.get('marker-end')).to.equal('url(#sewTogetherEnd)')
|
2023-09-08 10:18:57 +02:00
|
|
|
expect(c.attributes.get('data-text')).to.equal('plugin-annotations:sewTogether')
|
2023-03-10 03:05:33 +00:00
|
|
|
expect(c.attributes.get('data-text-class')).to.equal('center fill-note text-xs')
|
|
|
|
expect(c.ops[0].type).to.equal('move')
|
|
|
|
expect(c.ops[1].type).to.equal('curve')
|
|
|
|
expect(round(c.ops[0].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[0].to.y)).to.equal(20)
|
|
|
|
expect(round(c.ops[1].cp1.x)).to.equal(76.67)
|
|
|
|
expect(round(c.ops[1].cp1.y)).to.equal(20)
|
|
|
|
expect(round(c.ops[1].cp2.x)).to.equal(76.67)
|
|
|
|
expect(round(c.ops[1].cp2.y)).to.equal(220)
|
|
|
|
expect(round(c.ops[1].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[1].to.y)).to.equal(220)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run the sewtogether/hinge macro', () => {
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ Point, points, macro, part }) => {
|
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.hinge = new Point(40, 110)
|
|
|
|
points.to = new Point(10, 220)
|
2023-04-15 15:58:06 +02:00
|
|
|
macro('sewTogether', {
|
2023-03-10 03:05:33 +00:00
|
|
|
from: points.from,
|
|
|
|
hinge: points.hinge,
|
|
|
|
to: points.to,
|
|
|
|
})
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2023-03-10 03:05:33 +00:00
|
|
|
}
|
2023-09-08 10:18:57 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
2023-09-08 10:50:03 +02:00
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part], noCorePlugins: true })
|
2023-03-10 03:05:33 +00:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-09-08 10:18:57 +02:00
|
|
|
let c = pattern.parts[0].test.paths.__macro_sewtogether_sewtogether_hinge
|
|
|
|
expect(c.attributes.get('class')).to.equal('note dotted stroke-sm')
|
2023-03-10 03:05:33 +00:00
|
|
|
expect(c.attributes.get('marker-start')).to.equal('url(#sewTogetherCross)')
|
|
|
|
expect(c.ops[0].type).to.equal('move')
|
|
|
|
expect(c.ops[1].type).to.equal('line')
|
|
|
|
expect(round(c.ops[0].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[0].to.y)).to.equal(120)
|
|
|
|
expect(round(c.ops[1].to.x)).to.equal(35)
|
|
|
|
expect(round(c.ops[1].to.y)).to.equal(120)
|
|
|
|
})
|
|
|
|
|
2023-04-15 15:58:06 +02:00
|
|
|
it('Should run the sewTogether/hinge (with sa) macro', () => {
|
2023-03-10 03:05:33 +00:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ Point, points, macro, part }) => {
|
|
|
|
points.from = new Point(10, 20)
|
2023-03-10 03:23:01 +00:00
|
|
|
points.hinge = new Point(40, 110)
|
2023-03-10 03:05:33 +00:00
|
|
|
points.to = new Point(10, 220)
|
2023-04-15 15:58:06 +02:00
|
|
|
macro('sewTogether', {
|
2023-03-10 03:05:33 +00:00
|
|
|
from: points.from,
|
2023-03-10 03:23:01 +00:00
|
|
|
hinge: points.hinge,
|
2023-03-10 03:05:33 +00:00
|
|
|
to: points.to,
|
|
|
|
})
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2023-03-10 03:05:33 +00:00
|
|
|
}
|
2023-09-08 10:18:57 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
2023-09-08 10:50:03 +02:00
|
|
|
const Test = new Design({ plugins: [annotationsPlugin], parts: [part], noCorePlugins: true })
|
2023-03-10 03:23:01 +00:00
|
|
|
const pattern = new Test({ sa: 10 })
|
2023-03-10 03:05:33 +00:00
|
|
|
pattern.draft()
|
2023-09-08 10:18:57 +02:00
|
|
|
let c = pattern.parts[0].test.paths.__macro_sewtogether_sewtogether_hinge
|
2023-03-10 03:23:01 +00:00
|
|
|
expect(round(c.ops[1].to.x)).to.equal(0)
|
2023-03-10 03:05:33 +00:00
|
|
|
})
|
|
|
|
})
|