2022-09-09 20:20:38 +02:00
|
|
|
import chai from 'chai'
|
2022-09-10 18:45:57 +02:00
|
|
|
import { Design } from '../src/index.mjs'
|
2022-08-27 09:27:07 +02:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
const measurements = { head: 400 }
|
|
|
|
const toAbs = (val, { measurements }) => measurements.head * val
|
|
|
|
|
|
|
|
describe('Snapped options', () => {
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should snap a percentage options to equal steps', () => {
|
2022-09-10 18:45:57 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-08-27 09:27:07 +02:00
|
|
|
options: {
|
2022-09-09 20:20:38 +02:00
|
|
|
test: { pct: 30, min: 0, max: 100, snap: 12, toAbs },
|
2022-09-10 18:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const design = new Design({ parts: [ part ] })
|
|
|
|
const patternA = new design({ options: { test: 0.13 }, measurements }).draft()
|
|
|
|
const patternB = new design({ options: { test: 0.27 }, measurements }).draft()
|
2022-08-27 09:27:07 +02:00
|
|
|
expect(patternA.settings.absoluteOptions.test).to.equal(60)
|
|
|
|
expect(patternB.settings.absoluteOptions.test).to.equal(108)
|
2022-09-09 20:20:38 +02:00
|
|
|
})
|
2022-08-27 09:27:07 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should snap a percentage options to the Fibonacci sequence', () => {
|
2022-09-10 18:45:57 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-08-27 09:27:07 +02:00
|
|
|
options: {
|
|
|
|
test: {
|
2022-09-09 20:20:38 +02:00
|
|
|
pct: 30,
|
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
toAbs,
|
|
|
|
snap: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144],
|
|
|
|
},
|
2022-09-10 18:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const design = new Design({ parts: [ part ] })
|
|
|
|
const patternA = new design({ options: { test: 0.13 }, measurements }).draft()
|
|
|
|
const patternB = new design({ options: { test: 0.27 }, measurements }).draft()
|
|
|
|
const patternC = new design({ options: { test: 0.97 }, measurements }).draft()
|
2022-08-27 09:27:07 +02:00
|
|
|
expect(patternA.settings.absoluteOptions.test).to.equal(55)
|
|
|
|
expect(patternB.settings.absoluteOptions.test).to.equal(89)
|
|
|
|
expect(patternC.settings.absoluteOptions.test).to.equal(388)
|
2022-09-09 20:20:38 +02:00
|
|
|
})
|
2022-08-27 09:27:07 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should snap a percentage options to imperial snaps', () => {
|
2022-09-10 18:45:57 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-08-27 09:27:07 +02:00
|
|
|
options: {
|
|
|
|
test: {
|
2022-09-09 20:20:38 +02:00
|
|
|
pct: 30,
|
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
toAbs,
|
2022-08-27 09:27:07 +02:00
|
|
|
snap: {
|
2022-09-09 20:20:38 +02:00
|
|
|
metric: [25, 50, 75, 100],
|
|
|
|
imperial: [25.4, 50.8, 76.2, 101.6],
|
|
|
|
},
|
|
|
|
},
|
2022-09-10 18:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const design = new Design({ parts: [ part ] })
|
|
|
|
const patternA = new design({ options: { test: 0.13 }, measurements, units: 'metric' }).draft()
|
|
|
|
const patternB = new design({ options: { test: 0.27 }, measurements, units: 'metric' }).draft()
|
|
|
|
const patternC = new design({ options: { test: 0.97 }, measurements, units: 'metric' }).draft()
|
|
|
|
const patternD = new design({ options: { test: 0.01 }, measurements, units: 'metric' }).draft()
|
2022-08-27 09:27:07 +02:00
|
|
|
expect(patternA.settings.absoluteOptions.test).to.equal(50)
|
|
|
|
expect(patternB.settings.absoluteOptions.test).to.equal(100)
|
|
|
|
expect(patternC.settings.absoluteOptions.test).to.equal(388)
|
|
|
|
expect(patternD.settings.absoluteOptions.test).to.equal(4)
|
2022-09-09 20:20:38 +02:00
|
|
|
})
|
2022-08-27 09:27:07 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should snap a percentage options to metrics snaps', () => {
|
2022-09-10 18:45:57 +02:00
|
|
|
const part = {
|
|
|
|
name: 'test',
|
2022-08-27 09:27:07 +02:00
|
|
|
options: {
|
|
|
|
test: {
|
2022-09-09 20:20:38 +02:00
|
|
|
pct: 30,
|
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
toAbs,
|
2022-08-27 09:27:07 +02:00
|
|
|
snap: {
|
2022-09-09 20:20:38 +02:00
|
|
|
metric: [25, 50, 75, 100],
|
|
|
|
imperial: [25.4, 50.8, 76.2, 101.6],
|
|
|
|
},
|
|
|
|
},
|
2022-09-10 18:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const design = new Design({ parts: [ part ] })
|
|
|
|
const patternA = new design({ options: { test: 0.13 }, measurements, units: 'imperial' }).draft()
|
|
|
|
const patternB = new design({ options: { test: 0.27 }, measurements, units: 'imperial' }).draft()
|
|
|
|
const patternC = new design({ options: { test: 0.97 }, measurements, units: 'imperial' }).draft()
|
|
|
|
const patternD = new design({ options: { test: 0.01 }, measurements, units: 'imperial' }).draft()
|
2022-08-27 09:27:07 +02:00
|
|
|
expect(patternA.settings.absoluteOptions.test).to.equal(50.8)
|
|
|
|
expect(patternB.settings.absoluteOptions.test).to.equal(101.6)
|
|
|
|
expect(patternC.settings.absoluteOptions.test).to.equal(388)
|
|
|
|
expect(patternD.settings.absoluteOptions.test).to.equal(4)
|
2022-09-09 20:20:38 +02:00
|
|
|
})
|
|
|
|
})
|