diff --git a/plugins/plugin-annotations/tests/bartack.test.mjs b/plugins/plugin-annotations/tests/bartack.test.mjs new file mode 100644 index 00000000000..67bed27ee89 --- /dev/null +++ b/plugins/plugin-annotations/tests/bartack.test.mjs @@ -0,0 +1,291 @@ +import chai from 'chai' +import { round, Design } from '@freesewing/core' +import { annotationPlugin } from '../src/index.mjs' + +const expect = chai.expect + +describe('Bartack plugin Tests', () => { + it('draws a default bartack from a point', function () { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + macro('bartack', { + anchor: points.from, + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[0].to.x).to.equal(10) + expect(c.ops[0].to.y).to.equal(21.5) + expect(c.ops[1].type).to.equal('line') + expect(c.ops[1].to.x).to.equal(10) + expect(c.ops[1].to.y).to.equal(21.5) + expect(c.ops[2].to.x).to.equal(10) + expect(c.ops[2].to.y).to.equal(18.5) + expect(c.ops[3].to.x).to.equal(11) + expect(c.ops[3].to.y).to.equal(21.5) + expect(c.ops[4].to.x).to.equal(11) + expect(c.ops[4].to.y).to.equal(18.5) + expect(c.ops).to.have.lengthOf(31) + }) + + it('draws a bartack along a path', function () { + const part = { + name: 'test', + draft: ({ Point, points, Path, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 30) + macro('bartackAlong', { + path: new Path().move(points.from).line(points.to), + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[0].to.x).to.equal(8.5) + expect(c.ops[0].to.y).to.equal(20) + expect(c.ops[1].type).to.equal('line') + expect(c.ops[1].to.x).to.equal(8.5) + expect(c.ops[1].to.y).to.equal(20) + expect(c.ops[2].to.x).to.equal(11.5) + expect(c.ops[2].to.y).to.equal(20) + expect(c.ops[3].to.x).to.equal(8.5) + expect(c.ops[3].to.y).to.equal(21) + expect(c.ops[4].to.x).to.equal(11.5) + expect(c.ops[4].to.y).to.equal(21) + expect(c.ops).to.have.lengthOf(21) + }) + + it('can be called using the bartackFractionAlong syntax', function () { + const part = { + name: 'test', + draft: ({ Point, points, Path, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 100) + macro('bartackAlong', { + path: new Path().move(points.from).line(points.to), + start: 0.2, + end: 0.8, + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(round(c.ops[0].to.x)).to.equal(8.5) + expect(c.ops[0].to.y).to.equal(20) + expect(c.ops[1].type).to.equal('line') + expect(round(c.ops[1].to.x)).to.equal(8.5) + expect(c.ops[1].to.y).to.equal(20) + expect(round(c.ops[2].to.x)).to.equal(11.5) + expect(c.ops[2].to.y).to.equal(20) + expect(round(c.ops[3].to.x)).to.equal(8.5) + expect(c.ops[3].to.y).to.equal(21) + expect(round(c.ops[4].to.x)).to.equal(11.5) + expect(c.ops[4].to.y).to.equal(21) + expect(c.ops).to.have.lengthOf(161) + }) + + it('can be called using the bartackFractionAlong syntax', function () { + const part = { + name: 'test', + draft: ({ Point, points, Path, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 100) + macro('bartackFractionAlong', { + path: new Path().move(points.from).line(points.to), + start: 0.2, + end: 0.8, + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(round(c.ops[0].to.x)).to.equal(8.5) + expect(c.ops[0].to.y).to.equal(36) + expect(c.ops[1].type).to.equal('line') + expect(round(c.ops[1].to.x)).to.equal(8.5) + expect(c.ops[1].to.y).to.equal(36) + expect(round(c.ops[2].to.x)).to.equal(11.5) + expect(c.ops[2].to.y).to.equal(36) + expect(round(c.ops[3].to.x)).to.equal(8.5) + expect(c.ops[3].to.y).to.equal(37) + expect(round(c.ops[4].to.x)).to.equal(11.5) + expect(c.ops[4].to.y).to.equal(37) + expect(c.ops).to.have.lengthOf(97) + }) + + it('has configurable length', function () { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + macro('bartack', { + anchor: points.from, + length: 20, + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[0].to.x).to.equal(10) + expect(c.ops[0].to.y).to.equal(21.5) + expect(c.ops[1].type).to.equal('line') + expect(c.ops[1].to.x).to.equal(10) + expect(c.ops[1].to.y).to.equal(21.5) + expect(c.ops[2].to.x).to.equal(10) + expect(c.ops[2].to.y).to.equal(18.5) + expect(c.ops[3].to.x).to.equal(11) + expect(c.ops[3].to.y).to.equal(21.5) + expect(c.ops[4].to.x).to.equal(11) + expect(c.ops[4].to.y).to.equal(18.5) + expect(c.ops).to.have.lengthOf(41) + }) + + it('has configurable width', function () { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + macro('bartack', { + anchor: points.from, + width: 5, + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[0].to.x).to.equal(10) + expect(c.ops[0].to.y).to.equal(22.5) + expect(c.ops[1].type).to.equal('line') + expect(c.ops[1].to.x).to.equal(10) + expect(c.ops[1].to.y).to.equal(22.5) + expect(c.ops[2].to.x).to.equal(10) + expect(c.ops[2].to.y).to.equal(17.5) + expect(round(c.ops[3].to.x)).to.equal(11.67) + expect(c.ops[3].to.y).to.equal(22.5) + expect(round(c.ops[4].to.x)).to.equal(11.67) + expect(c.ops[4].to.y).to.equal(17.5) + expect(c.ops).to.have.lengthOf(19) + }) + + it('has configurable angle', function () { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + macro('bartack', { + anchor: points.from, + angle: 45, + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + expect(c.ops[0].type).to.equal('move') + expect(round(c.ops[0].to.x)).to.equal(11.06) + expect(round(c.ops[0].to.y)).to.equal(21.06) + expect(c.ops[1].type).to.equal('line') + expect(round(c.ops[1].to.x)).to.equal(11.06) + expect(round(c.ops[1].to.y)).to.equal(21.06) + expect(round(c.ops[2].to.x)).to.equal(8.94) + expect(round(c.ops[2].to.y)).to.equal(18.94) + expect(round(c.ops[3].to.x)).to.equal(11.72) + expect(round(c.ops[3].to.y)).to.equal(20.4) + expect(round(c.ops[4].to.x)).to.equal(9.6) + expect(round(c.ops[4].to.y)).to.equal(18.28) + expect(c.ops).to.have.lengthOf(33) + }) + + it('has configurable suffix', function () { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + macro('bartack', { + anchor: points.from, + suffix: 'foo', + }) + + part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.bartackfoo + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + }) + + it('has configurable prefix', function () { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + macro('bartack', { + anchor: points.from, + prefix: 'foo', + }) + + return part + }, + plugins: [annotationPlugin], + } + const design = new Design({ parts: [part] }) + const pattern = new design() + pattern.draft() + const c = pattern.parts[0].test.paths.foobartack + expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark') + }) +}) diff --git a/plugins/plugin-annotations/tests/buttons.test.mjs b/plugins/plugin-annotations/tests/buttons.test.mjs new file mode 100644 index 00000000000..dfc28f4945e --- /dev/null +++ b/plugins/plugin-annotations/tests/buttons.test.mjs @@ -0,0 +1,113 @@ +import chai from 'chai' +import { Design } from '@freesewing/core' +import { annotationPlugin } from '../src/index.mjs' + +const expect = chai.expect + +const Pattern = new Design() +const pattern = new Pattern().use(annotationPlugin) +pattern.draft().render() + +describe('Buttons Plugin Test', () => { + for (const snippet of ['button', 'buttonhole', 'snap-stud', 'snap-socket']) { + it(`Should add the ${snippet} snippet to defs`, () => { + expect(pattern.svg.defs.indexOf(``)).to.not.equal(-1) + }) + } + + it('Draws a button on an anchor point', () => { + const part = { + name: 'test', + draft: ({ points, Point, snippets, Snippet, part }) => { + points.anchor = new Point(10, 20) + snippets.button = new Snippet('button', points.anchor) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const svg = new Pattern().draft().render() + expect(svg).to.contain(' { + const part = { + name: 'test', + draft: ({ points, Point, snippets, Snippet, part }) => { + points.anchor = new Point(10, 20) + snippets.button = new Snippet('buttonhole', points.anchor) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const svg = new Pattern().draft().render() + expect(svg).to.contain(' { + const part = { + name: 'test', + draft: ({ points, Point, snippets, Snippet, part }) => { + points.anchor = new Point(10, 20) + snippets.button = new Snippet('buttonhole-start', points.anchor) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const svg = new Pattern().draft().render() + expect(svg).to.contain(' { + const part = { + name: 'test', + draft: ({ points, Point, snippets, Snippet, part }) => { + points.anchor = new Point(10, 20) + snippets.button = new Snippet('buttonhole-end', points.anchor) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const svg = new Pattern().draft().render() + expect(svg).to.contain(' { + const part = { + name: 'test', + draft: ({ points, Point, snippets, Snippet, part }) => { + points.anchor = new Point(10, 20) + snippets.button = new Snippet('snap-stud', points.anchor) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const svg = new Pattern().draft().render() + expect(svg).to.contain(' { + const part = { + name: 'test', + draft: ({ points, Point, snippets, Snippet, part }) => { + points.anchor = new Point(10, 20) + snippets.button = new Snippet('snap-socket', points.anchor) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const svg = new Pattern().draft().render() + expect(svg).to.contain(' { + it('Should run the default crossbox macro', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 10) + points.to = new Point(30, 30) + macro('crossbox', { + from: points.from, + to: points.to, + }) + + return part + }, + plugins: [annotationPlugin], + } + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) + const pattern = new Test() + pattern.draft() + var c = pattern.parts[0].test.paths['1crossBox'] + expect(c.attributes.get('class')).to.equal('lining dotted stroke-sm') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[1].type).to.equal('line') + expect(c.ops[2].type).to.equal('line') + expect(c.ops[3].type).to.equal('line') + expect(c.ops[4].type).to.equal('line') + expect(round(c.ops[0].to.x)).to.equal(10) + expect(round(c.ops[0].to.y)).to.equal(10) + expect(round(c.ops[1].to.x)).to.equal(30) + expect(round(c.ops[1].to.y)).to.equal(10) + expect(round(c.ops[2].to.x)).to.equal(30) + expect(round(c.ops[2].to.y)).to.equal(30) + expect(round(c.ops[3].to.x)).to.equal(10) + expect(round(c.ops[3].to.y)).to.equal(30) + expect(round(c.ops[4].to.x)).to.equal(10) + expect(round(c.ops[4].to.y)).to.equal(10) + c = pattern.parts[0].test.paths['1_topCross'] + expect(c.attributes.get('class')).to.equal('lining dotted stroke-sm') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[1].type).to.equal('line') + expect(c.ops[2].type).to.equal('line') + expect(c.ops[3].type).to.equal('line') + expect(c.ops[4].type).to.equal('line') + expect(c.ops[5].type).to.equal('line') + expect(c.ops[6].type).to.equal('move') + expect(c.ops[7].type).to.equal('line') + expect(round(c.ops[0].to.x)).to.equal(12) + expect(round(c.ops[0].to.y)).to.equal(12) + expect(round(c.ops[1].to.x)).to.equal(28) + expect(round(c.ops[1].to.y)).to.equal(28) + expect(round(c.ops[2].to.x)).to.equal(28) + expect(round(c.ops[2].to.y)).to.equal(12) + expect(round(c.ops[3].to.x)).to.equal(12) + expect(round(c.ops[3].to.y)).to.equal(28) + expect(round(c.ops[4].to.x)).to.equal(12) + expect(round(c.ops[4].to.y)).to.equal(12) + expect(round(c.ops[5].to.x)).to.equal(28) + expect(round(c.ops[5].to.y)).to.equal(12) + expect(round(c.ops[6].to.x)).to.equal(28) + expect(round(c.ops[6].to.y)).to.equal(28) + expect(round(c.ops[7].to.x)).to.equal(12) + expect(round(c.ops[7].to.y)).to.equal(28) + }) + + it('Should run the crossbox macro with text', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 10) + points.to = new Point(30, 30) + macro('crossbox', { + from: points.from, + to: points.to, + text: 'test', + }) + + return part + }, + plugins: [annotationPlugin], + } + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) + const pattern = new Test() + pattern.draft() + const c = pattern.parts[0].test.points.textAnchor + expect(c.attributes.get('data-text')).to.equal('test') + }) +}) diff --git a/plugins/plugin-annotations/tests/plugin.test.mjs b/plugins/plugin-annotations/tests/cutonfold.test.mjs similarity index 86% rename from plugins/plugin-annotations/tests/plugin.test.mjs rename to plugins/plugin-annotations/tests/cutonfold.test.mjs index d39ae8b045e..466a885b70f 100644 --- a/plugins/plugin-annotations/tests/plugin.test.mjs +++ b/plugins/plugin-annotations/tests/cutonfold.test.mjs @@ -1,6 +1,6 @@ import chai from 'chai' import { Design, round } from '@freesewing/core' -import { plugin } from '../src/index.mjs' +import { annotationPlugin } from '../src/index.mjs' const expect = chai.expect @@ -18,12 +18,12 @@ describe('Cutonfold Plugin Tests', () => { return part }, - plugins: [plugin], + plugins: [annotationPlugin], } - const Test = new Design({ plugins: [plugin], parts: [part] }) + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) const pattern = new Test() pattern.draft() - const c = pattern.parts[0].test.paths.cutonfold + const c = pattern.parts[0].test.paths.cutonfoldCutonfold expect(c.attributes.get('class')).to.equal('note') expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)') expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)') @@ -57,12 +57,12 @@ describe('Cutonfold Plugin Tests', () => { return part }, - plugins: [plugin], + plugins: [annotationPlugin], } - const Test = new Design({ plugins: [plugin], parts: [part] }) + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) const pattern = new Test() pattern.draft() - const c = pattern.parts[0].test.paths.cutonfold + const c = pattern.parts[0].test.paths.cutonfoldCutonfold expect(c.attributes.get('data-text')).to.equal('cutOnFoldAndGrainline') }) @@ -80,12 +80,12 @@ describe('Cutonfold Plugin Tests', () => { return part }, - plugins: [plugin], + plugins: [annotationPlugin], } - const Test = new Design({ plugins: [plugin], parts: [part] }) + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) const pattern = new Test() pattern.draft() - let c = pattern.parts[0].test.paths.cutonfold + let c = pattern.parts[0].test.paths.cutonfoldCutonfold expect(c.attributes.get('class')).to.equal('note') expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)') expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)') @@ -119,12 +119,12 @@ describe('Cutonfold Plugin Tests', () => { return part }, - plugins: [plugin], + plugins: [annotationPlugin], } - const Test = new Design({ plugins: [plugin], parts: [part] }) + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) const pattern = new Test() pattern.draft() - let c = pattern.parts[0].test.paths.cutonfold + let c = pattern.parts[0].test.paths.cutonfoldCutonfold expect(c.attributes.get('class')).to.equal('note') expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)') expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)') diff --git a/plugins/plugin-annotations/tests/grainline.test.mjs b/plugins/plugin-annotations/tests/grainline.test.mjs new file mode 100644 index 00000000000..4870f3b086d --- /dev/null +++ b/plugins/plugin-annotations/tests/grainline.test.mjs @@ -0,0 +1,39 @@ +import chai from 'chai' +import { round, Design } from '@freesewing/core' +import { annotationPlugin } from '../src/index.mjs' + +const expect = chai.expect + +describe('Grainline Plugin Tests', () => { + it('Should run the default grainline macro', () => { + const part = { + name: 'test', + draft: ({ points, Point, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 230) + macro('grainline', { + from: points.from, + to: points.to, + }) + + return part + }, + plugins: [annotationPlugin], + } + const Pattern = new Design({ parts: [part] }) + const pattern = new Pattern() + pattern.draft() + const c = pattern.parts[0].test.paths.grainline + expect(c.attributes.get('class')).to.equal('note') + expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)') + expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)') + expect(c.attributes.get('data-text')).to.equal('grainline') + expect(c.attributes.get('data-text-class')).to.equal('center fill-note') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[1].type).to.equal('line') + expect(round(c.ops[0].to.x)).to.equal(10) + expect(round(c.ops[0].to.y)).to.equal(30.5) + expect(round(c.ops[1].to.x)).to.equal(10) + expect(round(c.ops[1].to.y)).to.equal(219.5) + }) +}) diff --git a/plugins/plugin-annotations/tests/logo.test.mjs b/plugins/plugin-annotations/tests/logo.test.mjs new file mode 100644 index 00000000000..b1a27ac11e2 --- /dev/null +++ b/plugins/plugin-annotations/tests/logo.test.mjs @@ -0,0 +1,16 @@ +import chai from 'chai' +import { Design } from '@freesewing/core' +import { annotationPlugin } from '../src/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(annotationPlugin) + pattern.draft().render() + expect(pattern.svg.defs).to.contain( + '