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

112 lines
3.6 KiB
JavaScript
Raw Normal View History

import { expect } from 'chai'
2023-03-09 05:20:51 +00:00
import { Design } from '@freesewing/core'
import { annotationsPlugin } from '../src/index.mjs'
2023-03-09 05:20:51 +00:00
const Pattern = new Design()
const pattern = new Pattern().use(annotationsPlugin)
2023-03-09 05:20:51 +00:00
pattern.draft().render()
describe('Buttons Plugin Test', () => {
for (const snippet of ['button', 'buttonhole', 'snap-stud', 'snap-socket']) {
it(`Should add the ${snippet} snippet to defs`, () => {
2023-04-21 03:48:37 +00:00
expect(pattern.svg.defs.get(snippet)).to.not.equal(false)
2023-03-09 05:20:51 +00:00
})
}
it('Draws a button on an anchor point', () => {
const part = {
name: 'test',
draft: ({ points, Point, snippets, Snippet, part }) => {
points.anchor = new Point(10, 20)
snippets.button = new Snippet('button', points.anchor)
return part
},
plugins: [annotationsPlugin],
2023-03-09 05:20:51 +00:00
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
2023-03-09 05:20:51 +00:00
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#button"')
})
it('Draws a buttonhole centred on an anchor point', () => {
const part = {
name: 'test',
draft: ({ points, Point, snippets, Snippet, part }) => {
points.anchor = new Point(10, 20)
snippets.button = new Snippet('buttonhole', points.anchor)
return part
},
plugins: [annotationsPlugin],
2023-03-09 05:20:51 +00:00
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
2023-03-09 05:20:51 +00:00
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#buttonhole"')
})
it('Draws a buttonhole starting on an anchor point', () => {
const part = {
name: 'test',
draft: ({ points, Point, snippets, Snippet, part }) => {
points.anchor = new Point(10, 20)
snippets.button = new Snippet('buttonhole-start', points.anchor)
return part
},
plugins: [annotationsPlugin],
2023-03-09 05:20:51 +00:00
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
2023-03-09 05:20:51 +00:00
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#buttonhole-start"')
})
it('Draws a buttonhole ending on an anchor point', () => {
const part = {
name: 'test',
draft: ({ points, Point, snippets, Snippet, part }) => {
points.anchor = new Point(10, 20)
snippets.button = new Snippet('buttonhole-end', points.anchor)
return part
},
plugins: [annotationsPlugin],
2023-03-09 05:20:51 +00:00
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
2023-03-09 05:20:51 +00:00
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#buttonhole-end"')
})
it('Draws a snap-stud on an anchor point', () => {
const part = {
name: 'test',
draft: ({ points, Point, snippets, Snippet, part }) => {
points.anchor = new Point(10, 20)
snippets.button = new Snippet('snap-stud', points.anchor)
return part
},
plugins: [annotationsPlugin],
2023-03-09 05:20:51 +00:00
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
2023-03-09 05:20:51 +00:00
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#snap-stud"')
})
it('Draws a snap-socket on an anchor point', () => {
const part = {
name: 'test',
draft: ({ points, Point, snippets, Snippet, part }) => {
points.anchor = new Point(10, 20)
snippets.button = new Snippet('snap-socket', points.anchor)
return part
},
plugins: [annotationsPlugin],
2023-03-09 05:20:51 +00:00
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
2023-03-09 05:20:51 +00:00
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#snap-socket"')
})
})