1
0
Fork 0

fix (core) resolve after depenndencies before from dependencies

This commit is contained in:
Enoch Riese 2023-05-22 16:16:05 -05:00
parent b30e99f294
commit cc143153b2
3 changed files with 224 additions and 32 deletions

View file

@ -1,5 +1,6 @@
import chai from 'chai'
import { Design } from '../src/index.mjs'
import { fixturePart } from './fixtures/part.mjs'
const expect = chai.expect
@ -945,4 +946,184 @@ describe('Pattern', () => {
expect('' + error).to.contain('Unknown option type')
})
})
describe('Draft Order', () => {
describe('With no dependencies', () => {
it('Draft order should be the same the parts order in the config', () => {
const expectedMembers = []
const parts = []
for (var i = 0; i < 4; i++) {
let name = `part${i + 1}`
expectedMembers.push(name)
parts.push({ name, draft: (part) => part })
}
const Pattern = new Design({ parts })
const pattern = new Pattern().__init()
expect(pattern.config.draftOrder).to.have.ordered.members(expectedMembers)
})
})
describe('With simple dependencies', () => {
const afterPart = fixturePart('afterPart')
const fromPart = fixturePart('fromPart')
it('After dependencies should come before the parts that depend on them', () => {
const mainPart = fixturePart('mainPart', {
after: afterPart,
})
const Pattern = new Design({ parts: [mainPart] })
const pattern = new Pattern().__init()
expect(pattern.config.draftOrder).to.have.ordered.members(['afterPart', 'mainPart'])
})
it('After dependencies should be resolved in the order they are added to the part config', () => {
const secondAfter = fixturePart('secondAfter')
const mainPart = fixturePart('mainPart', {
after: [afterPart, secondAfter],
})
const Pattern = new Design({ parts: [mainPart] })
const pattern = new Pattern().__init()
expect(pattern.config.draftOrder).to.have.ordered.members([
'afterPart',
'secondAfter',
'mainPart',
])
})
it('From dependencies should come before the parts that depend on them', () => {
const mainPart = fixturePart('mainPart', {
from: fromPart,
})
const Pattern = new Design({ parts: [mainPart] })
const pattern = new Pattern().__init()
expect(pattern.config.draftOrder).to.have.ordered.members(['fromPart', 'mainPart'])
})
it('After dependencies should come before from dependencies', () => {
const mainPart = fixturePart('mainPart', {
after: afterPart,
from: fromPart,
})
const Pattern = new Design({ parts: [mainPart] })
const pattern = new Pattern().__init()
expect(pattern.config.draftOrder).to.have.ordered.members([
'afterPart',
'fromPart',
'mainPart',
])
})
})
describe('With Complex dependencies', () => {
it('After dependencies should come before the entire from dependency chain', () => {
const inheritedFrontBase = fixturePart('inheritedFrontBase')
const blockWaistband = fixturePart('blockWaistband')
const inheritedWaistbandBase = fixturePart('inheritedWaistbandBase', {
from: blockWaistband,
after: inheritedFrontBase,
})
const inheritedBase = fixturePart('inheritedBase')
const inheritedWaistband = fixturePart('inheritedWaistband', {
from: inheritedWaistbandBase,
after: inheritedBase,
})
const mainBack = fixturePart('mainBack')
const inheritedFront = fixturePart('inheritedFront')
const mainFront = fixturePart('mainFront', {
after: mainBack,
from: inheritedFront,
})
const mainWaistband = fixturePart('mainWaistband', {
from: inheritedWaistband,
after: mainFront,
})
const Pattern = new Design({ parts: [mainWaistband] })
const pattern = new Pattern().__init()
/**
* chain:
* mainWaistBand
* after: mainFront
* after: mainBack
* from: inheritedFront
* from: inheritedWaistband
* after: inheritedBase
* from: inheritedWaistbandBase
* after: inheritedFrontBase
* from: blockWaistband
*/
expect(pattern.config.draftOrder).to.have.ordered.members([
'mainBack',
'inheritedFront',
'mainFront',
'inheritedBase',
'inheritedFrontBase',
'blockWaistband',
'inheritedWaistbandBase',
'inheritedWaistband',
'mainWaistband',
])
})
it('Parts with multiple dependents should come before all dependency chains', () => {
const inheritedFrontBase = fixturePart('inheritedFrontBase')
const blockWaistband = fixturePart('blockWaistband')
const inheritedWaistbandBase = fixturePart('inheritedWaistbandBase', {
from: blockWaistband,
after: inheritedFrontBase,
})
const inheritedBase = fixturePart('inheritedBase')
const inheritedWaistband = fixturePart('inheritedWaistband', {
from: inheritedWaistbandBase,
after: inheritedBase,
})
const inheritedFront = fixturePart('inheritedFront')
const mainBack = fixturePart('mainBack', {
from: inheritedFront,
after: inheritedBase,
})
const mainFront = fixturePart('mainFront', {
after: mainBack,
from: inheritedFront,
})
const mainWaistband = fixturePart('mainWaistband', {
from: inheritedWaistband,
after: mainFront,
})
const Pattern = new Design({ parts: [mainWaistband] })
const pattern = new Pattern().__init()
/**
* chain:
* mainWaistBand
* after: mainFront
* after: mainBack
* after: inheritedBase
* from: inheritedFront
* from: inheritedFront
* from: inheritedWaistband
* after: inheritedBase
* from: inheritedWaistbandBase
* after: inheritedFrontBase
* from: blockWaistband
*/
expect(pattern.config.draftOrder).to.have.ordered.members([
'inheritedBase',
'inheritedFront',
'mainBack',
'mainFront',
'inheritedFrontBase',
'blockWaistband',
'inheritedWaistbandBase',
'inheritedWaistband',
'mainWaistband',
])
})
})
})
})