1
0
Fork 0

chore: Adapted tests for legend pattern

This commit is contained in:
Joost De Cock 2020-05-31 17:58:36 +02:00
parent bf730ba8af
commit 10471bab38
2 changed files with 52 additions and 54 deletions

View file

@ -10,8 +10,7 @@
* @param object patterns: Imported @freesewing/pattern-info * @param object patterns: Imported @freesewing/pattern-info
*/ */
const testPatternConfig = (design, pattern, expect, models, patterns) => { const testPatternConfig = (design, pattern, expect, models, patterns) => {
it('Metadata:', () => true)
it('Metadata:' , () => true)
it(` - 'name' should match package name`, () => { it(` - 'name' should match package name`, () => {
expect(pattern.config.name).to.equal(design) expect(pattern.config.name).to.equal(design)
}) })
@ -35,7 +34,9 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
expect(['pattern', 'block'].indexOf(pattern.config.type)).to.not.equal(-1) expect(['pattern', 'block'].indexOf(pattern.config.type)).to.not.equal(-1)
}) })
it(` - 'department' should be one of menswear, womenswear, unisex, or accessories`, () => { it(` - 'department' should be one of menswear, womenswear, unisex, or accessories`, () => {
expect(['menswear', 'womenswear', 'unisex', 'accessories'].indexOf(pattern.config.department)).to.not.equal(-1) expect(
['menswear', 'womenswear', 'unisex', 'accessories'].indexOf(pattern.config.department)
).to.not.equal(-1)
}) })
it(` - 'difficulty' should be a number between 1 and 5`, () => { it(` - 'difficulty' should be a number between 1 and 5`, () => {
expect(typeof pattern.config.difficulty).to.equal('number') expect(typeof pattern.config.difficulty).to.equal('number')
@ -43,11 +44,10 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
expect(pattern.config.difficulty < 6).to.be.true expect(pattern.config.difficulty < 6).to.be.true
}) })
/* /*
* Ensure optiongroup structure and content * Ensure optiongroup structure and content
*/ */
it('Option groups:' , () => true) it('Option groups:', () => true)
for (let group in pattern.config.optionGroups) { for (let group in pattern.config.optionGroups) {
for (let option of pattern.config.optionGroups[group]) { for (let option of pattern.config.optionGroups[group]) {
if (typeof option === 'string') { if (typeof option === 'string') {
@ -56,7 +56,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
}) })
} else { } else {
for (let subgroup in option) { for (let subgroup in option) {
it(` Subgroup: ${subgroup}` , () => true) it(` Subgroup: ${subgroup}`, () => true)
for (let suboption of option[subgroup]) { for (let suboption of option[subgroup]) {
it(` - '${suboption}' should be a valid option`, () => { it(` - '${suboption}' should be a valid option`, () => {
expect(pattern.config.options[suboption]).to.exist expect(pattern.config.options[suboption]).to.exist
@ -67,8 +67,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
} }
} }
if (['rendertest', 'tutorial', 'examples', 'legend'].indexOf(design) === -1) {
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/* /*
* Ensure pattern is listed as being for breasts or not * Ensure pattern is listed as being for breasts or not
*/ */
@ -84,14 +83,15 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
expect(result).to.be.true expect(result).to.be.true
}) })
/* /*
* Ensure required measurements are known measurements * Ensure required measurements are known measurements
*/ */
it('Required measurements:' , () => true) it('Required measurements:', () => true)
for (let measurement of pattern.config.measurements) { for (let measurement of pattern.config.measurements) {
it(` - '${measurement}' should be a known measurement`, () => { it(` - '${measurement}' should be a known measurement`, () => {
expect(models.measurements[breasts ? 'womenswear' : 'menswear'].indexOf(measurement)).to.not.equal(-1) expect(
models.measurements[breasts ? 'womenswear' : 'menswear'].indexOf(measurement)
).to.not.equal(-1)
}) })
} }
} }
@ -99,7 +99,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
/* /*
* Test validity of the pattern's options * Test validity of the pattern's options
*/ */
it('Pattern options:' , () => true) it('Pattern options:', () => true)
for (let name in pattern.config.options) { for (let name in pattern.config.options) {
let option = pattern.config.options[name] let option = pattern.config.options[name]
let type = typeof option let type = typeof option
@ -115,8 +115,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
it(` - Should have a maximum >= the default value`, () => { it(` - Should have a maximum >= the default value`, () => {
expect(option.max >= option.pct).to.be.true expect(option.max >= option.pct).to.be.true
}) })
} } else if (type === 'object' && typeof option.deg !== 'undefined') {
else if (type === 'object' && typeof option.deg !== 'undefined') {
// Degree option // Degree option
it(` - '${name}' is a degree option`, () => true) it(` - '${name}' is a degree option`, () => true)
it(` - Should have a default value`, () => { it(` - Should have a default value`, () => {
@ -128,8 +127,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
it(` - Should have a maximum >= the default value`, () => { it(` - Should have a maximum >= the default value`, () => {
expect(option.max >= option.deg).to.be.true expect(option.max >= option.deg).to.be.true
}) })
} } else if (type === 'object' && typeof option.mm !== 'undefined') {
else if (type === 'object' && typeof option.mm !== 'undefined') {
// Millimeter option // Millimeter option
it(` - '${name}' is a distance (mm) option`, () => true) it(` - '${name}' is a distance (mm) option`, () => true)
it(` - Should have a default value`, () => { it(` - Should have a default value`, () => {
@ -141,8 +139,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
it(` - Should have a maximum >= the default value`, () => { it(` - Should have a maximum >= the default value`, () => {
expect(option.max >= option.mm).to.be.true expect(option.max >= option.mm).to.be.true
}) })
} } else if (type === 'object' && typeof option.bool !== 'undefined') {
else if (type === 'object' && typeof option.bool !== 'undefined') {
// Boolean option // Boolean option
it(` - '${name}' is a boolean option`, () => true) it(` - '${name}' is a boolean option`, () => true)
it(` - Should have a default value`, () => { it(` - Should have a default value`, () => {
@ -151,8 +148,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
it(` - Default value should be one of TRUE or FALSE`, () => { it(` - Default value should be one of TRUE or FALSE`, () => {
expect([true, false].indexOf(option.bool)).to.not.equal(-1) expect([true, false].indexOf(option.bool)).to.not.equal(-1)
}) })
} } else if (type === 'object' && typeof option.count !== 'undefined') {
else if (type === 'object' && typeof option.count !== 'undefined') {
// Count option // Count option
it(` - '${name}' is a count option`, () => true) it(` - '${name}' is a count option`, () => true)
it(` - Should have a default value`, () => { it(` - Should have a default value`, () => {
@ -164,8 +160,7 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
it(` - Should have a maximum >= the default value`, () => { it(` - Should have a maximum >= the default value`, () => {
expect(option.max >= option.count).to.be.true expect(option.max >= option.count).to.be.true
}) })
} } else if (type === 'object' && typeof option.list !== 'undefined') {
else if (type === 'object' && typeof option.list !== 'undefined') {
// List option // List option
it(` - '${name}' is a list option`, () => true) it(` - '${name}' is a list option`, () => true)
it(` - Should have a default value`, () => { it(` - Should have a default value`, () => {
@ -177,12 +172,10 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
it(` - Its options should be an array of numbers or strings`, () => { it(` - Its options should be an array of numbers or strings`, () => {
for (let o of option.list) expect(['number', 'string'].indexOf(typeof o)).to.not.equal(-1) for (let o of option.list) expect(['number', 'string'].indexOf(typeof o)).to.not.equal(-1)
}) })
} } else if (type === 'number') {
else if (type === 'number') {
// Static number // Static number
return true return true
} } else if (type === 'string') {
else if (type === 'string') {
// Static string // Static string
return true return true
} }

View file

@ -10,37 +10,37 @@
* @param object patterns: Imported @freesewing/pattern-info * @param object patterns: Imported @freesewing/pattern-info
*/ */
const testPatternDrafting = (design, Pattern, expect, models, patterns) => { const testPatternDrafting = (design, Pattern, expect, models, patterns) => {
// Helper method to try/catch pattern drafting // Helper method to try/catch pattern drafting
const doesItDraft = pattern => { const doesItDraft = (pattern) => {
try { try {
pattern.draft() pattern.draft()
return true return true
} } catch (err) {
catch (err) { return false
return false }
}
} }
// Figure out whether this is a with(out)breasts pattern // Figure out whether this is a with(out)breasts pattern
const breasts = (patterns.withBreasts.indexOf(design) === -1) ? false : true const breasts = patterns.withBreasts.indexOf(design) === -1 ? false : true
const ourModels = models const ourModels = models[breasts ? 'withBreasts' : 'withoutBreasts']
[breasts ? 'withBreasts' : 'withoutBreasts'] const measurements = ourModels[breasts ? 'size34' : 'size42']
const measurements = ourModels
[breasts ? 'size34' : 'size42']
/* /*
* Draft pattern for different models * Draft pattern for different models
*/ */
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) { if (['rendertest', 'tutorial', 'examples', 'legend'].indexOf(design) === -1) {
it('Draft for different models:' , () => true) it('Draft for different models:', () => true)
for (let size in ourModels) { for (let size in ourModels) {
it(` - Drafting for ${size} (${breasts ? 'with':'no'} breasts)`, () => { it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
expect(doesItDraft(new Pattern({ expect(
measurements: ourModels[size], doesItDraft(
}))).to.equal(true) new Pattern({
measurements: ourModels[size]
})
)
).to.equal(true)
}) })
} }
} }
@ -48,18 +48,23 @@ const testPatternDrafting = (design, Pattern, expect, models, patterns) => {
/* /*
* Draft parts individually * Draft parts individually
*/ */
it('Draft parts individually:' , () => true) it('Draft parts individually:', () => true)
let parts let parts
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) parts = patterns.parts[design] if (['rendertest', 'tutorial', 'examples', 'legend'].indexOf(design) === -1)
parts = patterns.parts[design]
else parts = Pattern.config.parts else parts = Pattern.config.parts
for (let name of parts) { for (let name of parts) {
it(` - ${name} should draft on its own`, () => { it(` - ${name} should draft on its own`, () => {
expect(doesItDraft(new Pattern({ expect(
measurements, doesItDraft(
settings: { new Pattern({
only: [name] measurements,
} settings: {
}))).to.equal(true) only: [name]
}
})
)
).to.equal(true)
}) })
} }
} }