2024-02-04 12:14:42 +01:00
|
|
|
import { expect } from 'chai'
|
2023-03-09 05:20:51 +00:00
|
|
|
import { round, Design } from '@freesewing/core'
|
2023-04-10 15:20:32 +02:00
|
|
|
import { annotationsPlugin } from '../src/index.mjs'
|
2023-03-09 05:20:51 +00:00
|
|
|
|
|
|
|
describe('Grainline Plugin Tests', () => {
|
|
|
|
it('Should run the default grainline macro', () => {
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, macro, part }) => {
|
|
|
|
points.from = new Point(10, 20)
|
|
|
|
points.to = new Point(10, 230)
|
|
|
|
macro('grainline', {
|
|
|
|
from: points.from,
|
|
|
|
to: points.to,
|
|
|
|
})
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
2023-04-10 15:20:32 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2023-03-09 05:20:51 +00:00
|
|
|
}
|
2023-09-08 09:44:41 +02:00
|
|
|
// Note that we're not loading core plugins but the local plugin
|
2023-09-08 10:50:03 +02:00
|
|
|
const Pattern = new Design({ parts: [part], noCorePlugins: true })
|
2023-03-09 05:20:51 +00:00
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.draft()
|
2023-09-08 09:44:41 +02:00
|
|
|
const c = pattern.parts[0].test.paths.__macro_grainline_grainline_line
|
2023-03-09 05:20:51 +00:00
|
|
|
expect(c.attributes.get('class')).to.equal('note')
|
|
|
|
expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)')
|
|
|
|
expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)')
|
2023-09-08 09:44:41 +02:00
|
|
|
expect(c.attributes.get('data-text')).to.equal('plugin-annotations:grainline')
|
2023-03-09 05:20:51 +00: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(round(c.ops[0].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[0].to.y)).to.equal(30.5)
|
|
|
|
expect(round(c.ops[1].to.x)).to.equal(10)
|
|
|
|
expect(round(c.ops[1].to.y)).to.equal(219.5)
|
|
|
|
})
|
|
|
|
})
|