1
0
Fork 0
freesewing/tests/designs/sampling.mjs

155 lines
4.2 KiB
JavaScript
Raw Normal View History

2022-09-06 16:52:28 +02:00
import { adult, doll, giant } from '@freesewing/models'
2022-11-16 11:33:32 -06:00
import { getShortName } from './config.mjs'
2022-08-25 11:52:34 +02:00
import chai from 'chai'
const expect = chai.expect
2022-08-27 09:27:35 +02:00
// Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo']
/*
* This runs unit tests for pattern sampling
* It expects the following:
*
2022-08-27 09:27:35 +02:00
* @param object Pattern: Pattern constructor
2022-08-25 11:52:34 +02:00
* @param boolean log: Set to true to log errors
*/
export const testPatternSampling = (Pattern, log = false) => {
const config = Pattern.patternConfig
const design = getShortName(Pattern.designConfig.data.name)
2022-09-14 15:02:39 +02:00
//const parts = pattern.getPartList()
2021-09-12 14:03:25 +02:00
// Helper method to try/catch pattern sampling
const doesItSample = (pattern, log = false) => {
try {
pattern.sample().render()
if (log === 'always') {
console.log(pattern.store.logs)
console.log(pattern.setStores[pattern.activeSet].logs)
}
if (
pattern.store.logs.error.length < 1 &&
pattern.setStores[pattern.activeSet].logs.error.length < 1
) {
return true
}
if (log && log !== 'always') {
console.log(pattern.settings[pattern.activeSet])
console.log(pattern.store.logs)
console.log(pattern.setStores[pattern.activeSet].logs)
}
return false
} catch (err) {
if (log && log !== 'always') {
console.log(pattern.settings[pattern.activeSet])
console.log(err)
console.log(pattern.store.logs)
console.log(pattern.setStores[pattern.activeSet].logs)
}
return false
}
}
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/*
* Sample different measurements
*/
describe('Sample measurements:', () => {
for (const measurement of config.measurements || []) {
it(` Sample ${measurement}:`, () => {
expect(
doesItSample(
new Pattern({
sample: {
type: 'measurement',
measurement,
},
measurements: adult.cisFemale['36'],
}),
log
)
).to.equal(true)
})
}
})
}
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/*
* Sample different options
*/
describe('Sample options:', () => {
for (const option in config.options) {
if (typeof config.options[option] === 'object') {
it(` Sample ${option}:`, () => {
expect(
doesItSample(
new Pattern({
sample: {
type: 'option',
option,
},
measurements: adult.cisFemale['36'],
}),
log
)
).to.equal(true)
})
}
2022-06-30 12:09:35 +02:00
}
})
}
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
/*
* Sample pattern for different models
*/
describe(`Sample human measurements:`, () => {
2022-09-06 16:52:28 +02:00
for (const type of ['cisFemale', 'cisMale']) {
it(`Sample pattern for adult ${type} size range:`, () => {
expect(
doesItSample(
new Pattern({
sample: {
type: 'models',
models: adult[type],
},
}),
log
)
).to.equal(true)
})
}
})
}
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
2021-09-12 14:03:25 +02:00
if (deprecated.indexOf(design) === -1) {
/*
2022-09-06 16:52:28 +02:00
* Sample pattern for doll & giant
2021-09-12 14:03:25 +02:00
*/
2022-09-06 16:52:28 +02:00
for (const family of ['doll', 'giant']) {
describe(`Sample ${family} measurements:`, () => {
2022-09-06 16:52:28 +02:00
for (const type of ['cisFemale', 'cisMale']) {
it(`Sample pattern for ${family} ${type} size range:`, () => {
expect(
doesItSample(
new Pattern({
sample: {
type: 'models',
models: family === 'doll' ? doll[type] : giant[type],
},
}),
log
)
).to.equal(true)
})
}
2021-09-12 14:03:25 +02:00
})
}
}
}
}