1
0
Fork 0

chore: Adapted design tests to latest changes

This commit is contained in:
Joost De Cock 2022-08-31 17:54:37 +02:00
parent 62a55e22f4
commit c68534c132
3 changed files with 110 additions and 129 deletions

View file

@ -25,29 +25,29 @@ export const getFamily = design => {
*/ */
export const testPatternConfig = (Pattern) => { export const testPatternConfig = (Pattern) => {
const pattern = new Pattern() const pattern = new Pattern()
pattern.init() const config = pattern.getConfig()
it('Pattern metadata:', () => true) it('Pattern metadata:', () => true)
it(` - 'name' should be set and be a non-empty string`, () => { it(` - 'name' should be set and be a non-empty string`, () => {
expect(typeof pattern.config.name).to.equal('string') expect(typeof config.name).to.equal('string')
expect(pattern.config.name.length > 1).to.be.true expect(config.name.length > 1).to.be.true
}) })
// //
it(` - 'version' should be set and be a non-empty string`, () => { it(` - 'version' should be set and be a non-empty string`, () => {
expect(typeof pattern.config.version).to.equal('string') expect(typeof config.version).to.equal('string')
expect(pattern.config.version.length > 1).to.be.true expect(config.version.length > 1).to.be.true
}) })
it(` - 'version' should be a proper semantic version`, () => { it(` - 'version' should be a proper semantic version`, () => {
const chunks = pattern.config.version.split('.') const chunks = config.version.split('.')
if (chunks.length > 3) { if (chunks.length > 3) {
expect(pattern.config.version.split('.').length).to.equal(4) expect(config.version.split('.').length).to.equal(4)
expect(chunks[2]).to.contain.oneOf(['-alpha', '-beta', '-rc']) expect(chunks[2]).to.contain.oneOf(['-alpha', '-beta', '-rc'])
} }
else expect(pattern.config.version.split('.').length).to.equal(3) else expect(config.version.split('.').length).to.equal(3)
}) })
it('Monorepo metadata:', () => true) it('Monorepo metadata:', () => true)
// Store these for re-use // Store these for re-use
const shortName = getShortName(pattern.config.name) const shortName = getShortName(config.name)
const family = getFamily(shortName) const family = getFamily(shortName)
it(` - 'name' should be resolvable to a short name`, () => { it(` - 'name' should be resolvable to a short name`, () => {
expect(typeof shortName).to.equal('string') expect(typeof shortName).to.equal('string')
@ -96,34 +96,25 @@ export const testPatternConfig = (Pattern) => {
} }
if (family !== 'utilities') { if (family !== 'utilities') {
// Ensure required measurements are known measurements
// 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 (const measurement of config.measurements || []) {
it(` - '${measurement}' should be a known measurement`, () => { it(` - '${measurement}' should be a known measurement`, () => {
if (measurements.menswear.indexOf(measurement) !== -1) { expect(measurements.indexOf(measurement)).to.not.equal(-1)
expect(measurements.menswear.indexOf(measurement)).to.not.equal(-1)
} else {
expect(measurements.womenswear.indexOf(measurement)).to.not.equal(-1)
}
}) })
} }
it('Optional measurements:', () => true) it('Optional measurements:', () => true)
for (let measurement of pattern.config.optionalMeasurements || []) { for (let measurement of config.optionalMeasurements || []) {
it(` - '${measurement}' should be a known measurement`, () => { it(` - '${measurement}' should be a known measurement`, () => {
if (measurements.menswear.indexOf(measurement) !== -1) { expect(measurements.indexOf(measurement)).to.not.equal(-1)
expect(measurements.menswear.indexOf(measurement)).to.not.equal(-1)
} else {
expect(measurements.womenswear.indexOf(measurement)).to.not.equal(-1)
}
}) })
} }
} }
// 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 (const name in config.options) {
const option = pattern.config.options[name] const option = config.options[name]
const type = typeof option const type = typeof option
if (type === 'object' && typeof option.pct !== 'undefined') { if (type === 'object' && typeof option.pct !== 'undefined') {
it(` - If it has a 'menu' property, it should be a string`, () => { it(` - If it has a 'menu' property, it should be a string`, () => {

View file

@ -1,11 +1,9 @@
import designs from "../../config/software/designs.json" assert { type: 'json' } import designs from "../../config/software/designs.json" assert { type: 'json' }
import { nonHumanMeasurements } from './non-human-measurements.mjs' import { adults, dolls, giants } from '@freesewing/models'
import { withBreasts, withoutBreasts } from '@freesewing/models'
import { getShortName, getFamily } from './config.mjs' import { getShortName, getFamily } from './config.mjs'
import chai from 'chai' import chai from 'chai'
const expect = chai.expect const expect = chai.expect
const models = { withBreasts, withoutBreasts }
// Some patterns are deprecated and won't support more stringent doll/giant tests // Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo'] const deprecated = ['theo']
@ -25,9 +23,6 @@ export const testPatternDrafting = (Pattern, log=false) => {
const family = getFamily(design) const family = getFamily(design)
const parts = pattern.getPartList() const parts = pattern.getPartList()
// Load non-human measurements
const nonHuman = nonHumanMeasurements(models)
// Helper method to try/catch pattern drafting // Helper method to try/catch pattern drafting
const doesItDraftAndRender = (pattern, log=false) => { const doesItDraftAndRender = (pattern, log=false) => {
try { try {
@ -41,64 +36,60 @@ export const testPatternDrafting = (Pattern, log=false) => {
} }
} }
// FIXME: Just use womenswear measurements, as they should always work
const breasts = true
const ourModels = withBreasts
/* /*
* Draft pattern for different models * Draft pattern for different models
*/ */
if (family !== 'utilities') { if (family !== 'utilities') {
it('Draft for humans:', () => true) describe('Draft for humans:', () => {
for (const type of ['sheher', 'hehim']) {
for (let size in ourModels) { describe(type, () => {
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => { for (const size in adults[type]) {
expect( it(` - Drafting for size ${size}`, () => {
doesItDraftAndRender( expect(
new Pattern({ doesItDraftAndRender(
measurements: ourModels[size] new Pattern({
}), log measurements: adults[type][size]
) }), log
).to.equal(true) )
}) ).to.equal(true)
} })
}
})
}
})
if (deprecated.indexOf(design) === -1) { if (deprecated.indexOf(design) === -1) {
// Do the same for fantastical models (dolls, giants) // Do the same for fantastical models (dolls, giants)
it('Draft for dolls:', () => true) const fams = { dolls, giants }
for (const family of ['dolls', 'giants']) {
for (let size in nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls) { describe(`Draft for ${family}:`, () => {
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => { for (const type of ['sheher', 'hehim']) {
expect( describe(type, () => {
doesItDraftAndRender( for (const size in fams[family][type]) {
new Pattern({ it(` - Drafting at ${size}%`, () => {
measurements: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls[size] expect(
}), log doesItDraftAndRender(
) new Pattern({
).to.equal(true) measurements: fams[family][type][size]
}) }), log
} )
).to.equal(true)
it('Draft for giants:', () => true) })
}
for (let size in nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].giants) { })
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => { }
expect(
doesItDraftAndRender(
new Pattern({
measurements: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].giants[size]
}), log
)
).to.equal(true)
}) })
} }
} }
} }
}
/* /*
* Draft parts individually * Draft parts individually
*/ */
/*
it('Draft parts individually:', () => true) it('Draft parts individually:', () => true)
for (const name of parts) { for (const name of parts) {
it(` - ${name} should draft and render on its own`, () => { it(` - ${name} should draft and render on its own`, () => {
@ -112,10 +103,12 @@ export const testPatternDrafting = (Pattern, log=false) => {
).to.equal(true) ).to.equal(true)
}) })
} }
*/
/* /*
* Draft a paperless non-detailed pattern * Draft a paperless non-detailed pattern
*/ */
/*
it('Draft paperless non-detailed pattern:', () => true) it('Draft paperless non-detailed pattern:', () => true)
if (family !== 'utilities') { if (family !== 'utilities') {
for (const sa of [0,10]) { for (const sa of [0,10]) {
@ -134,4 +127,5 @@ export const testPatternDrafting = (Pattern, log=false) => {
} }
} }
} }
*/

View file

@ -1,11 +1,9 @@
import designs from "../../config/software/designs.json" assert { type: 'json' } import designs from "../../config/software/designs.json" assert { type: 'json' }
import { nonHumanMeasurements } from './non-human-measurements.mjs' import { adults, dolls, giants } from '@freesewing/models'
import { withBreasts, withoutBreasts } from '@freesewing/models'
import { getShortName, getFamily } from './config.mjs' import { getShortName, getFamily } from './config.mjs'
import chai from 'chai' import chai from 'chai'
const expect = chai.expect const expect = chai.expect
const models = { withBreasts, withoutBreasts }
// Some patterns are deprecated and won't support more stringent doll/giant tests // Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo'] const deprecated = ['theo']
@ -25,9 +23,6 @@ export const testPatternSampling = (Pattern, log=false) => {
const family = getFamily(design) const family = getFamily(design)
const parts = pattern.getPartList() const parts = pattern.getPartList()
// Load non-human measurements
const nonHuman = nonHumanMeasurements(models)
// Helper method to try/catch pattern sampling // Helper method to try/catch pattern sampling
const doesItSample = (pattern, log=false) => { const doesItSample = (pattern, log=false) => {
try { try {
@ -42,64 +37,61 @@ export const testPatternSampling = (Pattern, log=false) => {
} }
} }
// FIXME: Always use breasts for now
const breasts = true
const ourModels = models
[breasts ? 'withBreasts' : 'withoutBreasts']
const measurements = ourModels
[breasts ? 'size34' : 'size42']
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) { if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/* /*
* Sample different measurements * Sample different measurements
*/ */
it('Sample different measurements:' , () => true) describe('Sample measurements:' , () => {
for (let measurement of Pattern.config.measurements || []) { for (const measurement of config.measurements || []) {
it(` Sample ${measurement}:` , () => { it(` Sample ${measurement}:` , () => {
expect(doesItSample(new Pattern({ expect(doesItSample(new Pattern({
sample: { sample: {
type: 'measurement', type: 'measurement',
measurement measurement
}, },
measurements measurements: adults.sheher["36"]
}), log)).to.equal(true) }), log)).to.equal(true)
}) })
} }
})
} }
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) { if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/* /*
* Sample different options * Sample different options
*/ */
it('Sample different options:' , () => true) describe('Sample options:' , () => {
for (let option in Pattern.config.options) { for (const option in Pattern.config.options) {
if (typeof Pattern.config.options[option] === 'object') { if (typeof Pattern.config.options[option] === 'object') {
it(` Sample ${option}:` , () => { it(` Sample ${option}:` , () => {
expect(doesItSample(new Pattern({ expect(doesItSample(new Pattern({
sample: { sample: {
type: 'option', type: 'option',
option option
}, },
measurements measurements: adults.sheher["36"]
}), log)).to.equal(true) }), log)).to.equal(true)
}) })
}
} }
} })
} }
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) { if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/* /*
* Sample pattern for different models * Sample pattern for different models
*/ */
it('Sample pattern for size range:' , () => { describe(`Sample humans:` , () => {
expect(doesItSample(new Pattern({ for (const type of ['sheher', 'hehim']) {
sample: { it(`Sample pattern for adults ${type} size range:` , () => {
type: 'models', expect(doesItSample(new Pattern({
models: ourModels, sample: {
}, type: 'models',
measurements models: adults[type],
}), log)).to.equal(true) },
}), log)).to.equal(true)
})
}
}) })
} }
@ -108,19 +100,23 @@ export const testPatternSampling = (Pattern, log=false) => {
/* /*
* Sample pattern for dolls & giants * Sample pattern for dolls & giants
*/ */
for (const type of ['dolls', 'giants']) { for (const family of ['dolls', 'giants']) {
it(`Sample pattern for ${type}:` , () => { describe(`Sample ${family}:` , () => {
expect(doesItSample(new Pattern({ for (const type of ['sheher', 'hehim']) {
sample: { it(`Sample pattern for ${family} ${type} size range:` , () => {
type: 'models', expect(doesItSample(new Pattern({
models: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'][type] sample: {
}, type: 'models',
measurements models: family === 'dolls'
}), log)).to.equal(true) ? dolls[type]
: giants[type]
},
}), log)).to.equal(true)
})
}
}) })
} }
} }
} }
} }