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

272 lines
9.2 KiB
JavaScript
Raw Normal View History

import chai from 'chai'
2022-09-07 10:57:47 +02:00
import { Design } from '@freesewing/core'
import { annotationsPlugin } from '../src/index.mjs'
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',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(-12, -34)
2022-09-12 15:42:50 +02:00
macro('title', {
at: points.anchor,
nr: 3,
title: 'unitTest',
})
return part
2022-09-12 15:42:50 +02:00
},
plugins: [annotationsPlugin],
2022-09-12 15:42:50 +02:00
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
2022-09-12 15:42:50 +02:00
const pattern = new Pattern()
pattern.draft().render()
let p = pattern.parts[0].test.points.__macro_title_title_nr
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')
p = pattern.parts[0].test.points.__macro_title_title_title
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')
2024-01-07 16:06:48 +01:00
expect(p.attributes.get('data-text-y')).to.equal('-18')
p = pattern.parts[0].test.points.__macro_title_title_name
2024-01-07 16:06:48 +01:00
expect(p.attributes.get('data-text')).to.equal('FreeSewing TestPattern v99 ( ephemeral )')
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')
2024-01-07 16:06:48 +01:00
expect(p.attributes.get('data-text-y')).to.equal('-10')
p = pattern.parts[0].test.points.__macro_title_title_date
expect(p.attributes.get('data-text')).to.include(', 202')
2022-09-07 10:57:47 +02: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',
draft: ({ points, Point, macro, part }) => {
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,
})
return part
2022-09-12 15:42:50 +02:00
},
plugins: [annotationsPlugin],
2022-09-12 15:42:50 +02:00
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
2022-09-12 15:42:50 +02:00
const pattern = new Pattern()
pattern.draft().render()
let p = pattern.parts[0].test.points.__macro_title_title_nr
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')
})
it('Should run the title macro with a custom ID', () => {
2022-09-12 15:42:50 +02:00
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
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',
id: 'foo',
2022-09-12 15:42:50 +02:00
})
return part
2022-09-12 15:42:50 +02:00
},
plugins: [annotationsPlugin],
2022-09-12 15:42:50 +02:00
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
2022-09-12 15:42:50 +02:00
const pattern = new Pattern()
pattern.draft().render()
let p = pattern.parts[0].test.points.__macro_title_foo_nr
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')
p = pattern.parts[0].test.points.__macro_title_foo_title
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')
2024-01-07 16:06:48 +01:00
expect(p.attributes.get('data-text-y')).to.equal('-18')
p = pattern.parts[0].test.points.__macro_title_foo_name
2024-01-07 16:06:48 +01:00
expect(p.attributes.get('data-text')).to.equal('FreeSewing TestPattern v99 ( ephemeral )')
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')
2024-01-07 16:06:48 +01:00
expect(p.attributes.get('data-text-y')).to.equal('-10')
2022-09-07 10:57:47 +02:00
})
2023-05-04 16:24:29 -07:00
it('Should run the title macro with custom alignment', () => {
2023-05-04 16:24:29 -07:00
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',
id: 'left',
2023-05-04 16:24:29 -07:00
})
macro('title', {
at: points.anchor,
nr: 3,
title: 'unitTest',
align: 'right',
id: 'right',
2023-05-04 16:24:29 -07:00
})
macro('title', {
at: points.anchor,
nr: 3,
title: 'unitTest',
align: 'center',
id: 'center',
2023-05-04 16:24:29 -07:00
})
return part
},
plugins: [annotationsPlugin],
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
2023-05-04 16:24:29 -07:00
const pattern = new Pattern()
pattern.draft().render()
for (const align of ['left', 'center', 'right']) {
let p = pattern.parts[0].test.points[`__macro_title_${align}_nr`]
expect(p.attributes.get('data-text-class')).to.equal(`text-4xl fill-note font-bold ${align}`)
p = pattern.parts[0].test.points[`__macro_title_${align}_name`]
expect(p.attributes.get('data-text-class')).to.equal(`fill-note ${align}`)
p = pattern.parts[0].test.points[`__macro_title_${align}_title`]
expect(p.attributes.get('data-text-class')).to.equal(
`text-lg fill-current font-bold ${align}`
)
}
2023-05-04 16:24:29 -07:00
})
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],
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
2023-05-04 16:24:29 -07:00
const pattern = new Pattern()
pattern.draft().render()
let p = pattern.parts[0].test.points
expect(p.__macro_title_title_nr.attributes.get('data-text-class')).to.equal(
'text-4xl fill-note font-bold left'
)
expect(p.__macro_title_title_title.attributes.get('data-text-class')).to.equal(
'text-lg fill-current font-bold left'
)
expect(p.__macro_title_title_name.attributes.get('data-text-class')).to.equal('fill-note left')
2023-05-04 16:24:29 -07:00
})
2024-01-07 16:06:48 +01:00
it('Should run the title macro with notes', () => {
const notes = 'These are the notes\nHere are some more notes'
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(-12, -34)
macro('title', {
at: points.anchor,
nr: 3,
title: 'unitTest',
notes,
})
return part
},
plugins: [annotationsPlugin],
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
const pattern = new Pattern()
pattern.draft().render()
let p = pattern.parts[0].test.points.__macro_title_title_notes
expect(p.attributes.get('data-text')).to.equal(notes)
})
it('Should run the title macro with a custom brand', () => {
const brand = 'Bazooka Patterns'
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(-12, -34)
macro('title', {
at: points.anchor,
nr: 3,
title: 'unitTest',
brand,
id: 'foo',
})
return part
},
plugins: [annotationsPlugin],
}
// Note that we're not loading core plugins but the local plugin
const Pattern = new Design({
data: { name: 'testPattern', version: 99 },
parts: [part],
noCorePlugins: true,
})
const pattern = new Pattern()
pattern.draft().render()
let p = pattern.parts[0].test.points.__macro_title_foo_name
expect(p.attributes.get('data-text')).to.equal(`${brand} TestPattern v99 ( ephemeral )`)
})
2022-09-07 10:57:47 +02:00
})