Skip to content

Commit 2890609

Browse files
committed
Add unit test for audio effect adjustedTrim times
1 parent 6100e0f commit 2890609

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/unit/util/audio-effects.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ describe('Audio Effects manager', () => {
2828
expect(audioEffects.audioContext._.length).toBeGreaterThan(400);
2929
});
3030

31+
test('updates the trim positions after an effect has changed the length of selection', () => {
32+
const slowerEffect = new AudioEffects(audioBuffer, 'slower', 0.25, 0.75);
33+
expect(slowerEffect.adjustedTrimStartSeconds).toEqual(slowerEffect.trimStartSeconds);
34+
expect(slowerEffect.adjustedTrimEndSeconds).toBeGreaterThan(slowerEffect.trimEndSeconds);
35+
36+
const fasterEffect = new AudioEffects(audioBuffer, 'faster', 0.25, 0.75);
37+
expect(fasterEffect.adjustedTrimStartSeconds).toEqual(fasterEffect.trimStartSeconds);
38+
expect(fasterEffect.adjustedTrimEndSeconds).toBeLessThan(fasterEffect.trimEndSeconds);
39+
40+
// Some effects do not change the length of the selection
41+
const fadeEffect = new AudioEffects(audioBuffer, 'fade in', 0.25, 0.75);
42+
expect(fadeEffect.adjustedTrimStartSeconds).toEqual(fadeEffect.trimStartSeconds);
43+
// Should be within one millisecond (flooring can change the duration by one sample)
44+
expect(fadeEffect.adjustedTrimEndSeconds).toBeCloseTo(fadeEffect.trimEndSeconds, 3);
45+
});
46+
3147
test.skip('process starts the offline rendering context and returns a promise', () => {
3248
// @todo haven't been able to get web audio test api to actually run render
3349
});

0 commit comments

Comments
 (0)