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: { x1: 0, x2: 0 }, viewportCanvas: { x1: 0, x2: 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); }); }); }); });