1
0
Fork 0
This commit is contained in:
Wouter van Wageningen 2023-03-09 05:20:51 +00:00
parent 1838120872
commit a606319ad5
8 changed files with 890 additions and 13 deletions

View file

@ -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')
})
})

View file

@ -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(`<g id="${snippet}">`)).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('<use x="10" y="20" xlink:href="#button"')
})
it('Draws a buttonhole centred on an anchor point', () => {
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('<use x="10" y="20" xlink:href="#buttonhole"')
})
it('Draws a buttonhole starting on an anchor point', () => {
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('<use x="10" y="20" xlink:href="#buttonhole-start"')
})
it('Draws a buttonhole ending on an anchor point', () => {
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('<use x="10" y="20" xlink:href="#buttonhole-end"')
})
it('Draws a snap-stud on an anchor point', () => {
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('<use x="10" y="20" xlink:href="#snap-stud"')
})
it('Draws a snap-socket on an anchor point', () => {
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('<use x="10" y="20" xlink:href="#snap-socket"')
})
})

View file

@ -0,0 +1,93 @@
import chai from 'chai'
import { Design, round } from '@freesewing/core'
import { annotationPlugin } from '../src/index.mjs'
const expect = chai.expect
describe('Crossbox Plugin Tests', () => {
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')
})
})

View file

@ -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)')

View file

@ -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)
})
})

View file

@ -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(
'<g id="logo" transform="scale(1) translate(-23 -36)"><path class="logo"'
)
})
})

View file

@ -0,0 +1,43 @@
import chai from 'chai'
import { Design } from '@freesewing/core'
import { annotationPlugin } from '../src/index.mjs'
const expect = chai.expect
const part = {
name: 'test',
draft: ({ Point, snippets, Snippet }) => {
snippets.button = new Snippet('notch', new Point(10, 20))
},
plugins: [annotationPlugin],
}
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
pattern.draft().render()
describe('Notches Plugin Test', () => {
it(`Should add the snippets to defs`, () => {
expect(pattern.svg.defs).to.contain('<g id="notch">')
})
it(`Should add the notches snippet to defs`, () => {
expect(pattern.svg.defs.indexOf(`<g id="notch">`)).to.not.equal(-1)
})
it('Draws a notch on an anchor point', () => {
const part = {
name: 'test',
draft: ({ Point, snippets, Snippet, part }) => {
snippets.button = new Snippet('notch', new Point(10, 20))
return part
},
plugins: [annotationPlugin],
}
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
pattern.draft().render()
const c = pattern.svg
expect(c.layout.test.svg).to.contain('<use x="10" y="20" xlink:href="#notch"')
})
})

View file

@ -0,0 +1,282 @@
import chai from 'chai'
import { Design, round } from '@freesewing/core'
import { annotationPlugin } from '../src/index.mjs'
const expect = chai.expect
describe('Scalebox Plugin Tests', () => {
it('Should run the default scalebox macro', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(100, 200)
macro('scalebox', {
at: points.anchor,
})
return part
},
plugins: [annotationPlugin],
}
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
pattern.draft()
let p = pattern.parts[0].test.points
expect(p.__scaleboxMetricTopLeft.x).to.equal(50)
expect(p.__scaleboxMetricTopLeft.y).to.equal(175)
expect(p.__scaleboxMetricTopRight.x).to.equal(150)
expect(p.__scaleboxMetricTopRight.y).to.equal(175)
expect(p.__scaleboxMetricBottomLeft.x).to.equal(50)
expect(p.__scaleboxMetricBottomLeft.y).to.equal(225)
expect(p.__scaleboxMetricBottomRight.x).to.equal(150)
expect(p.__scaleboxMetricBottomRight.y).to.equal(225)
expect(p.__scaleboxImperialTopLeft.x).to.equal(49.2)
expect(p.__scaleboxImperialTopLeft.y).to.equal(174.6)
expect(p.__scaleboxImperialTopRight.x).to.equal(150.8)
expect(p.__scaleboxImperialTopRight.y).to.equal(174.6)
expect(p.__scaleboxImperialBottomLeft.x).to.equal(49.2)
expect(p.__scaleboxImperialBottomLeft.y).to.equal(225.4)
expect(p.__scaleboxImperialBottomRight.x).to.equal(150.8)
expect(p.__scaleboxImperialBottomRight.y).to.equal(225.4)
expect(p.__scaleboxLead.x).to.equal(55)
expect(p.__scaleboxLead.y).to.equal(185)
expect(p.__scaleboxTitle.x).to.equal(55)
expect(p.__scaleboxTitle.y).to.equal(195)
expect(p.__scaleboxText.x).to.equal(55)
expect(p.__scaleboxText.y).to.equal(207)
expect(p.__scaleboxLink.x).to.equal(55)
expect(p.__scaleboxLink.y).to.equal(212)
expect(p.__scaleboxMetric.x).to.equal(100)
expect(p.__scaleboxMetric.y).to.equal(220)
expect(p.__scaleboxImperial.x).to.equal(100)
expect(p.__scaleboxImperial.y).to.equal(224)
p = pattern.parts[0].test.paths.__scaleboxMetric
expect(p.ops[0].type).to.equal('move')
expect(p.ops[1].type).to.equal('line')
expect(p.ops[2].type).to.equal('line')
expect(p.ops[3].type).to.equal('line')
expect(p.ops[4].type).to.equal('close')
expect(p.ops[0].to.x).to.equal(50)
expect(p.ops[0].to.y).to.equal(175)
expect(p.ops[1].to.x).to.equal(50)
expect(p.ops[1].to.y).to.equal(225)
expect(p.ops[2].to.x).to.equal(150)
expect(p.ops[2].to.y).to.equal(225)
expect(p.ops[3].to.x).to.equal(150)
expect(p.ops[3].to.y).to.equal(175)
p = pattern.parts[0].test.paths.__scaleboxImperial
expect(p.ops[0].type).to.equal('move')
expect(p.ops[1].type).to.equal('line')
expect(p.ops[2].type).to.equal('line')
expect(p.ops[3].type).to.equal('line')
expect(p.ops[4].type).to.equal('close')
expect(p.ops[0].to.x).to.equal(49.2)
expect(p.ops[0].to.y).to.equal(174.6)
expect(p.ops[1].to.x).to.equal(49.2)
expect(p.ops[1].to.y).to.equal(225.4)
expect(p.ops[2].to.x).to.equal(150.8)
expect(p.ops[2].to.y).to.equal(225.4)
expect(p.ops[3].to.x).to.equal(150.8)
expect(p.ops[3].to.y).to.equal(174.6)
})
it('Should run the scalebox macro with rotation', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro }) => {
points.anchor = new Point(100, 200)
macro('scalebox', {
at: points.anchor,
rotate: 90,
})
},
plugins: [annotationPlugin],
}
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
pattern.draft()
const p = pattern.parts[0].test.points
expect(round(p.__scaleboxMetricTopLeft.x)).to.equal(75)
expect(round(p.__scaleboxMetricTopLeft.y)).to.equal(250)
expect(round(p.__scaleboxMetricTopRight.x)).to.equal(75)
expect(round(p.__scaleboxMetricTopRight.y)).to.equal(150)
expect(round(p.__scaleboxMetricBottomLeft.x)).to.equal(125)
expect(round(p.__scaleboxMetricBottomLeft.y)).to.equal(250)
expect(round(p.__scaleboxMetricBottomRight.x)).to.equal(125)
expect(round(p.__scaleboxMetricBottomRight.y)).to.equal(150)
expect(round(p.__scaleboxImperialTopLeft.x)).to.equal(74.6)
expect(round(p.__scaleboxImperialTopLeft.y)).to.equal(250.8)
expect(round(p.__scaleboxImperialTopRight.x)).to.equal(74.6)
expect(round(p.__scaleboxImperialTopRight.y)).to.equal(149.2)
expect(round(p.__scaleboxImperialBottomLeft.x)).to.equal(125.4)
expect(round(p.__scaleboxImperialBottomLeft.y)).to.equal(250.8)
expect(round(p.__scaleboxImperialBottomRight.x)).to.equal(125.4)
expect(round(p.__scaleboxImperialBottomRight.y)).to.equal(149.2)
expect(round(p.__scaleboxLead.x)).to.equal(85)
expect(round(p.__scaleboxLead.y)).to.equal(245)
expect(round(p.__scaleboxTitle.x)).to.equal(95)
expect(round(p.__scaleboxTitle.y)).to.equal(245)
expect(round(p.__scaleboxText.x)).to.equal(107)
expect(round(p.__scaleboxText.y)).to.equal(245)
expect(round(p.__scaleboxLink.x)).to.equal(112)
expect(round(p.__scaleboxLink.y)).to.equal(245)
expect(round(p.__scaleboxMetric.x)).to.equal(120)
expect(round(p.__scaleboxMetric.y)).to.equal(200)
expect(round(p.__scaleboxImperial.x)).to.equal(124)
expect(round(p.__scaleboxImperial.y)).to.equal(200)
})
it('Should run the scalebox macro with default text', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(100, 200)
macro('scalebox', {
at: points.anchor,
})
return part
},
plugins: [annotationPlugin],
}
const Pattern = new Design({
parts: [part],
data: { name: 'test', version: '1.2.3' },
})
const pattern = new Pattern()
pattern.draft()
let p = pattern.parts[0].test.points.__scaleboxLead.attributes
expect(p.get('data-text')).to.equal('FreeSewing')
expect(p.get('data-text-class')).to.equal('text-sm')
p = pattern.parts[0].test.points.__scaleboxTitle.attributes
expect(p.get('data-text')).to.equal('test v1.2.3')
expect(p.get('data-text-class')).to.equal('text-lg')
p = pattern.parts[0].test.points.__scaleboxText.attributes
expect(p.get('data-text-class')).to.equal('text-xs')
expect(p.get('data-text-lineheight')).to.equal('4')
expect(p.list['data-text'][0]).to.equal('supportFreesewingBecomeAPatron')
})
it('Should run the scalebox macro with custom text', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(100, 200)
macro('scalebox', {
at: points.anchor,
lead: 'theLead',
title: 'theTitle',
text: 'theText',
})
return part
},
plugins: [annotationPlugin],
}
const Pattern = new Design({
parts: [part],
data: { name: 'test', version: '1.2.3' },
})
const pattern = new Pattern()
pattern.draft()
let p = pattern.parts[0].test.points.__scaleboxLead.attributes
expect(p.get('data-text')).to.equal('theLead')
expect(p.get('data-text-class')).to.equal('text-sm')
p = pattern.parts[0].test.points.__scaleboxTitle.attributes
expect(p.get('data-text')).to.equal('theTitle')
expect(p.get('data-text-class')).to.equal('text-lg')
p = pattern.parts[0].test.points.__scaleboxText.attributes
expect(p.get('data-text')).to.equal('theText')
expect(p.get('data-text-class')).to.equal('text-xs')
expect(p.get('data-text-lineheight')).to.equal('4')
})
it('Should apply scale to the scalebox macro', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(100, 200)
macro('scalebox', {
at: points.anchor,
lead: 'theLead',
title: 'theTitle',
text: 'theText',
})
return part
},
plugins: [annotationPlugin],
}
const Pattern = new Design({
parts: [part],
plugins: [annotationPlugin],
data: { name: 'test', version: '1.2.3' },
})
const pattern = new Pattern({ scale: 0.5 })
pattern.draft()
let p = pattern.parts[0].test.points
expect(p.__scaleboxMetricTopLeft.x).to.equal(75)
expect(p.__scaleboxMetricTopLeft.y).to.equal(187.5)
expect(p.__scaleboxMetricTopRight.x).to.equal(125)
expect(p.__scaleboxMetricTopRight.y).to.equal(187.5)
expect(p.__scaleboxMetricBottomLeft.x).to.equal(75)
expect(p.__scaleboxMetricBottomLeft.y).to.equal(212.5)
expect(p.__scaleboxMetricBottomRight.x).to.equal(125)
expect(p.__scaleboxMetricBottomRight.y).to.equal(212.5)
expect(p.__scaleboxImperialTopLeft.x).to.equal(74.6)
expect(p.__scaleboxImperialTopLeft.y).to.equal(187.3)
expect(p.__scaleboxImperialTopRight.x).to.equal(125.4)
expect(p.__scaleboxImperialTopRight.y).to.equal(187.3)
expect(p.__scaleboxImperialBottomLeft.x).to.equal(74.6)
expect(p.__scaleboxImperialBottomLeft.y).to.equal(212.7)
expect(p.__scaleboxImperialBottomRight.x).to.equal(125.4)
expect(p.__scaleboxImperialBottomRight.y).to.equal(212.7)
expect(p.__scaleboxMetric.attributes.get('data-text')).to.equal(
'theWhiteInsideOfThisBoxShouldMeasure 5cm x 2.5cm'
)
expect(p.__scaleboxImperial.attributes.get('data-text')).to.equal(
'theBlackOutsideOfThisBoxShouldMeasure 2″ x 1″'
)
})
it('Should apply scale to the miniscale macro', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new Point(100, 200)
macro('miniscale', {
at: points.anchor,
})
return part
},
plugins: [annotationPlugin],
}
const Pattern = new Design({
parts: [part],
plugins: [annotationPlugin],
data: { name: 'test', version: '1.2.3' },
})
const pattern = new Pattern({ scale: 0.5 })
pattern.draft()
let p = pattern.parts[0].test.points
expect(p.__miniscaleMetricTopLeft.x).to.equal(92)
expect(p.__miniscaleMetricTopLeft.y).to.equal(192)
expect(p.__miniscaleMetricTopRight.x).to.equal(108)
expect(p.__miniscaleMetricTopRight.y).to.equal(192)
expect(p.__miniscaleMetricBottomLeft.x).to.equal(92)
expect(p.__miniscaleMetricBottomLeft.y).to.equal(208)
expect(p.__miniscaleMetricBottomRight.x).to.equal(108)
expect(p.__miniscaleMetricBottomRight.y).to.equal(208)
expect(p.__miniscaleImperialTopLeft.x).to.equal(92.0625)
expect(p.__miniscaleImperialTopLeft.y).to.equal(192.0625)
expect(p.__miniscaleImperialTopRight.x).to.equal(107.9375)
expect(p.__miniscaleImperialTopRight.y).to.equal(192.0625)
expect(p.__miniscaleImperialBottomLeft.x).to.equal(92.0625)
expect(p.__miniscaleImperialBottomLeft.y).to.equal(207.9375)
expect(p.__miniscaleImperialBottomRight.x).to.equal(107.9375)
expect(p.__miniscaleImperialBottomRight.y).to.equal(207.9375)
expect(p.__miniscaleMetric.attributes.get('data-text')).to.equal('1.6cm x 1.6cm')
expect(p.__miniscaleImperial.attributes.get('data-text')).to.equal('⅝″ x ⅝″')
})
})