2022-09-06 16:52:28 +02:00
|
|
|
import { adult, doll, giant } from '@freesewing/models'
|
2023-07-02 16:32:57 +02:00
|
|
|
import { getShortName, isUtilityDesign } from './config.mjs'
|
2024-02-04 12:14:42 +01:00
|
|
|
import { expect } from 'chai'
|
2022-08-27 09:27:35 +02:00
|
|
|
|
|
|
|
// Some patterns are deprecated and won't support more stringent doll/giant tests
|
|
|
|
const deprecated = ['theo']
|
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
/*
|
|
|
|
* 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
|
2020-03-15 16:34:56 +01:00
|
|
|
*/
|
2022-10-06 21:01:58 +02:00
|
|
|
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
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
// Helper method to try/catch pattern sampling
|
2022-10-06 21:01:58 +02:00
|
|
|
const doesItSample = (pattern, log = false) => {
|
2021-09-04 17:46:44 +02:00
|
|
|
try {
|
2022-10-06 21:01:58 +02:00
|
|
|
pattern.sample().render()
|
|
|
|
if (log === 'always') {
|
|
|
|
console.log(pattern.store.logs)
|
2022-11-16 10:58:43 -06:00
|
|
|
console.log(pattern.setStores[pattern.activeSet].logs)
|
2022-10-06 21:01:58 +02:00
|
|
|
}
|
2022-11-16 10:58:43 -06:00
|
|
|
if (
|
|
|
|
pattern.store.logs.error.length < 1 &&
|
|
|
|
pattern.setStores[pattern.activeSet].logs.error.length < 1
|
|
|
|
) {
|
2022-10-06 21:01:58 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (log && log !== 'always') {
|
2022-11-16 10:58:43 -06:00
|
|
|
console.log(pattern.settings[pattern.activeSet])
|
2022-10-06 21:01:58 +02:00
|
|
|
console.log(pattern.store.logs)
|
2022-11-16 10:58:43 -06:00
|
|
|
console.log(pattern.setStores[pattern.activeSet].logs)
|
2022-10-06 21:01:58 +02:00
|
|
|
}
|
|
|
|
|
2021-09-04 17:46:44 +02:00
|
|
|
return false
|
2022-10-06 21:01:58 +02:00
|
|
|
} catch (err) {
|
|
|
|
if (log && log !== 'always') {
|
2022-11-16 10:58:43 -06:00
|
|
|
console.log(pattern.settings[pattern.activeSet])
|
2022-10-06 21:01:58 +02:00
|
|
|
console.log(err)
|
|
|
|
console.log(pattern.store.logs)
|
2022-11-16 10:58:43 -06:00
|
|
|
console.log(pattern.setStores[pattern.activeSet].logs)
|
2022-10-06 21:01:58 +02:00
|
|
|
}
|
|
|
|
|
2021-09-04 17:46:44 +02:00
|
|
|
return false
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|
2023-07-02 16:32:57 +02:00
|
|
|
if (!isUtilityDesign(design)) {
|
2020-03-19 10:44:29 +01:00
|
|
|
/*
|
|
|
|
* Sample different measurements
|
|
|
|
*/
|
2022-10-06 21:01:58 +02:00
|
|
|
describe('Sample measurements:', () => {
|
2022-08-31 17:54:37 +02:00
|
|
|
for (const measurement of config.measurements || []) {
|
2022-10-06 21:01:58 +02:00
|
|
|
it(` Sample ${measurement}:`, () => {
|
|
|
|
expect(
|
|
|
|
doesItSample(
|
|
|
|
new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'measurement',
|
|
|
|
measurement,
|
|
|
|
},
|
|
|
|
measurements: adult.cisFemale['36'],
|
|
|
|
}),
|
|
|
|
log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
2022-08-31 17:54:37 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2020-03-19 10:44:29 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sample different options
|
|
|
|
*/
|
2022-10-06 21:01:58 +02:00
|
|
|
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-08-31 17:54:37 +02:00
|
|
|
}
|
2022-06-30 12:09:35 +02:00
|
|
|
}
|
2022-08-31 17:54:37 +02:00
|
|
|
})
|
2020-03-15 16:34:56 +01:00
|
|
|
|
2020-03-19 10:44:29 +01:00
|
|
|
/*
|
|
|
|
* Sample pattern for different models
|
|
|
|
*/
|
2022-10-06 21:01:58 +02:00
|
|
|
describe(`Sample human measurements:`, () => {
|
2022-09-06 16:52:28 +02:00
|
|
|
for (const type of ['cisFemale', 'cisMale']) {
|
2022-10-06 21:01:58 +02:00
|
|
|
it(`Sample pattern for adult ${type} size range:`, () => {
|
|
|
|
expect(
|
|
|
|
doesItSample(
|
|
|
|
new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'models',
|
|
|
|
models: adult[type],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
2022-08-31 17:54:37 +02:00
|
|
|
})
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
})
|
|
|
|
|
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']) {
|
2022-10-06 21:01:58 +02:00
|
|
|
describe(`Sample ${family} measurements:`, () => {
|
2022-09-06 16:52:28 +02:00
|
|
|
for (const type of ['cisFemale', 'cisMale']) {
|
2022-10-06 21:01:58 +02:00
|
|
|
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)
|
2022-08-31 17:54:37 +02:00
|
|
|
})
|
|
|
|
}
|
2021-09-12 14:03:25 +02:00
|
|
|
})
|
|
|
|
}
|
2021-09-11 15:50:32 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|