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

88 lines
3.3 KiB
JavaScript
Raw Normal View History

import chai from 'chai'
2022-09-14 15:02:39 +02:00
import { Design } from '@freesewing/core'
2022-09-15 13:49:55 +02:00
import { bannerPlugin } from '../src/index.mjs'
const expect = chai.expect
2018-12-28 15:08:20 +01:00
describe('Banner Plugin Tests', () => {
2021-11-21 16:34:03 +01:00
it('Should add repeating text to a path', () => {
2022-09-11 18:56:23 +02:00
const part = {
name: 'test',
draft: ({ Point, points, Path, paths, macro, part }) => {
2022-09-11 18:56:23 +02:00
points.from = new Point(30, 30)
points.to = new Point(30, 100)
paths.example = new Path().move(points.from).line(points.to)
2021-11-21 16:34:03 +01:00
2022-09-11 18:56:23 +02:00
macro('banner', {
text: 'foo',
path: paths.example,
2022-09-11 18:56:23 +02:00
})
return part
2022-09-11 18:56:23 +02:00
},
plugins: [bannerPlugin],
2022-09-11 18:56:23 +02:00
}
const design = new Design({ parts: [part] })
2022-09-11 18:56:23 +02:00
const pattern = new design()
pattern.draft()
const c = pattern.parts[0].test.paths.example
2021-11-21 16:34:03 +01:00
expect(c.attributes.get('data-text')).to.equal(
'            foo            foo            foo            foo            foo            foo            foo            foo            foo            foo            '
2021-11-21 16:34:03 +01:00
)
expect(c.attributes.get('data-text-class')).to.equal('center')
expect(c.attributes.get('data-text-dy')).to.equal('-1')
})
2021-11-21 16:34:03 +01:00
it('Number of spaces should be configurable', () => {
2022-09-11 18:56:23 +02:00
const part = {
name: 'test',
draft: ({ Point, points, Path, paths, macro, part }) => {
2022-09-11 18:56:23 +02:00
points.from = new Point(30, 30)
points.to = new Point(30, 100)
paths.example2 = new Path().move(points.from).line(points.to)
2021-11-20 13:58:40 +01:00
2022-09-11 18:56:23 +02:00
macro('banner', {
text: 'foo',
path: paths.example2,
2022-09-11 18:56:23 +02:00
spaces: 2,
repeat: 2,
})
return part
2022-09-11 18:56:23 +02:00
},
plugins: [bannerPlugin],
2022-09-11 18:56:23 +02:00
}
const design = new Design({ parts: [part] })
2022-09-11 18:56:23 +02:00
const pattern = new design()
pattern.draft()
const c = pattern.parts[0].test.paths.example2
expect(c.attributes.get('data-text')).to.equal('  foo  foo  ')
2021-11-21 16:34:03 +01:00
})
it('Number of repetitions should be configurable', () => {
2022-09-11 18:56:23 +02:00
const part = {
name: 'test',
draft: ({ Point, points, Path, paths, macro, part }) => {
2022-09-11 18:56:23 +02:00
points.from = new Point(30, 30)
points.to = new Point(30, 100)
paths.example3 = new Path().move(points.from).line(points.to)
2021-11-21 16:34:03 +01:00
2022-09-11 18:56:23 +02:00
macro('banner', {
text: 'foo',
path: paths.example3,
2022-09-11 18:56:23 +02:00
spaces: 1,
repeat: 4,
})
return part
2022-09-11 18:56:23 +02:00
},
plugins: [bannerPlugin],
2022-09-11 18:56:23 +02:00
}
const design = new Design({ parts: [part] })
2022-09-11 18:56:23 +02:00
const pattern = new design()
pattern.draft()
const c = pattern.parts[0].test.paths.example3
2022-09-11 18:56:23 +02:00
expect(c.attributes.get('data-text')).to.equal(' foo foo foo foo ')
2021-11-21 16:34:03 +01:00
})
})