Start to add test coverage to AppState
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-02-04 08:10:33 +01:00
parent 9f76d2764f
commit b64f0b4daa
2 changed files with 60 additions and 5 deletions

View File

@ -0,0 +1,50 @@
import { MediaSet } from './generated/media_set';
import { stateReducer, State } from './AppState';
import { from } from 'rxjs';
import { PlayState } from './Player';
import { CanvasLogicalWidth } from './HudCanvasState';
const initialState: State = {
selection: { start: 0, end: 0 },
viewport: { start: 0, end: 441000 },
overviewPeaks: from([]),
waveformPeaks: from([]),
selectionCanvas: { start: 0, end: 0 },
viewportCanvas: { start: 0, end: CanvasLogicalWidth },
position: { currentTime: 0, frame: 0, percent: 0 },
audioSrc: '',
videoSrc: '',
currentTime: 0,
playState: PlayState.Paused,
};
describe('stateReducer', () => {
describe('mediasetloaded', () => {
describe.each([
{
name: 'with a normal length media set',
audioFrames: 4410000,
wantViewportFrames: 220500,
},
{
name: 'with a very short media set',
audioFrames: 44100,
wantViewportFrames: 2200,
},
])('mousedown', ({ name, audioFrames, wantViewportFrames }) => {
test(name, () => {
const mediaSet = MediaSet.fromPartial({
id: '123',
audioFrames: audioFrames,
});
const state = stateReducer(
{ ...initialState },
{ type: 'mediasetloaded', mediaSet: mediaSet }
);
expect(state.mediaSet).toBe(mediaSet);
expect(state.viewport.start).toEqual(0);
expect(state.viewport.end).toEqual(wantViewportFrames);
});
});
});
});

View File

@ -379,7 +379,6 @@ function handlePositionChanged(
) { ) {
playState = PlayState.Paused; playState = PlayState.Paused;
forceCurrentTime = selection.start / mediaSet.audioSampleRate; forceCurrentTime = selection.start / mediaSet.audioSampleRate;
console.log('forceCurrentTime', forceCurrentTime);
} }
return { return {
@ -422,10 +421,16 @@ function selectionToWaveformCanvasRange(
selection: FrameRange, selection: FrameRange,
viewport: FrameRange viewport: FrameRange
): CanvasRange { ): CanvasRange {
const x1 = const x1 = frameToWaveformCanvasX(
frameToWaveformCanvasX(selection.start, viewport, CanvasLogicalWidth) || 0; selection.start,
const x2 = viewport,
frameToWaveformCanvasX(selection.end, viewport, CanvasLogicalWidth) || 0; CanvasLogicalWidth
);
const x2 = frameToWaveformCanvasX(
selection.end,
viewport,
CanvasLogicalWidth
);
if (x1 == x2) { if (x1 == x2) {
return { start: 0, end: 0 }; return { start: 0, end: 0 };