1
0
Fork 0

wip: Work on design init

This commit is contained in:
Joost De Cock 2022-09-24 12:44:41 +02:00 committed by joostdecock
parent f0e233513b
commit 485492e452
7 changed files with 307 additions and 280 deletions

View file

@ -5,6 +5,8 @@ const expect = chai.expect
describe('Pattern', () => {
describe('Pattern.constructor()', () => {
/*
it('Pattern constructor should return pattern object', () => {
const Pattern = new Design()
const pattern = new Pattern()
@ -15,10 +17,10 @@ describe('Pattern', () => {
const Pattern = new Design()
const pattern = new Pattern()
expect(Array.isArray(pattern.settings)).to.equal(true)
expect(Array.isArray(pattern.stores)).to.equal(true)
expect(Array.isArray(pattern.setStores)).to.equal(true)
expect(typeof pattern.store).to.equal('object')
expect(typeof pattern.config).to.equal('object')
expect(typeof pattern.store).to.equal('undefined')
expect(Object.keys(pattern).length).to.equal(4)
expect(Object.keys(pattern).length).to.equal(6)
})
it('Pattern constructor should add non-enumerable properties', () => {
@ -146,7 +148,7 @@ describe('Pattern', () => {
})
it('Pattern.__init() should resolve parts', () => {
expect(pattern.config.parts.length).to.equal(3)
expect(pattern.designConfig.parts.length).to.equal(3)
})
it('Pattern.__init() should resolve plugins', () => {
@ -154,8 +156,8 @@ describe('Pattern', () => {
})
it('Pattern.__init() should set config data in the store', () => {
expect(pattern.stores[0].get('data.name')).to.equal('test')
expect(pattern.stores[0].get('data.version')).to.equal('1.2.3')
expect(pattern.setStores[0].get('data.name')).to.equal('test')
expect(pattern.setStores[0].get('data.version')).to.equal('1.2.3')
})
it('Pattern.__init() should resolve dependencies', () => {
@ -518,12 +520,17 @@ describe('Pattern', () => {
},
},
}
const design = new Design({ plugins: [plugin1, plugin2] })
const part = {
name: 'test.part',
plugins: [ plugin1, plugin2 ],
draft: (part) => part,
}
const design = new Design({ parts: [part] })
const pattern = new design()
pattern.__init()
expect(pattern.hooks.preRender.length).to.equal(2)
})
it('Pattern.__init() should load conditional plugin', () => {
const plugin = {
name: 'example',
@ -535,9 +542,14 @@ describe('Pattern', () => {
},
}
const condition = () => true
const design = new Design({ plugins: [{ plugin, condition }] })
const part = {
name: 'test.part',
plugins: [ { plugin, condition } ],
draft: (part) => part,
}
const design = new Design({ parts: [ part ] })
const pattern = new design()
pattern.__init()
pattern.draft()
expect(pattern.hooks.preRender.length).to.equal(1)
})
@ -552,11 +564,15 @@ describe('Pattern', () => {
},
}
const condition = () => false
const design = new Design({ plugins: { plugin, condition } })
const part = {
name: 'test.part',
plugins: [ { plugin, condition } ],
draft: (part) => part,
}
const design = new Design({ parts: [ part ] })
const pattern = new design()
expect(pattern.hooks.preRender.length).to.equal(0)
})
it('Pattern.__init() should load multiple conditional plugins', () => {
const plugin = {
name: 'example',
@ -569,16 +585,20 @@ describe('Pattern', () => {
}
const condition1 = () => true
const condition2 = () => false
const design = new Design({
const part = {
name: 'test.part',
plugins: [
{ plugin, condition: condition1 },
{ plugin, condition: condition2 },
],
})
draft: (part) => part,
}
const design = new Design({ parts: [ part ] })
const pattern = new design()
pattern.__init()
expect(pattern.hooks.preRender.length).to.equal(1)
})
*/
it('Load conditional plugins that are also passing data', () => {
const plugin1 = {
@ -604,7 +624,7 @@ describe('Pattern', () => {
const part1 = {
name: 'part1',
plugins: [
[plugin1, {} ],
[plugin1, { some: 'data'} ],
{ plugin: plugin2, condition: condition1 }
],
draft: ({ part }) => part
@ -618,13 +638,17 @@ describe('Pattern', () => {
draft: ({ part }) => part
}
const design = new Design({
parts: [ part1, part2 ]
parts: [ part1 ]
})
const pattern = new design()
pattern.__init()
//console.log(pattern.store.logs)
console.log(pattern.config)
//console.log(pattern.hooks)
expect(pattern.hooks.preRender.length).to.equal(2)
})
/*
it('Pattern.__init() should register a hook via on', () => {
const Pattern = new Design()
const pattern = new Pattern()
@ -776,5 +800,6 @@ describe('Pattern', () => {
const pattern = new Pattern()
expect(() => pattern.__init()).to.throw()
})
*/
})
})