Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions apps/web/__tests__/unit/playback-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,40 @@ describe("playback store", () => {
video.dispatchEvent(new Event("timeupdate"));
expect(subscriber).toHaveBeenCalledTimes(1);
});

it("notifies subscribers when late fallbackDuration changes the store duration", () => {
const store = createPlaybackStore(0);
let observedDuration = store.getDuration();
store.subscribe(() => {
observedDuration = store.getDuration();
});

expect(observedDuration).toBe(0);

store.setFallbackDuration(60);

expect(observedDuration).toBe(60);
expect(store.getDuration()).toBe(60);
});

it("does not notify subscribers when fallbackDuration does not change total duration", () => {
const video = Object.assign(new EventTarget(), {
currentTime: 0,
duration: 120,
paused: true,
ended: false,
});
const store = createPlaybackStore(60);
store.attach(video as unknown as HTMLVideoElement);

const subscriber = vi.fn(() => store.getDuration());
store.subscribe(subscriber);
subscriber.mockClear();

store.setFallbackDuration(90);

expect(subscriber).not.toHaveBeenCalled();
expect(store.getDuration()).toBe(120);
store.detach();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ export function createPlaybackStore(fallbackDuration: number | null = 0) {
const getPlaying = () => playing;

const setFallbackDuration = (next: number | null) => {
const previousDuration = getDuration();
fallback = normalizeDuration(next);
if (!isFiniteDuration(duration)) duration = fallback;
if (getDuration() !== previousDuration) {
emitTime();
}
};

const seek = (target: number) => {
Expand Down
Loading