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

138 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-08-27 09:27:35 +02:00
import designs from "../../config/software/designs.json" assert { type: 'json' }
import { nonHumanMeasurements } from './non-human-measurements.mjs'
2022-08-25 12:53:07 +02:00
import { withBreasts, withoutBreasts } from '@freesewing/models'
2022-08-27 09:27:35 +02:00
import { getShortName, getFamily } from './config.mjs'
2022-08-25 11:52:34 +02:00
import chai from 'chai'
const expect = chai.expect
const models = { withBreasts, withoutBreasts }
2021-09-12 14:03:25 +02:00
// Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo']
/*
* This runs unit tests for pattern drafting
* It expects the following:
*
* @param object Pattern: pattern constructor
2022-08-25 11:52:34 +02:00
* @param boolean log: Set to true to log errors
*/
2022-08-27 09:27:35 +02:00
export const testPatternDrafting = (Pattern, log=false) => {
const pattern = new Pattern()
const config = pattern.getConfig()
const design = getShortName(config.name)
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 {
pattern.draft().render()
if (pattern.events.error.length < 1) return true
if (log) console.log(pattern.events.error)
return false
} catch (err) {
if (log) console.log(err)
return false
}
}
2022-08-25 11:52:34 +02:00
// FIXME: Just use womenswear measurements, as they should always work
const breasts = true
const ourModels = withBreasts
/*
* Draft pattern for different models
*/
2022-08-27 09:27:35 +02:00
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]
2021-09-11 16:44:51 +02:00
}), log
)
).to.equal(true)
})
}
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-12 14:03:25 +02:00
for (let size in nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].dolls) {
it(` - Drafting for ${size} (${breasts ? 'with' : 'no'} breasts)`, () => {
expect(
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 14:03:25 +02:00
it('Draft for giants:', () => true)
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(
doesItDraftAndRender(
2021-09-12 14:03:25 +02:00
new Pattern({
measurements: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'].giants[size]
}), log
)
).to.equal(true)
})
}
}
}
/*
* Draft parts individually
*/
it('Draft parts individually:', () => true)
2022-08-25 11:52:34 +02:00
for (const name of parts) {
it(` - ${name} should draft and render on its own`, () => {
expect(
doesItDraftAndRender(
new Pattern({
2022-08-25 11:52:34 +02:00
measurements: ourModels.size34,
only: [name]
2021-09-11 16:44:51 +02:00
}), log
)
).to.equal(true)
})
}
/*
* Draft a paperless non-detailed pattern
*/
it('Draft paperless non-detailed pattern:', () => true)
2022-08-27 09:27:35 +02:00
if (family !== 'utilities') {
for (const sa of [0,10]) {
it(` - Drafting paperless non-detailed pattern for size-40 (${breasts ? 'with' : 'no'} breasts) sa: ${sa}`, () => {
expect(
doesItDraftAndRender(
new Pattern({
measurements: ourModels.size40,
complete: false,
paperless: true,
sa
2021-09-11 16:44:51 +02:00
}), log
)
).to.equal(true)
})
}
}
}