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'
|
2023-04-15 15:14:56 +02:00
|
|
|
import { annotationsPlugin } from '../src/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
|
|
|
it('Should run the title macro', () => {
|
2022-09-12 15:42:50 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-27 14:08:32 +02:00
|
|
|
draft: ({ points, Point, macro, part }) => {
|
2022-09-15 07:53:35 +02:00
|
|
|
points.anchor = new Point(-12, -34)
|
2022-09-12 15:42:50 +02:00
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
})
|
2022-09-27 14:08:32 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-12 15:42:50 +02:00
|
|
|
},
|
2023-04-15 15:14:56 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-12 15:42:50 +02:00
|
|
|
}
|
|
|
|
const Pattern = new Design({
|
|
|
|
data: { name: 'testPattern', version: 99 },
|
|
|
|
parts: [part],
|
2022-09-07 10:57:47 +02:00
|
|
|
})
|
2022-09-12 15:42:50 +02:00
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.draft().render()
|
2022-09-27 14:08:32 +02:00
|
|
|
let p = pattern.parts[0].test.points.__titleNr
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.x).to.equal(-12)
|
|
|
|
expect(p.y).to.equal(-34)
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('3')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold left')
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
2022-09-27 14:08:32 +02:00
|
|
|
p = pattern.parts[0].test.points.__titleName
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold left')
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
2022-09-27 14:08:32 +02:00
|
|
|
p = pattern.parts[0].test.points.__titlePattern
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note left')
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-18')
|
2023-05-04 16:24:29 -07:00
|
|
|
p = pattern.parts[0].test.points.__exportDate
|
|
|
|
expect(p.attributes.get('data-text')).to.match(/^.+, .+ \d{1,2}, \d{4}@ \d\d:\d\d$/)
|
2022-09-07 10:57:47 +02:00
|
|
|
})
|
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', () => {
|
2022-09-12 15:42:50 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-27 14:08:32 +02:00
|
|
|
draft: ({ points, Point, macro, part }) => {
|
2022-09-15 07:53:35 +02:00
|
|
|
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
2022-09-12 15:42:50 +02:00
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
append: true,
|
|
|
|
})
|
2022-09-27 14:08:32 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-12 15:42:50 +02:00
|
|
|
},
|
2023-04-15 15:14:56 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-12 15:42:50 +02:00
|
|
|
}
|
|
|
|
const Pattern = new Design({
|
|
|
|
data: { name: 'testPattern', version: 99 },
|
|
|
|
parts: [part],
|
2022-09-07 10:57:47 +02:00
|
|
|
})
|
2022-09-12 15:42:50 +02:00
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.draft().render()
|
2022-09-27 14:08:32 +02:00
|
|
|
let p = pattern.parts[0].test.points.__titleNr
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.x).to.equal(-12)
|
|
|
|
expect(p.y).to.equal(-34)
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('# 3')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold left')
|
2022-09-07 10:57:47 +02:00
|
|
|
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', () => {
|
2022-09-12 15:42:50 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-09-27 14:08:32 +02:00
|
|
|
draft: ({ points, Point, macro, part }) => {
|
2022-09-15 07:53:35 +02:00
|
|
|
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
2022-09-12 15:42:50 +02:00
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
prefix: 'foo',
|
|
|
|
})
|
2022-09-27 14:08:32 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-12 15:42:50 +02:00
|
|
|
},
|
2023-04-15 15:14:56 +02:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-12 15:42:50 +02:00
|
|
|
}
|
|
|
|
const Pattern = new Design({
|
|
|
|
data: { name: 'testPattern', version: 99 },
|
|
|
|
parts: [part],
|
2022-09-07 10:57:47 +02:00
|
|
|
})
|
2022-09-12 15:42:50 +02:00
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.draft().render()
|
2022-09-27 14:08:32 +02:00
|
|
|
let p = pattern.parts[0].test.points._foo_titleNr
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.x).to.equal(-12)
|
|
|
|
expect(p.y).to.equal(-34)
|
|
|
|
expect(p.attributes.get('data-text')).to.equal('3')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold left')
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
2022-09-27 14:08:32 +02:00
|
|
|
p = pattern.parts[0].test.points._foo_titleName
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold left')
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
2022-09-27 14:08:32 +02:00
|
|
|
p = pattern.parts[0].test.points._foo_titlePattern
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
2023-05-04 16:24:29 -07:00
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note left')
|
2022-09-07 10:57:47 +02:00
|
|
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
|
|
|
expect(p.attributes.get('data-text-y')).to.equal('-18')
|
|
|
|
})
|
2023-05-04 16:24:29 -07:00
|
|
|
|
|
|
|
it('Should run the title macro with valid align prefixes', () => {
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, macro, part }) => {
|
|
|
|
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
align: 'left',
|
|
|
|
prefix: 'left',
|
|
|
|
})
|
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
align: 'right',
|
|
|
|
prefix: 'right',
|
|
|
|
})
|
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
align: 'center',
|
|
|
|
prefix: 'center',
|
|
|
|
})
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
|
|
|
plugins: [annotationsPlugin],
|
|
|
|
}
|
|
|
|
const Pattern = new Design({
|
|
|
|
data: { name: 'testPattern', version: 99 },
|
|
|
|
parts: [part],
|
|
|
|
})
|
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.draft().render()
|
|
|
|
let p = pattern.parts[0].test.points._left_titleNr
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold left')
|
|
|
|
p = pattern.parts[0].test.points._left_titleName
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold left')
|
|
|
|
p = pattern.parts[0].test.points._left_titlePattern
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note left')
|
|
|
|
p = pattern.parts[0].test.points._center_titleNr
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold center')
|
|
|
|
p = pattern.parts[0].test.points._center_titleName
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold center')
|
|
|
|
p = pattern.parts[0].test.points._center_titlePattern
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note center')
|
|
|
|
p = pattern.parts[0].test.points._right_titleNr
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold right')
|
|
|
|
p = pattern.parts[0].test.points._right_titleName
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold right')
|
|
|
|
p = pattern.parts[0].test.points._right_titlePattern
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note right')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run the title macro with an invalid align prefix', () => {
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ points, Point, macro, part }) => {
|
|
|
|
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
|
|
|
macro('title', {
|
|
|
|
at: points.anchor,
|
|
|
|
nr: 3,
|
|
|
|
title: 'unitTest',
|
|
|
|
align: 'invalidprefix',
|
|
|
|
})
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
|
|
|
plugins: [annotationsPlugin],
|
|
|
|
}
|
|
|
|
const Pattern = new Design({
|
|
|
|
data: { name: 'testPattern', version: 99 },
|
|
|
|
parts: [part],
|
|
|
|
})
|
|
|
|
const pattern = new Pattern()
|
|
|
|
pattern.draft().render()
|
|
|
|
let p = pattern.parts[0].test.points.__titleNr
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold left')
|
|
|
|
p = pattern.parts[0].test.points.__titleName
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold left')
|
|
|
|
p = pattern.parts[0].test.points.__titlePattern
|
|
|
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note left')
|
|
|
|
})
|
2022-09-07 10:57:47 +02:00
|
|
|
})
|