2021-11-27 16:42:47 +01:00
|
|
|
import chai from 'chai'
|
2022-09-07 10:57:47 +02:00
|
|
|
import { Design } from '@freesewing/core'
|
2022-09-15 13:49:55 +02:00
|
|
|
import { plugin } from '../src/index.mjs'
|
2021-11-27 16:42:47 +01:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
2022-09-07 10:57:47 +02:00
|
|
|
const Pattern = new Design()
|
2022-08-28 12:16:52 +02:00
|
|
|
const pattern = new Pattern().use(plugin)
|
2021-11-27 16:42:47 +01: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`, () => {
|
|
|
|
expect(pattern.svg.defs.indexOf(`<g id="${snippet}">`)).to.not.equal(-1)
|
|
|
|
})
|
|
|
|
}
|
2022-01-27 20:52:55 +01:00
|
|
|
|
|
|
|
it('Draws a button on an anchor point', () => {
|
2022-09-11 21:37:31 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, snippets, Snippet }) => {
|
|
|
|
points.anchor = new Point(10, 20)
|
|
|
|
snippets.button = new Snippet('button', points.anchor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const Pattern = new Design({ parts: [part], plugins: [plugin] })
|
|
|
|
const svg = new Pattern().draft().render()
|
|
|
|
expect(svg).to.contain('<use x="10" y="20" xlink:href="#button"')
|
2022-01-27 20:52:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Draws a buttonhole centred on an anchor point', () => {
|
2022-09-11 21:37:31 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, snippets, Snippet }) => {
|
|
|
|
points.anchor = new Point(10, 20)
|
|
|
|
snippets.button = new Snippet('buttonhole', points.anchor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const Pattern = new Design({ parts: [part], plugins: [plugin] })
|
|
|
|
const svg = new Pattern().draft().render()
|
|
|
|
expect(svg).to.contain('<use x="10" y="20" xlink:href="#buttonhole"')
|
2022-01-27 20:52:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Draws a buttonhole starting on an anchor point', () => {
|
2022-09-11 21:37:31 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, snippets, Snippet }) => {
|
|
|
|
points.anchor = new Point(10, 20)
|
|
|
|
snippets.button = new Snippet('buttonhole-start', points.anchor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const Pattern = new Design({ parts: [part], plugins: [plugin] })
|
|
|
|
const svg = new Pattern().draft().render()
|
|
|
|
expect(svg).to.contain('<use x="10" y="20" xlink:href="#buttonhole-start"')
|
2022-01-27 20:52:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Draws a buttonhole ending on an anchor point', () => {
|
2022-09-11 21:37:31 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, snippets, Snippet }) => {
|
|
|
|
points.anchor = new Point(10, 20)
|
|
|
|
snippets.button = new Snippet('buttonhole-end', points.anchor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const Pattern = new Design({ parts: [part], plugins: [plugin] })
|
|
|
|
const svg = new Pattern().draft().render()
|
|
|
|
expect(svg).to.contain('<use x="10" y="20" xlink:href="#buttonhole-end"')
|
2022-01-27 20:52:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Draws a snap-stud on an anchor point', () => {
|
2022-09-11 21:37:31 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, snippets, Snippet }) => {
|
|
|
|
points.anchor = new Point(10, 20)
|
|
|
|
snippets.button = new Snippet('snap-stud', points.anchor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const Pattern = new Design({ parts: [part], plugins: [plugin] })
|
|
|
|
const svg = new Pattern().draft().render()
|
|
|
|
expect(svg).to.contain('<use x="10" y="20" xlink:href="#snap-stud"')
|
2022-01-27 20:52:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Draws a snap-socket on an anchor point', () => {
|
2022-09-11 21:37:31 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, snippets, Snippet }) => {
|
|
|
|
points.anchor = new Point(10, 20)
|
|
|
|
snippets.button = new Snippet('snap-socket', points.anchor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const Pattern = new Design({ parts: [part], plugins: [plugin] })
|
|
|
|
const svg = new Pattern().draft().render()
|
|
|
|
expect(svg).to.contain('<use x="10" y="20" xlink:href="#snap-socket"')
|
2022-01-27 20:52:55 +01:00
|
|
|
})
|
2021-11-27 16:42:47 +01:00
|
|
|
})
|