
This plugin is used to draft designs for high bust rather than full chest circumference. To facilitate that, we provide(d) a named export called `withCondition` that checks whether the plugin is wanted, and if so loads it. Problem with that is that the conditional loading of a plugin applied to the entire pattern. And since we support drafting patterns for multiple sets (and use this to sample) this means that all of these sets would either get the plugin effect or not, based on the first set. So, to fix that, we have changed the lifecycle hook used by this plugin to `preSetDraft` (from `preDraft`) and changed the `withCondition` method to always return true. This means that the plugin will always be loaded, and we have moved the check that used to be in `withCondition` to the lifecycle hook. In other words, this plugin will now always be loaded and will check for each set whether it needs to do something. This allows the conditionality to apply to each set in the pattern, rather than to the entire pattern. Note that conditionally loading plugins pattern-wide is still a valid use-case. It just so happens that for this plugin, it was the wrong approach.
41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
import { expect } from 'chai'
|
|
import { Design } from '@freesewing/core'
|
|
import { plugin } from '../src/index.mjs'
|
|
|
|
const measurements = {
|
|
chest: 100,
|
|
highBust: 90,
|
|
}
|
|
const options = { draftForHighBust: true }
|
|
|
|
const Pattern = new Design()
|
|
const pattern = new Pattern({ measurements, options }).use(plugin)
|
|
pattern.draft()
|
|
|
|
describe('Bust plugin Tests', () => {
|
|
it('Should set swap the chest measurements', () => {
|
|
expect(pattern.settings[0].measurements.bust).to.equal(100)
|
|
expect(pattern.settings[0].measurements.chest).to.equal(90)
|
|
})
|
|
|
|
it('Should copy measurement from chest to bust and from highBust to chest', function () {
|
|
const testPattern = new Design({ measurements: [], options })
|
|
const pattern = new testPattern().use(plugin)
|
|
const userMeasurements = { chest: 50, highBust: 60 }
|
|
pattern.settings[0].measurements = userMeasurements
|
|
pattern.draft()
|
|
expect(pattern.settings[0].measurements.bust).to.equal(50)
|
|
expect(pattern.settings[0].measurements.chest).to.equal(60)
|
|
})
|
|
|
|
it('Should not overwrite existing bust measurements', function () {
|
|
let config = { measurements: [], options }
|
|
const testPattern = new Design(config, plugin)
|
|
let pattern = new testPattern()
|
|
let userMeasurements = { chest: 50, highBust: 60, bust: 55 }
|
|
pattern.settings[0].measurements = userMeasurements
|
|
pattern.draft()
|
|
expect(pattern.settings[0].measurements.bust).to.equal(55)
|
|
expect(pattern.settings[0].measurements.chest).to.equal(50)
|
|
})
|
|
})
|