Test GridTile

This commit is contained in:
Robin
2024-09-06 17:27:08 -04:00
parent 0c0be8a862
commit ba36cfa239
3 changed files with 136 additions and 48 deletions

View File

@@ -14,52 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { RoomMember } from "matrix-js-sdk/src/matrix";
import { expect, test, vi } from "vitest";
import { LocalParticipant, RemoteParticipant } from "livekit-client";
import {
LocalUserMediaViewModel,
RemoteUserMediaViewModel,
} from "./MediaViewModel";
import { withTestScheduler } from "../utils/test";
withLocalMedia,
withRemoteMedia,
withTestScheduler,
} from "../utils/test";
function withLocal(continuation: (vm: LocalUserMediaViewModel) => void): void {
const member = {} as unknown as RoomMember;
const vm = new LocalUserMediaViewModel(
"a",
member,
{} as unknown as LocalParticipant,
true,
);
try {
continuation(vm);
} finally {
vm.destroy();
}
}
function withRemote(
participant: Partial<RemoteParticipant>,
continuation: (vm: RemoteUserMediaViewModel) => void,
): void {
const member = {} as unknown as RoomMember;
const vm = new RemoteUserMediaViewModel(
"a",
member,
{ setVolume() {}, ...participant } as RemoteParticipant,
true,
);
try {
continuation(vm);
} finally {
vm.destroy();
}
}
test("set a participant's volume", () => {
test("set a participant's volume", async () => {
const setVolumeSpy = vi.fn();
withRemote({ setVolume: setVolumeSpy }, (vm) =>
await withRemoteMedia({}, { setVolume: setVolumeSpy }, async (vm) =>
withTestScheduler(({ expectObservable, schedule }) => {
schedule("-a|", {
a() {
@@ -72,9 +37,9 @@ test("set a participant's volume", () => {
);
});
test("mute and unmute a participant", () => {
test("mute and unmute a participant", async () => {
const setVolumeSpy = vi.fn();
withRemote({ setVolume: setVolumeSpy }, (vm) =>
await withRemoteMedia({}, { setVolume: setVolumeSpy }, async (vm) =>
withTestScheduler(({ expectObservable, schedule }) => {
schedule("-abc|", {
a() {
@@ -99,8 +64,8 @@ test("mute and unmute a participant", () => {
);
});
test("toggle fit/contain for a participant's video", () => {
withRemote({}, (vm) =>
test("toggle fit/contain for a participant's video", async () => {
await withRemoteMedia({}, {}, async (vm) =>
withTestScheduler(({ expectObservable, schedule }) => {
schedule("-ab|", {
a: () => vm.toggleFitContain(),
@@ -115,15 +80,15 @@ test("toggle fit/contain for a participant's video", () => {
);
});
test("local media remembers whether it should always be shown", () => {
withLocal((vm) =>
test("local media remembers whether it should always be shown", async () => {
await withLocalMedia(async (vm) =>
withTestScheduler(({ expectObservable, schedule }) => {
schedule("-a|", { a: () => vm.setAlwaysShow(false) });
expectObservable(vm.alwaysShow).toBe("ab", { a: true, b: false });
}),
);
// Next local media should start out *not* always shown
withLocal((vm) =>
await withLocalMedia(async (vm) =>
withTestScheduler(({ expectObservable, schedule }) => {
schedule("-a|", { a: () => vm.setAlwaysShow(true) });
expectObservable(vm.alwaysShow).toBe("ab", { a: false, b: true });