chore(plugin-dimension): Ported to v3
This commit is contained in:
parent
6598a93b46
commit
dbb0ceb35d
3 changed files with 62 additions and 47 deletions
|
@ -151,4 +151,3 @@ export const plugin = {
|
||||||
// More specifically named exports
|
// More specifically named exports
|
||||||
export const dimensionPlugin = plugin
|
export const dimensionPlugin = plugin
|
||||||
export const pluginDimension = plugin
|
export const pluginDimension = plugin
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
import { Pattern, round } from '@freesewing/core'
|
import { Design, Pattern, round } from '@freesewing/core'
|
||||||
import { plugin } from './dist/index.mjs'
|
import { plugin } from './dist/index.mjs'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Dimension Plugin Tests', () => {
|
describe('Dimension Plugin Tests', () => {
|
||||||
|
|
||||||
describe('Measures horizontal dimensions', function () {
|
describe('Measures horizontal dimensions', function () {
|
||||||
const pattern = new Pattern().use(plugin)
|
const part = {
|
||||||
pattern.parts.test = new pattern.Part()
|
name: 'test',
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
draft: ({ Point, points, macro }) => {
|
||||||
pattern.parts.test.points.to = new pattern.Point(200, 20)
|
points.from = new Point(10, 20)
|
||||||
const { macro } = pattern.parts.test.shorthand()
|
points.to = new Point(200, 20)
|
||||||
macro('hd', {
|
macro('hd', {
|
||||||
from: pattern.parts.test.points.from,
|
from: points.from,
|
||||||
to: pattern.parts.test.points.to,
|
to: points.to,
|
||||||
y: 35,
|
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', () => {
|
it('should draw a line and add text to indicate its length', () => {
|
||||||
const c = pattern.parts.test.paths['__paperless1']
|
const c = pattern.parts.test.paths['__paperless1']
|
||||||
|
@ -57,16 +61,21 @@ describe('Dimension Plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Measures vertical dimensions', () => {
|
describe('Measures vertical dimensions', () => {
|
||||||
const pattern = new Pattern().use(plugin)
|
const part = {
|
||||||
pattern.parts.test = new pattern.Part()
|
name: 'test',
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
draft: ({ Point, points, macro }) => {
|
||||||
pattern.parts.test.points.to = new pattern.Point(10, 200)
|
points.from = new Point(10, 20)
|
||||||
const { macro } = pattern.parts.test.shorthand()
|
points.to = new Point(10, 200)
|
||||||
macro('vd', {
|
macro('vd', {
|
||||||
from: pattern.parts.test.points.from,
|
from: points.from,
|
||||||
to: pattern.parts.test.points.to,
|
to: points.to,
|
||||||
x: 25,
|
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', () => {
|
it('Should draw a line and add text to indicate its length', () => {
|
||||||
const c = pattern.parts.test.paths['__paperless1']
|
const c = pattern.parts.test.paths['__paperless1']
|
||||||
|
@ -107,16 +116,21 @@ describe('Dimension Plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Measures the length of straight lines', () => {
|
describe('Measures the length of straight lines', () => {
|
||||||
const pattern = new Pattern().use(plugin)
|
const part = {
|
||||||
pattern.parts.test = new pattern.Part()
|
name: 'test',
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 10)
|
draft: ({ Point, points, macro }) => {
|
||||||
pattern.parts.test.points.to = new pattern.Point(100, 100)
|
points.from = new Point(10, 10)
|
||||||
const { macro } = pattern.parts.test.shorthand()
|
points.to = new Point(100, 100)
|
||||||
macro('ld', {
|
macro('ld', {
|
||||||
from: pattern.parts.test.points.from,
|
from: points.from,
|
||||||
to: pattern.parts.test.points.to,
|
to: points.to,
|
||||||
d: 15,
|
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', () => {
|
it('Should draw a line and add text to indicate its length', () => {
|
||||||
const c = pattern.parts.test.paths['__paperless1']
|
const c = pattern.parts.test.paths['__paperless1']
|
||||||
|
@ -157,19 +171,22 @@ describe('Dimension Plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Measures curved lines', () => {
|
describe('Measures curved lines', () => {
|
||||||
const pattern = new Pattern()
|
const part = {
|
||||||
pattern.draft = function () {}
|
name: 'test',
|
||||||
pattern.use(plugin)
|
draft: ({ Point, points, macro, Path }) => {
|
||||||
pattern.parts.test = new pattern.Part()
|
points.from = new Point(10, 10)
|
||||||
const from = new pattern.Point(10, 10)
|
points.cp1 = new Point(100, 10)
|
||||||
const cp1 = new pattern.Point(100, 10)
|
points.cp2 = new Point(10, 100)
|
||||||
const cp2 = new pattern.Point(10, 100)
|
points.to = new Point(100, 100)
|
||||||
const to = new pattern.Point(100, 100)
|
macro('pd', {
|
||||||
const { macro } = pattern.parts.test.shorthand()
|
path: new Path().move(points.from).curve(points.cp1, points.cp2, points.to),
|
||||||
macro('pd', {
|
d: 15,
|
||||||
path: new pattern.Path().move(from).curve(cp1, cp2, 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', () => {
|
it('Should draw a line and add text to indicate the length', () => {
|
||||||
const c = pattern.parts.test.paths['__paperless1']
|
const c = pattern.parts.test.paths['__paperless1']
|
||||||
|
|
|
@ -4,4 +4,3 @@ import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
||||||
|
|
||||||
// Run shared tests
|
// Run shared tests
|
||||||
sharedPluginTests(plugin)
|
sharedPluginTests(plugin)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue