1
0
Fork 0
freesewing/plugins/plugin-annotations/tests/buttons.test.mjs
joostdecock 26e282f5b7 fix: Fix tests after major chai upgrade
Note that the tests for Lumina are failing, but that's not related to
the chai upgrade, rather it seems these tests fail because of issues in
the design that we'll tackle later (it's a brand new design yet to be
released).
2024-02-04 12:14:42 +01:00

111 lines
3.6 KiB
JavaScript

import { expect } from 'chai'
import { Design } from '@freesewing/core'
import { annotationsPlugin } from '../src/index.mjs'
const Pattern = new Design()
const pattern = new Pattern().use(annotationsPlugin)
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.get(snippet)).to.not.equal(false)
})
}
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],
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
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],
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
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],
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
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],
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
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],
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
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],
}
const Pattern = new Design({ parts: [part], noCorePlugins: true })
const svg = new Pattern().draft().render()
expect(svg).to.contain('<use x="10" y="20" xlink:href="#snap-socket"')
})
})