2022-09-06 16:52:28 +02:00
|
|
|
import { adult, doll, giant } from '@freesewing/models'
|
2025-04-01 16:15:20 +02:00
|
|
|
import { getShortName } 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
|
|
|
}
|
|
|
|
|
2025-04-12 07:51:23 +00:00
|
|
|
const doesItDraftAndRender = (pattern, log = false) => {
|
|
|
|
try {
|
|
|
|
pattern.draft().render()
|
|
|
|
if (log) {
|
|
|
|
console.log(pattern.store.logs)
|
|
|
|
console.log(pattern.setStores[0].logs)
|
|
|
|
}
|
|
|
|
if (pattern.store.logs.error.length < 1 && pattern.setStores[0].logs.error.length < 1)
|
|
|
|
return true
|
|
|
|
return false
|
|
|
|
} catch (err) {
|
|
|
|
if (log) console.log(err)
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-01 16:15:20 +02:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sample different options
|
|
|
|
*/
|
|
|
|
describe('Sample options:', () => {
|
2025-04-12 07:51:23 +00:00
|
|
|
let hasSampledCoreSettings = false
|
|
|
|
for (const option in config.options) {
|
|
|
|
let saValues = [0, 10]
|
|
|
|
let paperlessValues = [false, true]
|
|
|
|
let completeValues = [true, false]
|
|
|
|
if (option.list || option.bool) {
|
|
|
|
hasSampledCoreSettings = true
|
|
|
|
} else {
|
|
|
|
// Performance optimization:
|
|
|
|
// sample different sa and paperless/complete settings only for options,
|
|
|
|
// which likely change the pattern structure (e.g. enable/disable parts).
|
|
|
|
// These are 'list' and 'bool' options.
|
|
|
|
// The hasSampledCoreSettings variable is used to ensure that all variants are tested at least once,
|
|
|
|
// even if no such options are present.
|
|
|
|
saValues = [0]
|
|
|
|
paperlessValues = [false]
|
|
|
|
completeValues = [true]
|
|
|
|
}
|
|
|
|
for (const sa of saValues) {
|
|
|
|
for (const complete of completeValues) {
|
|
|
|
for (const paperless of paperlessValues) {
|
|
|
|
if (typeof config.options[option] === 'object') {
|
|
|
|
it(` Sample ${option} with sa:${sa} complete:${complete} paperless:${paperless}`, () => {
|
|
|
|
expect(
|
|
|
|
doesItSample(
|
|
|
|
new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'option',
|
|
|
|
option,
|
|
|
|
},
|
|
|
|
measurements: adult.cisFemale['36'],
|
|
|
|
sa: sa,
|
|
|
|
complete: complete,
|
|
|
|
paperless: paperless,
|
|
|
|
}),
|
|
|
|
log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-31 17:54:37 +02:00
|
|
|
}
|
2025-04-12 07:51:23 +00:00
|
|
|
if (!hasSampledCoreSettings) {
|
|
|
|
// test core settings without sampling a specific option
|
|
|
|
let saValues = [0, 10]
|
|
|
|
let paperlessValues = [false, true]
|
|
|
|
let completeValues = [true, false]
|
|
|
|
for (const sa of saValues) {
|
|
|
|
for (const complete of completeValues) {
|
|
|
|
for (const paperless of paperlessValues) {
|
|
|
|
it(` Draft sa:${sa} complete:${complete} paperless:${paperless}`, () => {
|
|
|
|
expect(
|
|
|
|
doesItDraftAndRender(
|
|
|
|
new Pattern({
|
|
|
|
measurements: adult.cisFemale['36'],
|
|
|
|
sa: sa,
|
|
|
|
complete: complete,
|
|
|
|
paperless: paperless,
|
|
|
|
}),
|
|
|
|
log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2025-04-01 16:15:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sample pattern for different models
|
|
|
|
*/
|
|
|
|
describe(`Sample human measurements:`, () => {
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2020-03-19 10:44:29 +01:00
|
|
|
|
2025-04-01 16:15:20 +02:00
|
|
|
if (deprecated.indexOf(design) === -1) {
|
2020-03-19 10:44:29 +01:00
|
|
|
/*
|
2025-04-01 16:15:20 +02:00
|
|
|
* Sample pattern for doll & giant
|
2020-03-19 10:44:29 +01:00
|
|
|
*/
|
2025-04-01 16:15:20 +02:00
|
|
|
for (const family of ['doll', 'giant']) {
|
|
|
|
describe(`Sample ${family} measurements:`, () => {
|
|
|
|
for (const type of ['cisFemale', 'cisMale']) {
|
|
|
|
it(`Sample pattern for ${family} ${type} size range:`, () => {
|
2022-10-06 21:01:58 +02:00
|
|
|
expect(
|
|
|
|
doesItSample(
|
|
|
|
new Pattern({
|
|
|
|
sample: {
|
2025-04-01 16:15:20 +02:00
|
|
|
type: 'models',
|
|
|
|
models: family === 'doll' ? doll[type] : giant[type],
|
2022-10-06 21:01:58 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
2022-08-31 17:54:37 +02:00
|
|
|
}
|
2025-04-01 16:15:20 +02:00
|
|
|
})
|
2021-09-11 15:50:32 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|