refactor (core) move plugin and hook handling to its own class
This commit is contained in:
parent
e59341effa
commit
c5baaab234
5 changed files with 225 additions and 184 deletions
|
@ -18,7 +18,7 @@ describe('Pattern', () => {
|
|||
expect(Array.isArray(pattern.setStores)).to.equal(true)
|
||||
expect(typeof pattern.store).to.equal('object')
|
||||
expect(typeof pattern.config).to.equal('object')
|
||||
expect(Object.keys(pattern).length).to.equal(5)
|
||||
expect(Object.keys(pattern)).to.have.lengthOf(5)
|
||||
})
|
||||
|
||||
it('Pattern constructor should add non-enumerable properties', () => {
|
||||
|
@ -26,12 +26,10 @@ describe('Pattern', () => {
|
|||
const pattern = new Pattern()
|
||||
expect(typeof pattern.plugins).to.equal('object')
|
||||
expect(typeof pattern.autoLayout).to.equal('object')
|
||||
expect(typeof pattern.hooks).to.equal('object')
|
||||
expect(typeof pattern.Point).to.equal('function')
|
||||
expect(typeof pattern.Path).to.equal('function')
|
||||
expect(typeof pattern.Snippet).to.equal('function')
|
||||
expect(typeof pattern.Attributes).to.equal('function')
|
||||
expect(typeof pattern.macros).to.equal('object')
|
||||
// expect(typeof pattern.__designParts).to.equal('object')
|
||||
// expect(typeof pattern.config.inject).to.equal('object')
|
||||
// expect(typeof pattern.config.directDependencies).to.equal('object')
|
||||
|
@ -58,7 +56,7 @@ describe('Pattern', () => {
|
|||
absoluteOptions: {},
|
||||
}
|
||||
for (const [key, value] of Object.entries(dflts)) {
|
||||
if (typeof value === 'object') expect(Object.keys(value).length).to.equal(0)
|
||||
if (typeof value === 'object') expect(Object.keys(value)).to.have.lengthOf(0)
|
||||
else expect(pattern.settings[0][key]).to.equal(value)
|
||||
}
|
||||
})
|
||||
|
@ -120,19 +118,19 @@ describe('Pattern', () => {
|
|||
})
|
||||
|
||||
it('Pattern.__init() should resolve required measurements', () => {
|
||||
expect(pattern.config.measurements.length).to.equal(2)
|
||||
expect(pattern.config.measurements).to.have.lengthOf(2)
|
||||
expect(pattern.config.measurements[0]).to.equal('head')
|
||||
expect(pattern.config.measurements[1]).to.equal('knee')
|
||||
})
|
||||
|
||||
it('Pattern.__init() should resolve optional measurements', () => {
|
||||
expect(pattern.config.optionalMeasurements.length).to.equal(2)
|
||||
expect(pattern.config.optionalMeasurements).to.have.lengthOf(2)
|
||||
expect(pattern.config.optionalMeasurements[0]).to.equal('chest')
|
||||
expect(pattern.config.optionalMeasurements[1]).to.equal('waist')
|
||||
})
|
||||
|
||||
it('Pattern.__init() should resolve options', () => {
|
||||
expect(Object.keys(pattern.config.options).length).to.equal(3)
|
||||
expect(Object.keys(pattern.config.options)).to.have.lengthOf(3)
|
||||
for (const [key, value] of Object.entries(partA.options.optA)) {
|
||||
expect(pattern.config.options.optA[key]).to.equal(value)
|
||||
}
|
||||
|
@ -149,7 +147,7 @@ describe('Pattern', () => {
|
|||
})
|
||||
|
||||
it('Pattern.__init() should resolve plugins', () => {
|
||||
expect(Object.keys(pattern.config.plugins).length).to.equal(1)
|
||||
expect(Object.keys(pattern.config.plugins)).to.have.lengthOf(1)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should set config data in the store', () => {
|
||||
|
@ -160,12 +158,12 @@ describe('Pattern', () => {
|
|||
it('Pattern.__init() should resolve dependencies', () => {
|
||||
expect(typeof pattern.config.resolvedDependencies).to.equal('object')
|
||||
expect(Array.isArray(pattern.config.resolvedDependencies['test.partA'])).to.equal(true)
|
||||
expect(pattern.config.resolvedDependencies['test.partA'].length).to.equal(0)
|
||||
expect(pattern.config.resolvedDependencies['test.partA']).to.have.lengthOf(0)
|
||||
expect(Array.isArray(pattern.config.resolvedDependencies['test.partB'])).to.equal(true)
|
||||
expect(pattern.config.resolvedDependencies['test.partB'].length).to.equal(1)
|
||||
expect(pattern.config.resolvedDependencies['test.partB']).to.have.lengthOf(1)
|
||||
expect(pattern.config.resolvedDependencies['test.partB'][0]).to.equal('test.partA')
|
||||
expect(Array.isArray(pattern.config.resolvedDependencies['test.partC'])).to.equal(true)
|
||||
expect(pattern.config.resolvedDependencies['test.partC'].length).to.equal(2)
|
||||
expect(pattern.config.resolvedDependencies['test.partC']).to.have.lengthOf(2)
|
||||
expect(
|
||||
pattern.config.resolvedDependencies['test.partC'].indexOf('test.partA') !== -1
|
||||
).to.equal(true)
|
||||
|
@ -325,13 +323,13 @@ describe('Pattern', () => {
|
|||
const design = new Design({ parts: [partC] })
|
||||
const pattern = new design().addPart(partR).draft()
|
||||
// Measurements
|
||||
expect(pattern.config.measurements.length).to.equal(4)
|
||||
expect(pattern.config.measurements).to.have.lengthOf(4)
|
||||
expect(pattern.config.measurements.indexOf('measieA') === -1).to.equal(false)
|
||||
expect(pattern.config.measurements.indexOf('measieB') === -1).to.equal(false)
|
||||
expect(pattern.config.measurements.indexOf('measieC') === -1).to.equal(false)
|
||||
expect(pattern.config.measurements.indexOf('measieR') === -1).to.equal(false)
|
||||
// Optional measurements
|
||||
expect(pattern.config.optionalMeasurements.length).to.equal(4)
|
||||
expect(pattern.config.optionalMeasurements).to.have.lengthOf(4)
|
||||
expect(pattern.config.optionalMeasurements.indexOf('optmeasieA') === -1).to.equal(false)
|
||||
expect(pattern.config.optionalMeasurements.indexOf('optmeasieB') === -1).to.equal(false)
|
||||
expect(pattern.config.optionalMeasurements.indexOf('optmeasieC') === -1).to.equal(false)
|
||||
|
@ -473,13 +471,13 @@ describe('Pattern', () => {
|
|||
const design = new Design({ parts: [partD] })
|
||||
const pattern = new design().draft()
|
||||
// Measurements
|
||||
expect(pattern.config.measurements.length).to.equal(4)
|
||||
expect(pattern.config.measurements).to.have.lengthOf(4)
|
||||
expect(pattern.config.measurements.indexOf('measieA') === -1).to.equal(false)
|
||||
expect(pattern.config.measurements.indexOf('measieB') === -1).to.equal(false)
|
||||
expect(pattern.config.measurements.indexOf('measieC') === -1).to.equal(false)
|
||||
expect(pattern.config.measurements.indexOf('measieD') === -1).to.equal(false)
|
||||
// Optional measurements
|
||||
expect(pattern.config.optionalMeasurements.length).to.equal(4)
|
||||
expect(pattern.config.optionalMeasurements).to.have.lengthOf(4)
|
||||
expect(pattern.config.optionalMeasurements.indexOf('optmeasieA') === -1).to.equal(false)
|
||||
expect(pattern.config.optionalMeasurements.indexOf('optmeasieB') === -1).to.equal(false)
|
||||
expect(pattern.config.optionalMeasurements.indexOf('optmeasieC') === -1).to.equal(false)
|
||||
|
@ -578,7 +576,7 @@ describe('Pattern', () => {
|
|||
const design = new Design({ parts: [part] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
expect(pattern.hooks.preRender.length).to.equal(1)
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(1)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should load array of plugins', () => {
|
||||
|
@ -608,7 +606,7 @@ describe('Pattern', () => {
|
|||
const design = new Design({ parts: [part] })
|
||||
const pattern = new design()
|
||||
pattern.__init()
|
||||
expect(pattern.hooks.preRender.length).to.equal(2)
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(2)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should load conditional plugin if condition is met', () => {
|
||||
|
@ -629,8 +627,8 @@ describe('Pattern', () => {
|
|||
}
|
||||
const design = new Design({ parts: [part] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
expect(pattern.hooks.preRender.length).to.equal(1)
|
||||
pattern.__init()
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(1)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should not load conditional plugin if condition is not mett', () => {
|
||||
|
@ -651,7 +649,7 @@ describe('Pattern', () => {
|
|||
}
|
||||
const design = new Design({ parts: [part] })
|
||||
const pattern = new design()
|
||||
expect(pattern.hooks.preRender.length).to.equal(0)
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should load multiple conditional plugins', () => {
|
||||
|
@ -686,7 +684,7 @@ describe('Pattern', () => {
|
|||
const design = new Design({ parts: [part] })
|
||||
const pattern = new design()
|
||||
pattern.draft()
|
||||
expect(pattern.hooks.preRender.length).to.equal(1)
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(1)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should load a conditional plugin multiple times with different conditions', () => {
|
||||
|
@ -718,7 +716,7 @@ describe('Pattern', () => {
|
|||
expect(pattern.config.plugins).to.be.an('object').that.has.all.keys('example1', 'example1_')
|
||||
expect(pattern.config.plugins.example1.plugin).to.deep.equal(plugin1)
|
||||
expect(pattern.config.plugins.example1_.plugin).to.deep.equal(plugin1)
|
||||
expect(pattern.hooks.preRender.length).to.equal(1)
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(1)
|
||||
})
|
||||
|
||||
it('Load conditional plugins that are also passing data', () => {
|
||||
|
@ -757,7 +755,7 @@ describe('Pattern', () => {
|
|||
})
|
||||
const pattern = new design()
|
||||
pattern.__init()
|
||||
expect(pattern.hooks.preRender.length).to.equal(2)
|
||||
expect(pattern.plugins.hooks.preRender).to.have.lengthOf(2)
|
||||
})
|
||||
|
||||
it('Pattern.__init() should register a hook via on', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue