2022-08-27 09:27:35 +02:00
|
|
|
import designs from "../../config/software/designs.json" assert { type: 'json' }
|
2022-09-06 16:52:28 +02:00
|
|
|
import { adult, doll, giant } from '@freesewing/models'
|
2022-09-07 10:11:19 +02:00
|
|
|
import { getFamily, getShortName } from './config.mjs'
|
2022-08-25 11:52:34 +02:00
|
|
|
import chai from 'chai'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
2021-09-12 13:13:57 +02:00
|
|
|
|
2022-09-07 10:11:19 +02:00
|
|
|
const noSizes = [
|
|
|
|
'examples',
|
|
|
|
'rendertest',
|
|
|
|
'plugintest',
|
|
|
|
'legend',
|
|
|
|
'tutorial',
|
|
|
|
]
|
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
/*
|
|
|
|
* 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
|
2020-03-15 16:34:56 +01:00
|
|
|
*/
|
2022-08-27 09:27:35 +02:00
|
|
|
export const testPatternDrafting = (Pattern, log=false) => {
|
|
|
|
|
|
|
|
const pattern = new Pattern()
|
|
|
|
const config = pattern.getConfig()
|
2022-09-07 10:11:19 +02:00
|
|
|
const design = getShortName(config.data.name)
|
2022-08-27 09:27:35 +02:00
|
|
|
const family = getFamily(design)
|
|
|
|
const parts = pattern.getPartList()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Draft pattern for different models
|
|
|
|
*/
|
2022-08-27 09:27:35 +02:00
|
|
|
if (family !== 'utilities') {
|
2022-09-07 11:22:26 +02:00
|
|
|
describe('Draft for humans:', function() {
|
|
|
|
this.timeout(5000);
|
2022-09-06 16:52:28 +02:00
|
|
|
for (const type of ['cisFemale', 'cisMale']) {
|
2022-08-31 17:54:37 +02:00
|
|
|
describe(type, () => {
|
2022-09-06 16:52:28 +02:00
|
|
|
for (const size in adult[type]) {
|
2022-08-31 17:54:37 +02:00
|
|
|
it(` - Drafting for size ${size}`, () => {
|
|
|
|
expect(
|
|
|
|
doesItDraftAndRender(
|
|
|
|
new Pattern({
|
2022-09-06 16:52:28 +02:00
|
|
|
measurements: adult[type][size]
|
2022-08-31 17:54:37 +02:00
|
|
|
}), log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2021-09-12 14:03:25 +02:00
|
|
|
})
|
|
|
|
}
|
2022-08-31 17:54:37 +02:00
|
|
|
})
|
2021-09-12 13:13:57 +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-07 11:22:26 +02:00
|
|
|
describe(`Draft for ${family}:`, function() {
|
|
|
|
this.timeout(5000);
|
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({
|
|
|
|
measurements: fams[family][type][size]
|
|
|
|
}), log
|
|
|
|
)
|
|
|
|
).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2021-09-11 15:50:32 +02:00
|
|
|
}
|
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()
|
|
|
|
//})
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
2022-08-31 17:54:37 +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
|
|
|
|
*/
|
2022-08-31 17:54:37 +02:00
|
|
|
/*
|
2020-05-31 17:58:36 +02:00
|
|
|
it('Draft parts individually:', () => true)
|
2022-08-25 11:52:34 +02:00
|
|
|
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
|
|
|
})
|
|
|
|
}
|
2022-08-31 17:54:37 +02:00
|
|
|
*/
|
2021-09-04 17:46:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Draft a paperless non-detailed pattern
|
|
|
|
*/
|
2022-08-31 17:54:37 +02:00
|
|
|
/*
|
2021-09-04 17:46:44 +02:00
|
|
|
it('Draft paperless non-detailed pattern:', () => true)
|
2022-08-27 09:27:35 +02:00
|
|
|
if (family !== 'utilities') {
|
2021-09-04 17:46:44 +02:00
|
|
|
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
|
|
|
}
|
2022-08-31 17:54:37 +02:00
|
|
|
*/
|
2020-03-15 16:34:56 +01:00
|
|
|
|