2021-11-27 16:46:38 +01:00
|
|
|
import chai from 'chai'
|
2022-09-07 10:57:47 +02:00
|
|
|
import { Design } from '@freesewing/core'
|
2022-08-28 14:06:01 +02:00
|
|
|
import { plugin } from './dist/index.mjs'
|
2021-11-27 16:46:38 +01:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Title Plugin Tests', () => {
|
2022-09-07 10:57:47 +02:00
|
|
|
const Pattern = new Design()
|
2022-08-28 14:06:01 +02:00
|
|
|
const pattern = new Pattern().use(plugin)
|
2021-11-27 16:46:38 +01:00
|
|
|
pattern.draft().render()
|
|
|
|
|
2022-09-07 10:57:47 +02:00
|
|
|
it('Should run the title macro', () => {
|
|
|
|
const Pattern = new Design({ data: { name: 'testPattern', version: 99 } })
|
|
|
|
let pattern = new Pattern()
|
|
|
|
pattern.draft = function () {}
|
|
|
|
pattern.use(plugin)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
pattern.parts.test.points.anchor = new pattern.Point(-12, -34)
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('title', {
|
2021-11-27 16:46:38 +01:00
|
|
|
at: pattern.parts.test.points.anchor,
|
|
|
|
nr: 3,
|
2022-09-07 10:57:47 +02:00
|
|
|
title: 'unitTest',
|
|
|
|
})
|
|
|
|
pattern.render()
|
|
|
|
let p = pattern.parts.test.points.__titleNr
|
|
|
|
expect(p.x).to.equal(-12)
|
|
|
|
expect(p.y).to.equal(-34)
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('3')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
|
|
|
p = pattern.parts.test.points.__titleName
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
|
|
|
p = pattern.parts.test.points.__titlePattern
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-18')
|
|
|
|
})
|
2021-11-27 16:46:38 +01:00
|
|
|
|
2022-09-07 10:57:47 +02:00
|
|
|
it('Should run the title macro with append flag', () => {
|
|
|
|
const Pattern = new Design({ data: { name: 'testPattern', version: 99 } })
|
|
|
|
let pattern = new Pattern()
|
|
|
|
pattern.draft = function () {}
|
|
|
|
pattern.use(plugin)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr('data-text', '#')
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('title', {
|
2021-11-27 16:46:38 +01:00
|
|
|
at: pattern.parts.test.points.anchor,
|
|
|
|
nr: 3,
|
2022-09-07 10:57:47 +02:00
|
|
|
title: 'unitTest',
|
|
|
|
append: true,
|
|
|
|
})
|
|
|
|
pattern.render()
|
|
|
|
let p = pattern.parts.test.points.__titleNr
|
|
|
|
expect(p.x).to.equal(-12)
|
|
|
|
expect(p.y).to.equal(-34)
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('# 3')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
|
|
|
})
|
2021-11-27 16:46:38 +01:00
|
|
|
|
2022-09-07 10:57:47 +02:00
|
|
|
it('Should run the title macro with point prefix', () => {
|
|
|
|
const Pattern = new Design({ data: { name: 'testPattern', version: 99 } })
|
|
|
|
let pattern = new Pattern()
|
|
|
|
pattern.draft = function () {}
|
|
|
|
pattern.use(plugin)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr('data-text', '#')
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('title', {
|
2021-11-27 16:46:38 +01:00
|
|
|
at: pattern.parts.test.points.anchor,
|
|
|
|
nr: 3,
|
2022-09-07 10:57:47 +02:00
|
|
|
title: 'unitTest',
|
|
|
|
prefix: 'foo',
|
|
|
|
})
|
|
|
|
pattern.render()
|
|
|
|
let p = pattern.parts.test.points._foo_titleNr
|
|
|
|
expect(p.x).to.equal(-12)
|
|
|
|
expect(p.y).to.equal(-34)
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('3')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
|
|
|
p = pattern.parts.test.points._foo_titleName
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
|
|
|
p = pattern.parts.test.points._foo_titlePattern
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note')
|
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-18')
|
|
|
|
})
|
|
|
|
})
|