chore(plugin-bartack): Ported to v3
This commit is contained in:
parent
945076830a
commit
38519b6aba
3 changed files with 126 additions and 95 deletions
|
@ -1,19 +1,23 @@
|
|||
import chai from 'chai'
|
||||
import { round, Pattern } from '@freesewing/core'
|
||||
import { plugin } from './dist/index.mjs'
|
||||
import { round, Design } from '@freesewing/core'
|
||||
import { plugin } from '../src/index.mjs'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Bartack plugin Tests', () => {
|
||||
it('draws a default bartack from a point', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartack', {
|
||||
anchor: pattern.parts.test.points.from,
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
macro('bartack', {
|
||||
anchor: points.from,
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -32,16 +36,19 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('draws a bartack along a path', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
const from = new pattern.Point(10, 20)
|
||||
const to = new pattern.Point(10, 30)
|
||||
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartackAlong', {
|
||||
path: new pattern.Path().move(from).line(to),
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
points.to = new Point(10, 30)
|
||||
macro('bartackAlong', {
|
||||
path: new Path().move(points.from).line(points.to),
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -60,18 +67,21 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('can be called using the bartackFractionAlong syntax', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
const from = new pattern.Point(10, 20)
|
||||
const to = new pattern.Point(10, 100)
|
||||
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartackAlong', {
|
||||
path: new pattern.Path().move(from).line(to),
|
||||
start: 0.2,
|
||||
end: 0.8,
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
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,
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -90,18 +100,21 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('can be called using the bartackFractionAlong syntax', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
const from = new pattern.Point(10, 20)
|
||||
const to = new pattern.Point(10, 100)
|
||||
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartackFractionAlong', {
|
||||
path: new pattern.Path().move(from).line(to),
|
||||
start: 0.2,
|
||||
end: 0.8,
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
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,
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -120,15 +133,19 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('has configurable length', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartack', {
|
||||
anchor: pattern.parts.test.points.from,
|
||||
length: 20,
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
macro('bartack', {
|
||||
anchor: points.from,
|
||||
length: 20,
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -147,15 +164,19 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('has configurable width', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartack', {
|
||||
anchor: pattern.parts.test.points.from,
|
||||
width: 5,
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
macro('bartack', {
|
||||
anchor: points.from,
|
||||
width: 5,
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -174,15 +195,19 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('has configurable angle', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartack', {
|
||||
anchor: pattern.parts.test.points.from,
|
||||
angle: 45,
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
macro('bartack', {
|
||||
anchor: points.from,
|
||||
angle: 45,
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
|
@ -201,29 +226,37 @@ describe('Bartack plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('has configurable suffix', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartack', {
|
||||
anchor: pattern.parts.test.points.from,
|
||||
suffix: 'foo',
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
macro('bartack', {
|
||||
anchor: points.from,
|
||||
suffix: 'foo',
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.bartackfoo
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
})
|
||||
|
||||
it('has configurable prefix', function () {
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('bartack', {
|
||||
anchor: pattern.parts.test.points.from,
|
||||
prefix: 'foo',
|
||||
})
|
||||
const part = {
|
||||
name: 'test',
|
||||
draft: ({ Point, points, Path, paths, macro }) => {
|
||||
points.from = new Point(10, 20)
|
||||
macro('bartack', {
|
||||
anchor: points.from,
|
||||
prefix: 'foo',
|
||||
})
|
||||
},
|
||||
}
|
||||
const design = new Design({ parts: [part], plugins: [plugin] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
const c = pattern.parts.test.paths.foobartack
|
||||
expect(c.attributes.get('class')).to.equal('stroke-sm stroke-mark')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue