2021-11-27 13:04:58 +01:00
|
|
|
import chai from 'chai'
|
2022-08-28 12:00:26 +02:00
|
|
|
import { Pattern } from '@freesewing/core'
|
2022-08-28 12:06:41 +02:00
|
|
|
import { bannerPlugin } from './dist/index.mjs'
|
2021-11-27 13:04:58 +01:00
|
|
|
|
|
|
|
const expect = chai.expect
|
2018-12-28 15:08:20 +01:00
|
|
|
|
2021-11-27 16:41:53 +01:00
|
|
|
describe('Banner Plugin Tests', () => {
|
2021-11-20 13:58:40 +01:00
|
|
|
|
2022-08-28 12:00:26 +02:00
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.use(bannerPlugin).render()
|
2021-11-21 16:34:03 +01:00
|
|
|
pattern.parts.test = new pattern.Part()
|
2021-11-27 13:04:58 +01:00
|
|
|
const { Point, points, Path, paths, macro } = pattern.parts.test.shorthand()
|
2021-11-21 16:34:03 +01:00
|
|
|
|
|
|
|
it('Should add repeating text to a path', () => {
|
|
|
|
pattern.parts.test.points.from = new pattern.Point(30, 30)
|
|
|
|
pattern.parts.test.points.to = new pattern.Point(30, 100)
|
2021-11-20 13:58:40 +01:00
|
|
|
pattern.parts.test.paths.example = new Path()
|
|
|
|
.move(pattern.parts.test.points.from)
|
2021-11-21 16:34:03 +01:00
|
|
|
.line(pattern.parts.test.points.to)
|
|
|
|
|
|
|
|
macro('banner', {
|
|
|
|
text: 'foo',
|
|
|
|
path: 'example',
|
|
|
|
})
|
|
|
|
let c = pattern.parts.test.paths.example
|
|
|
|
expect(c.attributes.get('data-text')).to.equal(
|
2022-01-18 17:43:02 +01:00
|
|
|
'            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-16 23:49:45 +01:00
|
|
|
|
2021-11-21 16:34:03 +01:00
|
|
|
it('Number of spaces should be configurable', () => {
|
|
|
|
pattern.parts.test.points.from = new pattern.Point(60, 30)
|
|
|
|
pattern.parts.test.points.to = new pattern.Point(60, 100)
|
2021-11-20 13:58:40 +01:00
|
|
|
pattern.parts.test.paths.example2 = new Path()
|
|
|
|
.move(pattern.parts.test.points.from)
|
2021-11-21 16:34:03 +01:00
|
|
|
.line(pattern.parts.test.points.to)
|
2021-11-20 13:58:40 +01:00
|
|
|
|
2021-11-21 16:34:03 +01:00
|
|
|
macro('banner', {
|
|
|
|
text: 'foo',
|
|
|
|
path: 'example2',
|
|
|
|
spaces: 2,
|
|
|
|
repeat: 2,
|
|
|
|
})
|
|
|
|
let c = pattern.parts.test.paths.example2
|
2022-01-18 17:43:02 +01:00
|
|
|
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', () => {
|
|
|
|
pattern.parts.test.points.from = new pattern.Point(90, 30)
|
|
|
|
pattern.parts.test.points.to = new pattern.Point(90, 100)
|
2021-11-20 13:58:40 +01:00
|
|
|
pattern.parts.test.paths.example3 = new Path()
|
|
|
|
.move(pattern.parts.test.points.from)
|
2021-11-21 16:34:03 +01:00
|
|
|
.line(pattern.parts.test.points.to)
|
|
|
|
|
|
|
|
macro('banner', {
|
|
|
|
text: 'foo',
|
|
|
|
path: 'example3',
|
|
|
|
spaces: 1,
|
|
|
|
repeat: 4,
|
|
|
|
})
|
|
|
|
let c = pattern.parts.test.paths.example3
|
|
|
|
expect(c.attributes.get('data-text')).to.equal(
|
2022-01-18 17:43:02 +01:00
|
|
|
' foo foo foo foo '
|
2021-11-21 16:34:03 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|