From 8a5141584c3fb6389107b588edcff62c9c2bbffa Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Wed, 7 Sep 2022 10:57:47 +0200 Subject: [PATCH] chore: Fixed plugin tests --- plugins/plugin-bust/tests/plugin.test.mjs | 3 +- plugins/plugin-buttons/tests/plugin.test.mjs | 3 +- plugins/plugin-i18n/tests/plugin.test.mjs | 3 +- plugins/plugin-logo/tests/plugin.test.mjs | 3 +- .../plugin-measurements/tests/plugin.test.mjs | 3 +- plugins/plugin-mirror/tests/plugin.test.mjs | 3 +- plugins/plugin-notches/tests/plugin.test.mjs | 3 +- plugins/plugin-scalebox/src/scalebox.mjs | 4 +- plugins/plugin-scalebox/tests/plugin.test.mjs | 10 +- plugins/plugin-theme/tests/plugin.test.mjs | 3 +- plugins/plugin-title/src/index.mjs | 14 +- plugins/plugin-title/tests/plugin.test.mjs | 180 +++++++++--------- plugins/plugin-title/tests/shared.test.mjs | 1 - .../tests/plugin.test.mjs | 3 +- 14 files changed, 122 insertions(+), 114 deletions(-) diff --git a/plugins/plugin-bust/tests/plugin.test.mjs b/plugins/plugin-bust/tests/plugin.test.mjs index 8f9f5381ad5..8cd45ace22f 100644 --- a/plugins/plugin-bust/tests/plugin.test.mjs +++ b/plugins/plugin-bust/tests/plugin.test.mjs @@ -1,5 +1,5 @@ import chai from 'chai' -import { Design, Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from './dist/index.mjs' const expect = chai.expect @@ -9,6 +9,7 @@ const measurements = { highBust: 90, } +const Pattern = new Design() const pattern = new Pattern({ measurements } ).use(plugin) pattern.apply({measurements}).draft().render() diff --git a/plugins/plugin-buttons/tests/plugin.test.mjs b/plugins/plugin-buttons/tests/plugin.test.mjs index 81fad3154c6..225e4406440 100644 --- a/plugins/plugin-buttons/tests/plugin.test.mjs +++ b/plugins/plugin-buttons/tests/plugin.test.mjs @@ -1,9 +1,10 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from './dist/index.mjs' const expect = chai.expect +const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.draft().render() diff --git a/plugins/plugin-i18n/tests/plugin.test.mjs b/plugins/plugin-i18n/tests/plugin.test.mjs index 623cd417932..ff8ce3ac322 100644 --- a/plugins/plugin-i18n/tests/plugin.test.mjs +++ b/plugins/plugin-i18n/tests/plugin.test.mjs @@ -1,5 +1,5 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect @@ -14,6 +14,7 @@ const content = { describe('I18n Plugin Tests', () => { it('Should translate text on insert', () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin, content) pattern.parts.test = new pattern.Part() pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr( diff --git a/plugins/plugin-logo/tests/plugin.test.mjs b/plugins/plugin-logo/tests/plugin.test.mjs index f13482c0610..89a54129c73 100644 --- a/plugins/plugin-logo/tests/plugin.test.mjs +++ b/plugins/plugin-logo/tests/plugin.test.mjs @@ -1,11 +1,12 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect describe('Logo Plugin Tests', () => { it('Should import style and defs', () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.draft().render() expect(pattern.svg.defs).to.contain( diff --git a/plugins/plugin-measurements/tests/plugin.test.mjs b/plugins/plugin-measurements/tests/plugin.test.mjs index 0d8d01ebc9e..245e6662889 100644 --- a/plugins/plugin-measurements/tests/plugin.test.mjs +++ b/plugins/plugin-measurements/tests/plugin.test.mjs @@ -1,5 +1,5 @@ import chai from 'chai' -import { Design, Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from './dist/index.mjs' const expect = chai.expect @@ -13,6 +13,7 @@ const measurements = { crossSeamFront: 42 } +const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.apply({ measurements } ).draft() diff --git a/plugins/plugin-mirror/tests/plugin.test.mjs b/plugins/plugin-mirror/tests/plugin.test.mjs index 26a33f6e758..62c5b2fe50b 100644 --- a/plugins/plugin-mirror/tests/plugin.test.mjs +++ b/plugins/plugin-mirror/tests/plugin.test.mjs @@ -1,10 +1,11 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect describe('Mirror Plugin Tests', () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.parts.test = new pattern.Part() pattern.parts.test.points.mirrorA = new pattern.Point(-100, -100) diff --git a/plugins/plugin-notches/tests/plugin.test.mjs b/plugins/plugin-notches/tests/plugin.test.mjs index 0f437e0b89e..b6298c5b953 100644 --- a/plugins/plugin-notches/tests/plugin.test.mjs +++ b/plugins/plugin-notches/tests/plugin.test.mjs @@ -1,9 +1,10 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect +const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.draft().render() diff --git a/plugins/plugin-scalebox/src/scalebox.mjs b/plugins/plugin-scalebox/src/scalebox.mjs index 0dd20eafbb3..f9cc124f39d 100644 --- a/plugins/plugin-scalebox/src/scalebox.mjs +++ b/plugins/plugin-scalebox/src/scalebox.mjs @@ -154,10 +154,10 @@ export function scalebox(so) { if (so.title) this.points.__scaleboxTitle.attributes.set('data-text', so.title) else { let name = this.context.config?.data?.name || 'No Name' - name = name.replace('@freesewing/', '') + if (name.indexOf('@freesewing/') !== -1) name = name.replace('@freesewing/', '') this.points.__scaleboxTitle = this.points.__scaleboxTitle .attr('data-text', name) - .attr('data-text', 'v' + + .attr('data-text', 'v' + this.context.config?.data?.version || 'No Version') } this.points.__scaleboxTitle.attributes.add('data-text-class', 'text-lg') diff --git a/plugins/plugin-scalebox/tests/plugin.test.mjs b/plugins/plugin-scalebox/tests/plugin.test.mjs index 32ecdfa7991..242ae27efcc 100644 --- a/plugins/plugin-scalebox/tests/plugin.test.mjs +++ b/plugins/plugin-scalebox/tests/plugin.test.mjs @@ -1,11 +1,12 @@ import chai from 'chai' -import { Pattern, round } from '@freesewing/core' +import { Design, round } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect describe('Scalebox Plugin Tests', () => { it("Should run the default scalebox macro", () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.parts.test = new pattern.Part(); pattern.parts.test.points.anchor = new pattern.Point(100, 200); @@ -73,6 +74,7 @@ describe('Scalebox Plugin Tests', () => { }); it("Should run the scalebox macro with rotation", () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.parts.test = new pattern.Part(); pattern.parts.test.points.anchor = new pattern.Point(100, 200); @@ -113,6 +115,7 @@ describe('Scalebox Plugin Tests', () => { }); it("Should run the scalebox macro with default text", () => { + const Pattern = new Design({ data: { version: '1.2.3', name: 'test' }}) const pattern = new Pattern().use(plugin) pattern.parts.test = new pattern.Part(); pattern.parts.test.points.anchor = new pattern.Point(100, 200); @@ -124,7 +127,7 @@ describe('Scalebox Plugin Tests', () => { expect(p.get("data-text")).to.equal("FreeSewing"); expect(p.get("data-text-class")).to.equal("text-sm"); p = pattern.parts.test.points.__scaleboxTitle.attributes; - expect(p.get("data-text")).to.equal(" vundefined"); + expect(p.get("data-text")).to.equal("test v1.2.3"); expect(p.get("data-text-class")).to.equal("text-lg"); p = pattern.parts.test.points.__scaleboxText.attributes; expect(p.get("data-text-class")).to.equal("text-xs"); @@ -133,6 +136,7 @@ describe('Scalebox Plugin Tests', () => { }); it("Should run the scalebox macro with custom text", () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.parts.test = new pattern.Part(); pattern.parts.test.points.anchor = new pattern.Point(100, 200); @@ -156,6 +160,7 @@ describe('Scalebox Plugin Tests', () => { }) it("Should apply scale to the scalebox macro", () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.settings.scale = 0.5 pattern.parts.test = new pattern.Part(); @@ -188,6 +193,7 @@ describe('Scalebox Plugin Tests', () => { }); it("Should apply scale to the miniscale macro", () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.settings.scale = 0.5 pattern.parts.test = new pattern.Part(); diff --git a/plugins/plugin-theme/tests/plugin.test.mjs b/plugins/plugin-theme/tests/plugin.test.mjs index 451d73ba7f3..8a9cd48e1b6 100644 --- a/plugins/plugin-theme/tests/plugin.test.mjs +++ b/plugins/plugin-theme/tests/plugin.test.mjs @@ -1,10 +1,11 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect describe('Theme Plugin Tests', () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.apply({ paperless: true }) pattern.draft().render() diff --git a/plugins/plugin-title/src/index.mjs b/plugins/plugin-title/src/index.mjs index 6de6342bf53..eb537f5569e 100644 --- a/plugins/plugin-title/src/index.mjs +++ b/plugins/plugin-title/src/index.mjs @@ -100,10 +100,15 @@ export const plugin = { if (mins < 10) mins = `0${mins}` this.points[`_${prefix}_exportDate`] = so.at .shift(-90 - so.rotation, shift * so.scale) - .attr('data-text', now.toLocaleDateString( - this.context.settings.locale || 'en', - { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric'} - )) + .attr( + 'data-text', + now.toLocaleDateString(this.context.settings.locale || 'en', { + weekday: 'long', + year: 'numeric', + month: 'short', + day: 'numeric', + }) + ) .attr('data-text', `@ ${hours}:${mins}`) .attr('data-text-class', 'text-sm') .attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale))) @@ -114,4 +119,3 @@ export const plugin = { // More specifically named exports export const titlePlugin = plugin export const pluginTitle = plugin - diff --git a/plugins/plugin-title/tests/plugin.test.mjs b/plugins/plugin-title/tests/plugin.test.mjs index f4c8949c821..5d97a4c0a58 100644 --- a/plugins/plugin-title/tests/plugin.test.mjs +++ b/plugins/plugin-title/tests/plugin.test.mjs @@ -1,112 +1,102 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from './dist/index.mjs' const expect = chai.expect describe('Title Plugin Tests', () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.draft().render() - it("Should run the title macro", () => { - let pattern = new Pattern({ name: "testPattern", version: 99 }); - 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", { + 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', { at: pattern.parts.test.points.anchor, nr: 3, - 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"); - }); + 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') + }) - it("Should run the title macro with append flag", () => { - let pattern = new Pattern({ name: "testPattern", version: 99 }); - 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", { + 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', { at: pattern.parts.test.points.anchor, nr: 3, - 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"); - }); + 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') + }) - it("Should run the title macro with point prefix", () => { - let pattern = new Pattern({ name: "testPattern", version: 99 }); - 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", { + 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', { at: pattern.parts.test.points.anchor, nr: 3, - 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"); - }); -}); + 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') + }) +}) diff --git a/plugins/plugin-title/tests/shared.test.mjs b/plugins/plugin-title/tests/shared.test.mjs index fdf846844b0..ea9a6b5c890 100644 --- a/plugins/plugin-title/tests/shared.test.mjs +++ b/plugins/plugin-title/tests/shared.test.mjs @@ -4,4 +4,3 @@ import { sharedPluginTests } from '../../../tests/plugins/shared.mjs' // Run shared tests sharedPluginTests(plugin) - diff --git a/plugins/plugin-versionfree-svg/tests/plugin.test.mjs b/plugins/plugin-versionfree-svg/tests/plugin.test.mjs index 045889be135..a9aae599349 100644 --- a/plugins/plugin-versionfree-svg/tests/plugin.test.mjs +++ b/plugins/plugin-versionfree-svg/tests/plugin.test.mjs @@ -1,10 +1,11 @@ import chai from 'chai' -import { Pattern } from '@freesewing/core' +import { Design } from '@freesewing/core' import { plugin } from '../dist/index.mjs' const expect = chai.expect describe('Versionfree Plugin Tests', () => { + const Pattern = new Design() const pattern = new Pattern().use(plugin) pattern.draft().render() it('Should remove version numbers from SVG attributes', () => {