2023-02-21 16:17:57 +02:00
|
|
|
import chai from 'chai'
|
|
|
|
import { Design } from '../src/index.mjs'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Pattern', () => {
|
|
|
|
describe('.addPart()', () => {
|
|
|
|
const part1 = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
const part2 = {
|
|
|
|
name: 'test2',
|
2023-02-21 22:33:57 +02:00
|
|
|
after: part1,
|
2023-02-21 16:17:57 +02:00
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
const part3 = {
|
|
|
|
name: 'test3',
|
2023-02-21 22:33:57 +02:00
|
|
|
from: part2,
|
2023-02-21 16:17:57 +02:00
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
2023-02-23 18:22:22 +02:00
|
|
|
describe('with runtime: true, resolveImmediately: true', () => {
|
|
|
|
it('adds the part to the current draft cycle')
|
|
|
|
it('does not add the part to subsequent draft cycles')
|
|
|
|
})
|
|
|
|
|
2023-02-21 16:17:57 +02:00
|
|
|
describe('with resolveImmediately: true', () => {
|
2023-02-21 22:33:57 +02:00
|
|
|
it('Should add the part to parts object', () => {
|
2023-02-21 16:17:57 +02:00
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
pattern.addPart(part2, true)
|
2023-02-21 22:33:57 +02:00
|
|
|
expect(pattern.config.parts.test2).to.equal(part2)
|
2023-02-21 16:17:57 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should resolve injected dependencies for the new part', () => {
|
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
2023-02-21 22:33:57 +02:00
|
|
|
pattern.addPart(part3, true)
|
|
|
|
expect(pattern.config.inject.test3).to.equal('test2')
|
2023-02-21 16:17:57 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should resolve all dependencies for the new part', () => {
|
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
pattern.addPart(part3, true)
|
|
|
|
expect(pattern.config.resolvedDependencies.test3).to.have.members(['test', 'test2'])
|
2023-02-21 22:33:57 +02:00
|
|
|
expect(pattern.config.parts.test2).to.equal(part2)
|
2023-02-21 16:17:57 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add a the measurements for the new part', () => {
|
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
|
|
|
|
const part2 = {
|
|
|
|
name: 'test2',
|
|
|
|
measurements: ['neck'],
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
pattern.addPart(part2, true)
|
|
|
|
expect(pattern.config.measurements).to.include('neck')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add the plugins for the new part', () => {
|
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
|
|
|
|
const plugin = { name: 'testPlugin' }
|
|
|
|
const part2 = {
|
|
|
|
name: 'test2',
|
|
|
|
plugins: [plugin],
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
pattern.addPart(part2, true)
|
|
|
|
expect(pattern.config.plugins.testPlugin).to.equal(plugin)
|
|
|
|
})
|
|
|
|
|
2023-02-21 22:33:57 +02:00
|
|
|
it('Should resolve the options for the new part', () => {
|
2023-02-21 16:17:57 +02:00
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
|
|
|
|
const opt1 = { pct: 10, min: 0, max: 50 }
|
|
|
|
const part2 = {
|
|
|
|
name: 'test2',
|
|
|
|
options: {
|
|
|
|
opt1,
|
|
|
|
},
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
pattern.addPart(part2, true)
|
|
|
|
expect(pattern.config.options.opt1).to.equal(opt1)
|
|
|
|
})
|
2023-02-21 22:33:57 +02:00
|
|
|
|
|
|
|
it('Should resolve the dependency options for the new part', () => {
|
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
|
|
|
|
const opt1 = { pct: 10, min: 0, max: 50 }
|
|
|
|
const part2 = {
|
|
|
|
name: 'test2',
|
|
|
|
options: {
|
|
|
|
opt1,
|
|
|
|
},
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
const part3 = {
|
|
|
|
name: 'test3',
|
|
|
|
from: part2,
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
pattern.addPart(part3, true)
|
|
|
|
expect(pattern.config.options.opt1).to.equal(opt1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should resolve the overwritten options for the new part', () => {
|
|
|
|
const design = new Design({ parts: [part1] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.__init()
|
|
|
|
|
|
|
|
const opt1 = { pct: 10, min: 0, max: 50 }
|
|
|
|
const part2 = {
|
|
|
|
name: 'test2',
|
|
|
|
options: {
|
|
|
|
opt1: { pct: 15, min: 10, max: 55 },
|
|
|
|
},
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
const part3 = {
|
|
|
|
name: 'test3',
|
|
|
|
from: part2,
|
|
|
|
options: {
|
|
|
|
opt1,
|
|
|
|
},
|
|
|
|
draft: ({ part }) => part,
|
|
|
|
}
|
|
|
|
|
|
|
|
pattern.addPart(part3, true)
|
|
|
|
expect(pattern.config.options.opt1).to.equal(opt1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with resolveImmediately: false', () => {
|
|
|
|
it('does not create duplications in the configuration')
|
2023-02-21 16:17:57 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|