2022-09-07 21:16:44 +02:00
|
|
|
import chai from 'chai'
|
2022-09-14 15:02:39 +02:00
|
|
|
import { Design } from '@freesewing/core'
|
2023-04-15 17:09:29 -04:00
|
|
|
import { annotationsPlugin } from '../src/index.mjs'
|
2022-09-07 21:16:44 +02:00
|
|
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
methods = { ...store.cutlist }
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-19 20:12:17 -05:00
|
|
|
expect(methods.addCut).to.be.a('function')
|
|
|
|
expect(methods.removeCut).to.be.a('function')
|
|
|
|
expect(methods.setGrain).to.be.a('function')
|
|
|
|
expect(methods.setCutOnFold).to.be.a('function')
|
2023-04-15 17:09:29 -04:00
|
|
|
expect(methods.getCutFabrics).to.be.a('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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.addCut()
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-09 17:45:10 -06:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.fabric).to.have.lengthOf(1)
|
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.fabric[0]).to.deep.equal({
|
|
|
|
cut: 2,
|
|
|
|
identical: false,
|
|
|
|
bias: false,
|
|
|
|
ignoreOnFold: false,
|
|
|
|
})
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.addCut({ cut: 3, material: 'lining', identical: true })
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-09 17:45:10 -06:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.lining).to.have.lengthOf(1)
|
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.lining[0]).to.deep.equal({
|
|
|
|
cut: 3,
|
|
|
|
identical: true,
|
|
|
|
bias: false,
|
|
|
|
ignoreOnFold: false,
|
|
|
|
})
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.addCut(2, 'fabric')
|
|
|
|
store.cutlist.addCut(4, 'lining', true)
|
|
|
|
store.cutlist.addCut(false, 'lining')
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-19 20:12:17 -05:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.lining).to.be.undefined
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.addCut(2, 'fabric')
|
|
|
|
store.cutlist.addCut(4, 'lining', true)
|
|
|
|
store.cutlist.removeCut('lining')
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-19 20:12:17 -05:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.lining).to.be.undefined
|
2023-03-09 17:45:10 -06:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials.fabric[0].cut).to.equal(2)
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.addCut(2, 'fabric')
|
|
|
|
store.cutlist.addCut(4, 'lining', true)
|
|
|
|
store.cutlist.removeCut()
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-19 20:12:17 -05:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.materials).to.be.undefined
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.setGrain(45)
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2022-09-25 15:29:02 +02:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.grain).to.equal(45)
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ store, part }) => {
|
|
|
|
store.cutlist.setGrain(45)
|
|
|
|
store.cutlist.setGrain(false)
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-19 20:12:17 -05:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.grain).to.be.undefined
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ Point, store, part }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
try {
|
2023-03-19 20:12:17 -05:00
|
|
|
store.cutlist.setCutOnFold(new Point(2, 2), new Point(200, 200))
|
2022-09-11 21:40:21 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2022-09-25 15:29:02 +02:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.cutOnFold[0].x).to.equal(2)
|
|
|
|
expect(pattern.setStores[0].cutlist.example_part.cutOnFold[0].y).to.equal(2)
|
|
|
|
expect(pattern.setStores[0].cutlist.example_part.cutOnFold[1].x).to.equal(200)
|
|
|
|
expect(pattern.setStores[0].cutlist.example_part.cutOnFold[1].y).to.equal(200)
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
|
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',
|
2023-03-19 20:12:17 -05:00
|
|
|
draft: ({ Point, store, part }) => {
|
2022-09-07 21:16:44 +02:00
|
|
|
try {
|
2023-03-19 20:12:17 -05:00
|
|
|
store.cutlist.setCutOnFold(new Point(2, 2), new Point(200, 200))
|
|
|
|
store.cutlist.setCutOnFold(false)
|
2022-09-11 21:40:21 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
|
|
|
|
return part
|
2022-09-11 21:40:21 +02:00
|
|
|
},
|
2023-04-15 17:09:29 -04:00
|
|
|
plugins: [annotationsPlugin],
|
2022-09-07 21:16:44 +02:00
|
|
|
}
|
2022-09-25 15:29:02 +02:00
|
|
|
const Test = new Design({ parts: [part] })
|
2022-09-07 21:16:44 +02:00
|
|
|
const pattern = new Test()
|
|
|
|
pattern.draft()
|
2023-03-19 20:12:17 -05:00
|
|
|
expect(pattern.setStores[0].cutlist.example_part.cutOnFold).to.be.undefined
|
2022-09-07 21:16:44 +02:00
|
|
|
})
|
|
|
|
})
|