diff --git a/designs/test/tests/shared.test.mjs b/designs/test/tests/shared.test.mjs new file mode 100644 index 00000000000..46b43f3e815 --- /dev/null +++ b/designs/test/tests/shared.test.mjs @@ -0,0 +1,16 @@ +// This file is auto-generated | Any changes you make will be overwritten. +import { Test } from '../src/index.mjs' + +// Shared tests +import { testPatternConfig } from '../../../tests/designs/config.mjs' +import { testPatternDrafting } from '../../../tests/designs/drafting.mjs' +import { testPatternSampling } from '../../../tests/designs/sampling.mjs' + +// Test config +testPatternConfig(Test) + +// Test drafting - Change the second parameter to `true` to log errors +testPatternDrafting(Test, false) + +// Test sampling - Change the second parameter to `true` to log errors +testPatternSampling(Test, false) diff --git a/plugins/plugin-annotations/src/pleat.mjs b/plugins/plugin-annotations/src/pleat.mjs index 4eb6957b278..e8ca2be9bc5 100644 --- a/plugins/plugin-annotations/src/pleat.mjs +++ b/plugins/plugin-annotations/src/pleat.mjs @@ -46,11 +46,11 @@ export const pleat = { paths[so.prefix + 'PleatFrom'] = new Path() .move(points[so.prefix + 'From']) .line(points[so.prefix + 'FromIn']) - .attr('class', 'note ' + (so.reverse ? 'dashed' : '')) + .attr('class', 'note' + (so.reverse ? ' dashed' : '')) paths[so.prefix + 'PleatTo'] = new Path() .move(points[so.prefix + 'To']) .line(points[so.prefix + 'ToIn']) - .attr('class', 'note ' + (so.reverse ? '' : 'dashed')) + .attr('class', 'note' + (so.reverse ? '' : ' dashed')) paths[so.prefix + 'PleatArrow'] = new Path() .move( points[so.prefix + (so.reverse ? 'To' : 'From')].shiftFractionTowards( diff --git a/plugins/plugin-annotations/tests/pleat.test.mjs b/plugins/plugin-annotations/tests/pleat.test.mjs new file mode 100644 index 00000000000..1c316047ada --- /dev/null +++ b/plugins/plugin-annotations/tests/pleat.test.mjs @@ -0,0 +1,82 @@ +import chai from 'chai' +import { Design, round } from '@freesewing/core' +import { annotationPlugin } from '../src/index.mjs' + +const expect = chai.expect + +describe('Pleat Plugin Tests', () => { + it('Should run the default pleat macro', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 220) + macro('pleat', { + 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.pleatPleatFrom + expect(c.attributes.get('class')).to.equal('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(20) + expect(round(c.ops[1].to.x)).to.equal(45) + expect(round(c.ops[1].to.y)).to.equal(20) + c = pattern.parts[0].test.paths.pleatPleatTo + expect(c.attributes.get('class')).to.equal('note dashed') + 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(220) + expect(round(c.ops[1].to.x)).to.equal(45) + expect(round(c.ops[1].to.y)).to.equal(220) + c = pattern.parts[0].test.paths.pleatPleatArrow + expect(c.attributes.get('class')).to.equal('note') + expect(c.attributes.get('marker-end')).to.equal('url(#pleatTo)') + 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(18.75) + expect(round(c.ops[0].to.y)).to.equal(20) + expect(round(c.ops[1].to.x)).to.equal(18.75) + expect(round(c.ops[1].to.y)).to.equal(220) + }) + + it('Should run the pleat/reverse macro', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 220) + macro('pleat', { + from: points.from, + to: points.to, + reverse: true, + }) + + 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.pleatPleatFrom + expect(c.attributes.get('class')).to.equal('note dashed') + c = pattern.parts[0].test.paths.pleatPleatTo + expect(c.attributes.get('class')).to.equal('note') + c = pattern.parts[0].test.paths.pleatPleatArrow + expect(round(c.ops[0].to.x)).to.equal(18.75) + expect(round(c.ops[0].to.y)).to.equal(220) + expect(round(c.ops[1].to.x)).to.equal(18.75) + expect(round(c.ops[1].to.y)).to.equal(20) + }) +}) diff --git a/plugins/plugin-annotations/tests/sewtogether.test.mjs b/plugins/plugin-annotations/tests/sewtogether.test.mjs new file mode 100644 index 00000000000..afc7ddcc5af --- /dev/null +++ b/plugins/plugin-annotations/tests/sewtogether.test.mjs @@ -0,0 +1,108 @@ +import chai from 'chai' +import { Design, round } from '@freesewing/core' +import { annotationPlugin } from '../src/index.mjs' + +const expect = chai.expect + +describe('Sewtogether Plugin Tests', () => { + it('Should run the default sewtogether macro', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 220) + macro('sewtogether', { + from: points.from, + to: points.to, + }) + + return part + }, + plugins: [annotationPlugin], + } + const Test = new Design({ plugins: [annotationPlugin], parts: [part] }) + const pattern = new Test() + pattern.draft() + const c = pattern.parts[0].test.paths.sewtogetherSewTogether + expect(c.attributes.get('class')).to.equal('dotted note stroke-sm') + expect(c.attributes.get('marker-start')).to.equal('url(#sewTogetherStart)') + expect(c.attributes.get('marker-end')).to.equal('url(#sewTogetherEnd)') + expect(c.attributes.get('data-text')).to.equal('sewTogether') + expect(c.attributes.get('data-text-class')).to.equal('center fill-note text-xs') + expect(c.ops[0].type).to.equal('move') + expect(c.ops[1].type).to.equal('curve') + expect(round(c.ops[0].to.x)).to.equal(10) + expect(round(c.ops[0].to.y)).to.equal(20) + expect(round(c.ops[1].cp1.x)).to.equal(76.67) + expect(round(c.ops[1].cp1.y)).to.equal(20) + expect(round(c.ops[1].cp2.x)).to.equal(76.67) + expect(round(c.ops[1].cp2.y)).to.equal(220) + expect(round(c.ops[1].to.x)).to.equal(10) + expect(round(c.ops[1].to.y)).to.equal(220) + }) + + it('Should run the sewtogether/hinge macro', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + points.hinge = new Point(40, 110) + points.to = new Point(10, 220) + macro('sewtogether', { + from: points.from, + hinge: points.hinge, + 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.sewtogetherSewTogetherHinge + console.log({ c: c }) + console.log({ p: pattern.parts[0].test.paths }) + console.log({ t: pattern.parts[0].test }) + console.log({ ps0: pattern.parts[0] }) + expect(c.attributes.get('class')).to.equal('dotted note stroke-sm') + expect(c.attributes.get('marker-start')).to.equal('url(#sewTogetherCross)') + 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(120) + expect(round(c.ops[1].to.x)).to.equal(35) + expect(round(c.ops[1].to.y)).to.equal(120) + }) + + it('Should run the pleat/reverse macro', () => { + const part = { + name: 'test', + draft: ({ Point, points, macro, part }) => { + points.from = new Point(10, 20) + points.to = new Point(10, 220) + macro('pleat', { + from: points.from, + to: points.to, + reverse: true, + }) + + 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.pleatPleatFrom + expect(c.attributes.get('class')).to.equal('note dashed') + c = pattern.parts[0].test.paths.pleatPleatTo + expect(c.attributes.get('class')).to.equal('note') + c = pattern.parts[0].test.paths.pleatPleatArrow + expect(round(c.ops[0].to.x)).to.equal(18.75) + expect(round(c.ops[0].to.y)).to.equal(220) + expect(round(c.ops[1].to.x)).to.equal(18.75) + expect(round(c.ops[1].to.y)).to.equal(20) + }) +})