Add test coverage for waveformselectionchanged event
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-02-07 07:55:47 +01:00
parent a0bb48fb69
commit 29129afe90
1 changed files with 122 additions and 1 deletions

View File

@ -14,7 +14,7 @@ const initialState: State = {
position: { currentTime: 0, frame: 0, percent: 0 },
audioSrc: '',
videoSrc: '',
currentTime: 0,
currentTime: undefined,
playState: PlayState.Paused,
};
@ -191,4 +191,125 @@ describe('stateReducer', () => {
}
);
});
describe('waveformselectionchanged', () => {
describe.each([
{
name: 'paused',
audioSampleRate: 44100,
event: {
mode: SelectionMode.Selecting,
prevMode: SelectionMode.Selecting,
selection: { x1: 100, x2: 200 },
},
playState: PlayState.Paused,
position: { frame: 0, currentTime: 0, percent: 0 },
viewport: { start: 0, end: 88200 },
wantSelection: { start: 4410, end: 8820 },
wantCurrentTime: undefined,
},
{
name: 'playing, viewport 100%, selection is in progress',
audioSampleRate: 44100,
event: {
mode: SelectionMode.Selecting,
prevMode: SelectionMode.Selecting,
selection: { x1: 200, x2: 220 },
},
playState: PlayState.Playing,
position: { frame: 22000, currentTime: 0.4988, percent: 4.98 },
viewport: { start: 0, end: 441000 },
wantSelection: { start: 44100, end: 48510 },
wantCurrentTime: undefined,
},
{
name: 'playing, viewport partial, selection is in progress',
audioSampleRate: 44100,
event: {
mode: SelectionMode.Selecting,
prevMode: SelectionMode.Selecting,
selection: { x1: 0, x2: 100 },
},
playState: PlayState.Playing,
position: { frame: 22000, currentTime: 0.4988, percent: 4.98 },
viewport: { start: 88200, end: 176400 },
wantSelection: { start: 88200, end: 92610 },
wantCurrentTime: undefined,
},
{
name: 'playing, selection is ending, currFrame is before selection start',
audioSampleRate: 44100,
event: {
mode: SelectionMode.Normal,
prevMode: SelectionMode.Selecting,
selection: { x1: 1001, x2: 1200 },
},
playState: PlayState.Playing,
position: { frame: 22000, currentTime: 0.4988, percent: 4.98 },
viewport: { start: 0, end: 88200 },
wantSelection: { start: 44144, end: 52920 },
wantCurrentTime: 1.000997732426304,
},
{
name: 'playing, selection is ending, currFrame is within selection',
audioSampleRate: 44100,
event: {
mode: SelectionMode.Normal,
prevMode: SelectionMode.Selecting,
selection: { x1: 1001, x2: 1200 },
},
playState: PlayState.Playing,
position: { frame: 50000, currentTime: 1.133, percent: 11.33 },
viewport: { start: 0, end: 88200 },
wantSelection: { start: 44144, end: 52920 },
wantCurrentTime: undefined,
},
{
name: 'playing, selection is ending, currFrame is after selection end',
audioSampleRate: 44100,
event: {
mode: SelectionMode.Normal,
prevMode: SelectionMode.Selecting,
selection: { x1: 1001, x2: 1200 },
},
playState: PlayState.Playing,
position: { frame: 88200, currentTime: 2.0, percent: 20.0 },
viewport: { start: 0, end: 88200 },
wantSelection: { start: 44144, end: 52920 },
wantCurrentTime: 1.000997732426304,
},
])(
'$name',
({
audioSampleRate,
event,
playState,
position,
viewport,
wantSelection,
wantCurrentTime,
}) => {
it('generates the expected state', () => {
const mediaSet = MediaSet.fromPartial({
id: '123',
audioFrames: 441000,
audioSampleRate: audioSampleRate,
});
const state = stateReducer(
{
...initialState,
position,
mediaSet,
playState,
viewport,
},
{ type: 'waveformselectionchanged', event }
);
expect(state.selection).toEqual(wantSelection);
expect(state.currentTime).toEqual(wantCurrentTime);
});
}
);
});
});