2021-11-27 16:54:50 +01:00
|
|
|
import { nonHumanMeasurements } from './non-human-measurements.mjs'
|
2022-08-25 11:52:34 +02:00
|
|
|
import { measurements, withBreasts, withoutBreasts } from '@freesewing/models'
|
|
|
|
import chai from 'chai'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
const models = { withBreasts, withoutBreasts }
|
2021-09-12 13:13:57 +02:00
|
|
|
|
2021-09-04 17:46:44 +02:00
|
|
|
// Some patterns are different
|
|
|
|
const isGarment = design => ([
|
|
|
|
'rendertest',
|
|
|
|
'tutorial',
|
|
|
|
'examples',
|
|
|
|
'legend',
|
2022-01-19 11:32:03 +01:00
|
|
|
'plugintest',
|
2021-09-04 17:46:44 +02:00
|
|
|
].indexOf(design) === -1)
|
|
|
|
|
2021-09-12 14:03:25 +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 drafting
|
|
|
|
* It expects the following:
|
|
|
|
*
|
|
|
|
* @param string me: Name of the pattern (eg 'aaron')
|
|
|
|
* @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-08-25 11:52:34 +02:00
|
|
|
export const testPatternDrafting = (design, Pattern, log=false) => {
|
2021-09-12 13:28:44 +02:00
|
|
|
// Load non-human measurements
|
|
|
|
const nonHuman = nonHumanMeasurements(models)
|
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
// Helper method to try/catch pattern drafting
|
2022-01-29 08:03:55 +01:00
|
|
|
const doesItDraftAndRender = (pattern, log=false) => {
|
2020-05-31 17:58:36 +02:00
|
|
|
try {
|
2022-01-29 08:03:55 +01:00
|
|
|
pattern.draft().render()
|
2021-09-04 17:46:44 +02:00
|
|
|
if (pattern.events.error.length < 1) return true
|
|
|
|
if (log) console.log(pattern.events.error)
|
|
|
|
return false
|
2020-05-31 17:58:36 +02:00
|
|
|
} catch (err) {
|
2021-09-04 17:46:44 +02:00
|
|
|
if (log) console.log(err)
|
2020-05-31 17:58:36 +02:00
|
|
|
return false
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|
2022-08-25 11:52:34 +02:00
|
|
|
// FIXME: Just use womenswear measurements, as they should always work
|
|
|
|
const breasts = true
|
|
|
|
const ourModels = withBreasts
|
|
|
|
//const measies = measurements.womenswear.size34
|
2020-03-15 16:34:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Draft pattern for different models
|
|
|
|
*/
|
2021-09-04 17:46:44 +02:00
|
|
|
if (isGarment(design)) {
|
2021-09-12 13:13:57 +02:00
|
|
|
it('Draft for humans:', () => true)
|
2020-03-15 16:34:56 +01:00
|
|
|
|
2020-03-19 10:44:29 +01:00
|
|
|
for (let size in ourModels) {
|
2020-05-31 17:58:36 +02:00
|
|
|
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
|
|
|
|
expect(
|
2022-01-29 08:03:55 +01:00
|
|
|
doesItDraftAndRender(
|
2020-05-31 17:58:36 +02:00
|
|
|
new Pattern({
|
|
|
|
measurements: ourModels[size]
|
2021-09-11 16:44:51 +02:00
|
|
|
}), log
|
2020-05-31 17:58:36 +02:00
|
|
|
)
|
|
|
|
).to.equal(true)
|
2020-03-19 10:44:29 +01:00
|
|
|
})
|
|
|
|
}
|
2021-09-11 15:50:32 +02:00
|
|
|
|
2021-09-12 14:03:25 +02:00
|
|
|
if (deprecated.indexOf(design) === -1) {
|
2021-11-27 13:02:58 +01:00
|
|
|
// Do the same for fantastical models (dolls, giants)
|
2021-09-12 14:03:25 +02:00
|
|
|
it('Draft for dolls:', () => true)
|
2021-09-11 15:50:32 +02:00
|
|
|
|
2021-09-12 14:03:25 +02:00
|
|
|
for (let size in nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls) {
|
|
|
|
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
|
|
|
|
expect(
|
2022-01-29 08:03:55 +01:00
|
|
|
doesItDraftAndRender(
|
2021-09-12 14:03:25 +02:00
|
|
|
new Pattern({
|
|
|
|
measurements: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls[size]
|
|
|
|
}), log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2021-09-12 13:13:57 +02:00
|
|
|
|
2021-09-12 14:03:25 +02:00
|
|
|
it('Draft for giants:', () => true)
|
2021-09-12 13:13:57 +02:00
|
|
|
|
2021-09-12 14:03:25 +02:00
|
|
|
for (let size in nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].giants) {
|
|
|
|
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
|
|
|
|
expect(
|
2022-01-29 08:03:55 +01:00
|
|
|
doesItDraftAndRender(
|
2021-09-12 14:03:25 +02:00
|
|
|
new Pattern({
|
|
|
|
measurements: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].giants[size]
|
|
|
|
}), log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2021-09-11 15:50:32 +02:00
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|
2021-09-04 17:46:44 +02:00
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
/*
|
|
|
|
* Draft parts individually
|
|
|
|
*/
|
2020-05-31 17:58:36 +02:00
|
|
|
it('Draft parts individually:', () => true)
|
2022-08-25 11:52:34 +02:00
|
|
|
const parts = Pattern.config.parts || []
|
|
|
|
for (const name of parts) {
|
2022-01-29 08:03:55 +01:00
|
|
|
it(` - ${name} should draft and render on its own`, () => {
|
2020-05-31 17:58:36 +02:00
|
|
|
expect(
|
2022-01-29 08:03:55 +01:00
|
|
|
doesItDraftAndRender(
|
2020-05-31 17:58:36 +02:00
|
|
|
new Pattern({
|
2022-08-25 11:52:34 +02:00
|
|
|
measurements: ourModels.size34,
|
2022-01-29 08:03:55 +01:00
|
|
|
only: [name]
|
2021-09-11 16:44:51 +02:00
|
|
|
}), log
|
2020-05-31 17:58:36 +02:00
|
|
|
)
|
|
|
|
).to.equal(true)
|
2020-03-15 16:34:56 +01:00
|
|
|
})
|
|
|
|
}
|
2021-09-04 17:46:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Draft a paperless non-detailed pattern
|
|
|
|
*/
|
|
|
|
it('Draft paperless non-detailed pattern:', () => true)
|
|
|
|
if (isGarment(design)) {
|
|
|
|
for (const sa of [0,10]) {
|
|
|
|
it(` - Drafting paperless non-detailed pattern for size-40 (${breasts ? 'with' : 'no'} breasts) sa: ${sa}`, () => {
|
|
|
|
expect(
|
2022-01-29 08:03:55 +01:00
|
|
|
doesItDraftAndRender(
|
2021-09-04 17:46:44 +02:00
|
|
|
new Pattern({
|
|
|
|
measurements: ourModels.size40,
|
|
|
|
complete: false,
|
|
|
|
paperless: true,
|
2022-01-29 08:03:55 +01:00
|
|
|
sa
|
2021-09-11 16:44:51 +02:00
|
|
|
}), log
|
2021-09-04 17:46:44 +02:00
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|