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) => {
const pattern = new Pattern()
pattern.init()
const config = pattern.getConfig()
it('Pattern metadata:', () => true)
it(` - 'name' should be set and be a non-empty string`, () => {
expect(typeof pattern.config.name).to.equal('string')
expect(pattern.config.name.length > 1).to.be.true
expect(typeof config.name).to.equal('string')
expect(config.name.length > 1).to.be.true
})
//
it(` - 'version' should be set and be a non-empty string`, () => {
expect(typeof pattern.config.version).to.equal('string')
expect(pattern.config.version.length > 1).to.be.true
expect(typeof config.version).to.equal('string')
expect(config.version.length > 1).to.be.true
})
it(` - 'version' should be a proper semantic version`, () => {
const chunks = pattern.config.version.split('.')
const chunks = config.version.split('.')
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'])
}
else expect(pattern.config.version.split('.').length).to.equal(3)
else expect(config.version.split('.').length).to.equal(3)
})
it('Monorepo metadata:', () => true)
// Store these for re-use
const shortName = getShortName(pattern.config.name)
const shortName = getShortName(config.name)
const family = getFamily(shortName)
it(` - 'name' should be resolvable to a short name`, () => {
expect(typeof shortName).to.equal('string')
@ -96,34 +96,25 @@ export const testPatternConfig = (Pattern) => {
}
if (family !== 'utilities') {
// Ensure required measurements are known measurements
// Ensure required measurements are known measurements
it('Required measurements:', () => true)
for (let measurement of pattern.config.measurements || []) {
for (const measurement of config.measurements || []) {
it(` - '${measurement}' should be a known measurement`, () => {
if (measurements.menswear.indexOf(measurement) !== -1) {
expect(measurements.menswear.indexOf(measurement)).to.not.equal(-1)
} else {
expect(measurements.womenswear.indexOf(measurement)).to.not.equal(-1)
}
expect(measurements.indexOf(measurement)).to.not.equal(-1)
})
}
it('Optional measurements:', () => true)
for (let measurement of pattern.config.optionalMeasurements || []) {
for (let measurement of config.optionalMeasurements || []) {
it(` - '${measurement}' should be a known measurement`, () => {
if (measurements.menswear.indexOf(measurement) !== -1) {
expect(measurements.menswear.indexOf(measurement)).to.not.equal(-1)
} else {
expect(measurements.womenswear.indexOf(measurement)).to.not.equal(-1)
}
expect(measurements.indexOf(measurement)).to.not.equal(-1)
})
}
}
// Test validity of the pattern's options
it('Pattern options:', () => true)
for (let name in pattern.config.options) {
const option = pattern.config.options[name]
for (const name in config.options) {
const option = config.options[name]
const type = typeof option
if (type === 'object' && typeof option.pct !== 'undefined') {
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 { nonHumanMeasurements } from './non-human-measurements.mjs'
import { withBreasts, withoutBreasts } from '@freesewing/models'
import { adults, dolls, giants } from '@freesewing/models'
import { getShortName, getFamily } from './config.mjs'
import chai from 'chai'
const expect = chai.expect
const models = { withBreasts, withoutBreasts }
// Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo']
@ -25,9 +23,6 @@ export const testPatternDrafting = (Pattern, log=false) => {
const family = getFamily(design)
const parts = pattern.getPartList()
// Load non-human measurements
const nonHuman = nonHumanMeasurements(models)
// Helper method to try/catch pattern drafting
const doesItDraftAndRender = (pattern, log=false) => {
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
*/
if (family !== 'utilities') {
it('Draft for humans:', () => true)
for (let size in ourModels) {
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
expect(
doesItDraftAndRender(
new Pattern({
measurements: ourModels[size]
}), log
)
).to.equal(true)
})
}
describe('Draft for humans:', () => {
for (const type of ['sheher', 'hehim']) {
describe(type, () => {
for (const size in adults[type]) {
it(` - Drafting for size ${size}`, () => {
expect(
doesItDraftAndRender(
new Pattern({
measurements: adults[type][size]
}), log
)
).to.equal(true)
})
}
})
}
})
if (deprecated.indexOf(design) === -1) {
// Do the same for fantastical models (dolls, giants)
it('Draft for dolls:', () => true)
for (let size in nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls) {
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
expect(
doesItDraftAndRender(
new Pattern({
measurements: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls[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)
const fams = { dolls, giants }
for (const family of ['dolls', 'giants']) {
describe(`Draft for ${family}:`, () => {
for (const type of ['sheher', 'hehim']) {
describe(type, () => {
for (const size in fams[family][type]) {
it(` - Drafting at ${size}%`, () => {
expect(
doesItDraftAndRender(
new Pattern({
measurements: fams[family][type][size]
}), log
)
).to.equal(true)
})
}
})
}
})
}
}
}
}
/*
* Draft parts individually
*/
/*
it('Draft parts individually:', () => true)
for (const name of parts) {
it(` - ${name} should draft and render on its own`, () => {
@ -112,10 +103,12 @@ export const testPatternDrafting = (Pattern, log=false) => {
).to.equal(true)
})
}
*/
/*
* Draft a paperless non-detailed pattern
*/
/*
it('Draft paperless non-detailed pattern:', () => true)
if (family !== 'utilities') {
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 { nonHumanMeasurements } from './non-human-measurements.mjs'
import { withBreasts, withoutBreasts } from '@freesewing/models'
import { adults, dolls, giants } from '@freesewing/models'
import { getShortName, getFamily } from './config.mjs'
import chai from 'chai'
const expect = chai.expect
const models = { withBreasts, withoutBreasts }
// Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo']
@ -25,9 +23,6 @@ export const testPatternSampling = (Pattern, log=false) => {
const family = getFamily(design)
const parts = pattern.getPartList()
// Load non-human measurements
const nonHuman = nonHumanMeasurements(models)
// Helper method to try/catch pattern sampling
const doesItSample = (pattern, log=false) => {
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) {
/*
* Sample different measurements
*/
it('Sample different measurements:' , () => true)
for (let measurement of Pattern.config.measurements || []) {
it(` Sample ${measurement}:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'measurement',
measurement
},
measurements
}), log)).to.equal(true)
})
}
describe('Sample measurements:' , () => {
for (const measurement of config.measurements || []) {
it(` Sample ${measurement}:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'measurement',
measurement
},
measurements: adults.sheher["36"]
}), log)).to.equal(true)
})
}
})
}
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/*
* Sample different options
*/
it('Sample different options:' , () => true)
for (let option in Pattern.config.options) {
if (typeof Pattern.config.options[option] === 'object') {
it(` Sample ${option}:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'option',
option
},
measurements
}), log)).to.equal(true)
})
describe('Sample options:' , () => {
for (const option in Pattern.config.options) {
if (typeof Pattern.config.options[option] === 'object') {
it(` Sample ${option}:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'option',
option
},
measurements: adults.sheher["36"]
}), log)).to.equal(true)
})
}
}
}
})
}
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/*
* Sample pattern for different models
*/
it('Sample pattern for size range:' , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'models',
models: ourModels,
},
measurements
}), log)).to.equal(true)
describe(`Sample humans:` , () => {
for (const type of ['sheher', 'hehim']) {
it(`Sample pattern for adults ${type} size range:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'models',
models: adults[type],
},
}), log)).to.equal(true)
})
}
})
}
@ -108,19 +100,23 @@ export const testPatternSampling = (Pattern, log=false) => {
/*
* Sample pattern for dolls & giants
*/
for (const type of ['dolls', 'giants']) {
it(`Sample pattern for ${type}:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'models',
models: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'][type]
},
measurements
}), log)).to.equal(true)
for (const family of ['dolls', 'giants']) {
describe(`Sample ${family}:` , () => {
for (const type of ['sheher', 'hehim']) {
it(`Sample pattern for ${family} ${type} size range:` , () => {
expect(doesItSample(new Pattern({
sample: {
type: 'models',
models: family === 'dolls'
? dolls[type]
: giants[type]
},
}), log)).to.equal(true)
})
}
})
}
}
}
}