Fix voice notes rendering at 00:00 when playback had not begun. (#30961)

* Fix clocks rendering at 00:00 when playback had not begun.

* Add a rendering test

* Add a test

* remove only

* add another test
This commit is contained in:
Will Hunt
2025-10-07 23:03:25 +01:00
committed by GitHub
parent 25f4853d97
commit 0f530f636b
4 changed files with 102 additions and 4 deletions

View File

@@ -0,0 +1,74 @@
/*
Copyright 2025 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { type Mocked } from "jest-mock";
import { type MatrixEvent, type Room } from "matrix-js-sdk/src/matrix";
import { SimpleObservable } from "matrix-widget-api";
import { PlaybackQueue } from "../../../src/audio/PlaybackQueue";
import { PlaybackState, type Playback } from "../../../src/audio/Playback";
import { MockEventEmitter } from "../../test-utils";
import { UPDATE_EVENT } from "../../../src/stores/AsyncStore";
describe("PlaybackQueue", () => {
let playbackQueue: PlaybackQueue;
beforeEach(() => {
const mockRoom = {
getMember: jest.fn(),
} as unknown as Mocked<Room>;
playbackQueue = new PlaybackQueue(mockRoom);
});
it("does not call skipTo on playback if clock advances to 0s", () => {
const mockEvent = {
getId: jest.fn().mockReturnValue("$foo:bar"),
} as unknown as Mocked<MatrixEvent>;
const mockPlayback = new MockEventEmitter({
clockInfo: {
liveData: new SimpleObservable<number[]>(),
},
skipTo: jest.fn(),
}) as unknown as Mocked<Playback>;
// Enqueue
playbackQueue.unsortedEnqueue(mockEvent, mockPlayback);
// Emit our clockInfo of 0, which will playbackQueue to save the state.
mockPlayback.clockInfo.liveData.update([0]);
// Fire an update event to say that we have stopped.
// Note that Playback really emits an UPDATE_EVENT whenever state changes, the types are lies.
mockPlayback.emit(UPDATE_EVENT as any, PlaybackState.Stopped);
expect(mockPlayback.skipTo).not.toHaveBeenCalled();
});
it("does call skipTo on playback if clock advances to 0s", () => {
const mockEvent = {
getId: jest.fn().mockReturnValue("$foo:bar"),
} as unknown as Mocked<MatrixEvent>;
const mockPlayback = new MockEventEmitter({
clockInfo: {
liveData: new SimpleObservable<number[]>(),
},
skipTo: jest.fn(),
}) as unknown as Mocked<Playback>;
// Enqueue
playbackQueue.unsortedEnqueue(mockEvent, mockPlayback);
// Emit our clockInfo of 0, which will playbackQueue to save the state.
mockPlayback.clockInfo.liveData.update([1]);
// Fire an update event to say that we have stopped.
// Note that Playback really emits an UPDATE_EVENT whenever state changes, the types are lies.
mockPlayback.emit(UPDATE_EVENT as any, PlaybackState.Stopped);
expect(mockPlayback.skipTo).toHaveBeenCalledWith(1);
});
});