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

142 lines
3.7 KiB
JavaScript
Raw Normal View History

2022-09-06 16:52:28 +02:00
import { adult, doll, giant } from '@freesewing/models'
import { getShortName, isUtilityDesign } from './config.mjs'
import { expect } from 'chai'
import { timingPlugin } from '@freesewing/plugin-timing'
2022-08-25 11:52:34 +02:00
2022-11-15 16:50:28 -06:00
const ciTimeout = 10000
/*
* 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-09-15 13:49:55 +02:00
export const testPatternDrafting = (Pattern, log = false) => {
2022-09-25 10:46:50 +02:00
const design = getShortName(Pattern.designConfig.data.name)
2022-09-15 13:49:55 +02:00
// Helper method to try/catch pattern drafting
2022-09-15 13:49:55 +02:00
const doesItDraftAndRender = (pattern, log = false) => {
try {
2022-11-15 16:33:56 -06:00
pattern.draft().render()
if (log) {
2022-09-25 10:46:50 +02:00
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
}
}
/*
* Draft pattern for different models
*/
if (!isUtilityDesign(design)) {
2022-09-15 13:49:55 +02:00
describe('Draft for humans:', function () {
2022-11-15 15:32:55 -06:00
this.timeout(ciTimeout)
2022-09-06 16:52:28 +02:00
for (const type of ['cisFemale', 'cisMale']) {
describe(type, () => {
2022-09-06 16:52:28 +02:00
for (const size in adult[type]) {
it(` - Drafting for size ${size}`, () => {
expect(
doesItDraftAndRender(
new Pattern({
2022-09-15 13:49:55 +02:00
measurements: adult[type][size],
}).use(timingPlugin),
2022-09-15 13:49:55 +02:00
log
)
).to.equal(true)
})
}
2021-09-12 14:03:25 +02:00
})
}
})
2022-09-06 16:52:28 +02:00
// Do the same for fantastical models (doll, giant)
const fams = { doll, giant }
for (const family of ['doll', 'giant']) {
2022-09-15 13:49:55 +02:00
describe(`Draft for ${family}:`, function () {
2022-11-15 15:32:55 -06:00
this.timeout(ciTimeout)
2022-09-06 16:52:28 +02:00
for (const type of ['cisFemale', 'cisMale']) {
2022-09-04 11:31:53 +02:00
describe(type, () => {
for (const size in fams[family][type]) {
it(` - Drafting at ${size}%`, () => {
expect(
doesItDraftAndRender(
new Pattern({
2022-09-15 13:49:55 +02:00
measurements: fams[family][type][size],
}),
log
2022-09-04 11:31:53 +02:00
)
).to.equal(true)
})
}
})
}
})
}
2022-09-07 10:11:19 +02:00
} else {
// Utility pattern - Just draft them once
2022-09-07 11:22:26 +02:00
// FIXME: This hangs when running all tests, not sure why
//it(` - Draft utility pattern`, function() {
// this.timeout(5000);
// expect(
// doesItDraftAndRender(
// new Pattern({
// measurements: adult.cisFemale[34]
// }), log
// )
// ).to.equal(true)
// done()
//})
}
}
2022-09-15 13:49:55 +02:00
/*
* 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)
})
}
*/
2022-09-15 13:49:55 +02:00
/*
* 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)
})
}
}
}
*/