2022-09-07 21:16:44 +02:00
|
|
|
import chai from 'chai'
|
|
|
|
import { Design, Point } from '@freesewing/core'
|
|
|
|
import { plugin } from '../dist/index.mjs'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Cutlist Plugin Tests', () => {
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Draft method should receive added methods', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
let methods
|
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
methods = { addCut, removeCut, setGrain, setCutOnFold }
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2022-09-11 21:40:21 +02:00
|
|
|
expect(typeof methods.addCut).to.equal('function')
|
|
|
|
expect(typeof methods.removeCut).to.equal('function')
|
|
|
|
expect(typeof methods.setGrain).to.equal('function')
|
|
|
|
expect(typeof methods.setCutOnFold).to.equal('function')
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should handle addCut() with defaults', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
addCut()
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(pattern.store.cutlist.example_part.materials.fabric.cut).to.equal(2)
|
|
|
|
expect(pattern.store.cutlist.example_part.materials.fabric.identical).to.equal(false)
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should handle addCut() with non-defaults', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
addCut(3, 'lining', true)
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(pattern.store.cutlist.example_part.materials.lining.cut).to.equal(3)
|
|
|
|
expect(pattern.store.cutlist.example_part.materials.lining.identical).to.equal(true)
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should remove cut info via addCut(false)', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
addCut(2, 'fabric')
|
|
|
|
addCut(4, 'lining', true)
|
|
|
|
addCut(false, 'lining')
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(typeof pattern.store.cutlist.example_part.materials.lining).to.equal('undefined')
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should remove cut info for a material via removeCut()', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
addCut(2, 'fabric')
|
|
|
|
addCut(4, 'lining', true)
|
|
|
|
removeCut('lining')
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(typeof pattern.store.cutlist.example_part.materials.lining).to.equal('undefined')
|
|
|
|
expect(pattern.store.cutlist.example_part.materials.fabric.cut).to.equal(2)
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should remove cut info for all materials via removeCut(true)', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
addCut(2, 'fabric')
|
|
|
|
addCut(4, 'lining', true)
|
|
|
|
removeCut()
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(typeof pattern.store.cutlist.example_part.materials).to.equal('undefined')
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should set the grain via setGrain()', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
setGrain(45)
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(pattern.store.cutlist.example_part.grain).to.equal(45)
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should remove the grain via setGrain(false)', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
setGrain(45)
|
|
|
|
setGrain(false)
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(typeof pattern.store.cutlist.example_part.grain).to.equal('undefined')
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should set the cutOnFold via setCutOnFold(p1, p2)', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ Point, addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
try {
|
2022-09-11 21:40:21 +02:00
|
|
|
setCutOnFold(new Point(2, 2), new Point(200, 200))
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(pattern.store.cutlist.example_part.cutOnFold[0].x).to.equal(2)
|
|
|
|
expect(pattern.store.cutlist.example_part.cutOnFold[0].y).to.equal(2)
|
|
|
|
expect(pattern.store.cutlist.example_part.cutOnFold[1].x).to.equal(200)
|
|
|
|
expect(pattern.store.cutlist.example_part.cutOnFold[1].y).to.equal(200)
|
|
|
|
})
|
|
|
|
|
2022-09-11 21:40:21 +02:00
|
|
|
it('Should removet the cutOnFold via setCutOnFold(false)', () => {
|
2022-09-07 21:16:44 +02:00
|
|
|
const part = {
|
|
|
|
name: 'example_part',
|
2022-09-11 21:40:21 +02:00
|
|
|
draft: ({ Point, addCut, removeCut, setGrain, setCutOnFold }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
try {
|
2022-09-11 21:40:21 +02:00
|
|
|
setCutOnFold(new Point(2, 2), new Point(200, 200))
|
|
|
|
setCutOnFold(false)
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
},
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-11 21:40:21 +02:00
|
|
|
const Test = new Design({ plugins: [plugin], parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
|
|
|
expect(typeof pattern.store.cutlist.example_part.cutOnFold).to.equal('undefined')
|
|
|
|
})
|
|
|
|
})
|