1
0
Fork 0
freesewing/plugins/plugin-cutlist/tests/plugin.test.mjs

204 lines
5.8 KiB
JavaScript
Raw Normal View History

import chai from 'chai'
2022-09-14 15:02:39 +02:00
import { Design } from '@freesewing/core'
2022-09-15 13:49:55 +02:00
import { plugin } from '../src/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', () => {
let methods
const part = {
name: 'example_part',
draft: ({ addCut, removeCut, setGrain, setCutOnFold, part }) => {
methods = { addCut, removeCut, setGrain, setCutOnFold }
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
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-11 21:40:21 +02:00
it('Should handle addCut() with defaults', () => {
const part = {
name: 'example_part',
draft: ({ addCut, part }) => {
addCut()
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
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-11 21:40:21 +02:00
it('Should handle addCut() with non-defaults', () => {
const part = {
name: 'example_part',
draft: ({ addCut, part }) => {
2023-03-09 17:45:10 -06:00
addCut({ cut: 3, material: 'lining', identical: true })
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
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-11 21:40:21 +02:00
it('Should remove cut info via addCut(false)', () => {
const part = {
name: 'example_part',
draft: ({ addCut, part }) => {
addCut(2, 'fabric')
addCut(4, 'lining', true)
addCut(false, 'lining')
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
expect(typeof pattern.setStores[0].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()', () => {
const part = {
name: 'example_part',
draft: ({ addCut, removeCut, part }) => {
addCut(2, 'fabric')
addCut(4, 'lining', true)
removeCut('lining')
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
expect(typeof pattern.setStores[0].cutlist.example_part.materials.lining).to.equal('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-11 21:40:21 +02:00
it('Should remove cut info for all materials via removeCut(true)', () => {
const part = {
name: 'example_part',
draft: ({ addCut, removeCut, part }) => {
addCut(2, 'fabric')
addCut(4, 'lining', true)
removeCut()
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
expect(typeof pattern.setStores[0].cutlist.example_part.materials).to.equal('undefined')
})
2022-09-11 21:40:21 +02:00
it('Should set the grain via setGrain()', () => {
const part = {
name: 'example_part',
draft: ({ setGrain, part }) => {
setGrain(45)
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
expect(pattern.setStores[0].cutlist.example_part.grain).to.equal(45)
})
2022-09-11 21:40:21 +02:00
it('Should remove the grain via setGrain(false)', () => {
const part = {
name: 'example_part',
draft: ({ setGrain, part }) => {
setGrain(45)
setGrain(false)
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
expect(typeof pattern.setStores[0].cutlist.example_part.grain).to.equal('undefined')
})
2022-09-11 21:40:21 +02:00
it('Should set the cutOnFold via setCutOnFold(p1, p2)', () => {
const part = {
name: 'example_part',
draft: ({ Point, setCutOnFold, part }) => {
try {
2022-09-11 21:40:21 +02:00
setCutOnFold(new Point(2, 2), new Point(200, 200))
} catch (err) {
console.log(err)
}
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
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-11 21:40:21 +02:00
it('Should removet the cutOnFold via setCutOnFold(false)', () => {
const part = {
name: 'example_part',
draft: ({ Point, setCutOnFold, part }) => {
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)
}
return part
2022-09-11 21:40:21 +02:00
},
plugins: [plugin],
}
const Test = new Design({ parts: [part] })
const pattern = new Test()
pattern.draft()
expect(typeof pattern.setStores[0].cutlist.example_part.cutOnFold).to.equal('undefined')
})
})