[tests] feat: when sampling options, also test different settings for sa, paperless and complete (#225)
This ensures that we catch crashes that only occur with certain options set and/or only with sa and/or complete enabled. Closes #189 Closes #85 Reviewed-on: https://codeberg.org/freesewing/freesewing/pulls/225 Reviewed-by: Joost De Cock <joostdecock@noreply.codeberg.org> Co-authored-by: Jonathan Haas <haasjona@gmail.com> Co-committed-by: Jonathan Haas <haasjona@gmail.com>
This commit is contained in:
parent
5672638bf9
commit
aa9267b3c9
1 changed files with 86 additions and 18 deletions
|
@ -50,6 +50,23 @@ export const testPatternSampling = (Pattern, log = false) => {
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sample different measurements
|
||||
*/
|
||||
|
@ -76,9 +93,29 @@ export const testPatternSampling = (Pattern, log = false) => {
|
|||
* Sample different options
|
||||
*/
|
||||
describe('Sample options:', () => {
|
||||
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}:`, () => {
|
||||
it(` Sample ${option} with sa:${sa} complete:${complete} paperless:${paperless}`, () => {
|
||||
expect(
|
||||
doesItSample(
|
||||
new Pattern({
|
||||
|
@ -87,6 +124,9 @@ export const testPatternSampling = (Pattern, log = false) => {
|
|||
option,
|
||||
},
|
||||
measurements: adult.cisFemale['36'],
|
||||
sa: sa,
|
||||
complete: complete,
|
||||
paperless: paperless,
|
||||
}),
|
||||
log
|
||||
)
|
||||
|
@ -94,6 +134,34 @@ export const testPatternSampling = (Pattern, log = false) => {
|
|||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue