1
0
Fork 0

chore(plugin-dimension): Ported to v3

This commit is contained in:
joostdecock 2022-09-11 21:55:32 +02:00
parent 6598a93b46
commit dbb0ceb35d
3 changed files with 62 additions and 47 deletions

View file

@ -1,22 +1,26 @@
import chai from 'chai'
import { Pattern, round } from '@freesewing/core'
import { Design, Pattern, round } from '@freesewing/core'
import { plugin } from './dist/index.mjs'
const expect = chai.expect
describe('Dimension Plugin Tests', () => {
describe('Measures horizontal dimensions', function () {
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
pattern.parts.test.points.to = new pattern.Point(200, 20)
const { macro } = pattern.parts.test.shorthand()
macro('hd', {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to,
y: 35,
})
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
points.from = new Point(10, 20)
points.to = new Point(200, 20)
macro('hd', {
from: points.from,
to: points.to,
y: 35,
})
},
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const pattern = new Test()
pattern.draft()
it('should draw a line and add text to indicate its length', () => {
const c = pattern.parts.test.paths['__paperless1']
@ -57,16 +61,21 @@ describe('Dimension Plugin Tests', () => {
})
describe('Measures vertical dimensions', () => {
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
pattern.parts.test.points.to = new pattern.Point(10, 200)
const { macro } = pattern.parts.test.shorthand()
macro('vd', {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to,
x: 25,
})
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
points.from = new Point(10, 20)
points.to = new Point(10, 200)
macro('vd', {
from: points.from,
to: points.to,
x: 25,
})
},
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const pattern = new Test()
pattern.draft()
it('Should draw a line and add text to indicate its length', () => {
const c = pattern.parts.test.paths['__paperless1']
@ -107,16 +116,21 @@ describe('Dimension Plugin Tests', () => {
})
describe('Measures the length of straight lines', () => {
const pattern = new Pattern().use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 10)
pattern.parts.test.points.to = new pattern.Point(100, 100)
const { macro } = pattern.parts.test.shorthand()
macro('ld', {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to,
d: 15,
})
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
points.from = new Point(10, 10)
points.to = new Point(100, 100)
macro('ld', {
from: points.from,
to: points.to,
d: 15,
})
},
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const pattern = new Test()
pattern.draft()
it('Should draw a line and add text to indicate its length', () => {
const c = pattern.parts.test.paths['__paperless1']
@ -157,19 +171,22 @@ describe('Dimension Plugin Tests', () => {
})
describe('Measures curved lines', () => {
const pattern = new Pattern()
pattern.draft = function () {}
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
const from = new pattern.Point(10, 10)
const cp1 = new pattern.Point(100, 10)
const cp2 = new pattern.Point(10, 100)
const to = new pattern.Point(100, 100)
const { macro } = pattern.parts.test.shorthand()
macro('pd', {
path: new pattern.Path().move(from).curve(cp1, cp2, to),
d: 15,
})
const part = {
name: 'test',
draft: ({ Point, points, macro, Path }) => {
points.from = new Point(10, 10)
points.cp1 = new Point(100, 10)
points.cp2 = new Point(10, 100)
points.to = new Point(100, 100)
macro('pd', {
path: new Path().move(points.from).curve(points.cp1, points.cp2, points.to),
d: 15,
})
},
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const pattern = new Test()
pattern.draft()
it('Should draw a line and add text to indicate the length', () => {
const c = pattern.parts.test.paths['__paperless1']