diff options
Diffstat (limited to 'lib/project/tests/gui_state.test.mjs')
| -rw-r--r-- | lib/project/tests/gui_state.test.mjs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/project/tests/gui_state.test.mjs b/lib/project/tests/gui_state.test.mjs new file mode 100644 index 0000000..10775eb --- /dev/null +++ b/lib/project/tests/gui_state.test.mjs @@ -0,0 +1,31 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {parseTime, formatTime, selection, stable, matches, monitoringGain, absolutePath} from '../src/producer/web/state.js'; + +test('exact excerpt times work beyond four hours without wrapping', () => { + assert.equal(parseTime('05:12:03.125'), 18723.125); + assert.equal(formatTime(18723.125), '05:12:03.125'); + assert.equal(parseTime('14400'), 14400); + assert.equal(formatTime(59.9999), '00:01:00'); + for (const value of ['1:60:00', '-1', 'Infinity', '1e3', '', '00:00:60']) assert.throws(() => parseTime(value)); + assert.deepEqual(selection('03:59:30', '04:00:00', 14400), {start: 14370, duration: 30}); + for (const [start, end] of [['0', '121'], ['2', '1'], ['0', '0'], ['14399', '14401']]) assert.throws(() => selection(start, end, 14400)); +}); + +test('preview identity includes source, exact selection and every requested setting', () => { + const snapshot = {path: 'take.wav', input_id: 'identity', start: 10, duration: 30, settings: {mp3: true, trim_silence: true, denoiser: 'none'}}; + assert.ok(matches(snapshot, structuredClone(snapshot))); + assert.ok(matches(snapshot, {...snapshot, settings: {denoiser: 'none', trim_silence: true, mp3: true}})); + for (const change of [{path: 'other.wav'}, {input_id: 'changed'}, {start: 11}, {duration: 29}, {settings: {...snapshot.settings, trim_silence: false}}]) assert.equal(matches(snapshot, {...snapshot, ...change}), false); + assert.equal(matches(snapshot, null), false); + assert.equal(stable({b: 2, a: 1}), stable({a: 1, b: 2})); +}); + +test('monitoring is attenuation only and independent of export settings', () => { + assert.equal(monitoringGain(-6, false), 1); + assert.equal(monitoringGain(6, true), 1); + assert.equal(monitoringGain(NaN, true), 1); + assert.ok(Math.abs(monitoringGain(-6, true) - 0.501187) < 0.000001); + assert.equal(absolutePath('/recordings', 'delivery/master.wav'), '/recordings/delivery/master.wav'); + assert.equal(absolutePath('/', './master.wav'), '/master.wav'); +}); |
