From 03c80707c948bcc780fa464083ab069a4e7d3076 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 22 Mar 2022 16:40:09 -0600 Subject: [PATCH] Fix tests for type changes This is a conflict between https://github.com/matrix-org/matrix-react-sdk/pull/8104 and https://github.com/matrix-org/matrix-react-sdk/pull/8084 --- .../rooms/MessageComposerButtons-test.tsx | 1 + test/components/views/rooms/RoomTile-test.tsx | 28 ++++++++++++++----- .../views/voip/VoiceChannelRadio-test.tsx | 15 ++++++++-- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/test/components/views/rooms/MessageComposerButtons-test.tsx b/test/components/views/rooms/MessageComposerButtons-test.tsx index 65e9abb1e7..436fbd21f4 100644 --- a/test/components/views/rooms/MessageComposerButtons-test.tsx +++ b/test/components/views/rooms/MessageComposerButtons-test.tsx @@ -226,6 +226,7 @@ function createRoomState(room: Room, narrow: boolean): IRoomState { matrixClientIsReady: false, timelineRenderingType: TimelineRenderingType.Room, liveTimeline: undefined, + resizing: false, narrow, }; } diff --git a/test/components/views/rooms/RoomTile-test.tsx b/test/components/views/rooms/RoomTile-test.tsx index 31f927c2d3..56dc2cda88 100644 --- a/test/components/views/rooms/RoomTile-test.tsx +++ b/test/components/views/rooms/RoomTile-test.tsx @@ -17,11 +17,10 @@ limitations under the License. import React from "react"; import { mount } from "enzyme"; import { act } from "react-dom/test-utils"; -import { MatrixWidgetType } from "matrix-widget-api"; +import { ClientWidgetApi, MatrixWidgetType } from "matrix-widget-api"; import "../../../skinned-sdk"; import { stubClient, mkStubRoom } from "../../../test-utils"; -import PlatformPeg from "../../../../src/PlatformPeg"; import RoomTile from "../../../../src/components/views/rooms/RoomTile"; import SettingsStore from "../../../../src/settings/SettingsStore"; import WidgetStore from "../../../../src/stores/WidgetStore"; @@ -31,18 +30,33 @@ import VoiceChannelStore, { VoiceChannelEvent } from "../../../../src/stores/Voi import { DefaultTagID } from "../../../../src/stores/room-list/models"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; import { VOICE_CHANNEL_ID } from "../../../../src/utils/VoiceChannelUtils"; +import { mocked } from "jest-mock"; +import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; +import PlatformPeg from "../../../../src/PlatformPeg"; +import BasePlatform from "../../../../src/BasePlatform"; describe("RoomTile", () => { - PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false }); - SettingsStore.getValue = setting => setting === "feature_voice_rooms"; + jest.spyOn(PlatformPeg, 'get') + .mockReturnValue({ overrideBrowserShortcuts: () => false } as unknown as BasePlatform); + + const cli = mocked(MatrixClientPeg.get()); + beforeEach(() => { + const realGetValue = SettingsStore.getValue; + jest.spyOn(SettingsStore, 'getValue').mockImplementation((name, roomId) => { + if (name === "feature_voice_rooms") { + return true; + } + return realGetValue(name, roomId); + }); + stubClient(); DMRoomMap.makeShared(); }); describe("voice rooms", () => { - const room = mkStubRoom("!1:example.org"); - room.isCallRoom.mockReturnValue(true); + const room = mkStubRoom("!1:example.org", "voice room", cli); + room.isCallRoom = () => true; // Set up mocks to simulate the remote end of the widget API let messageSent; @@ -72,7 +86,7 @@ describe("RoomTile", () => { send: messageSendMock, reply: () => {}, }, - }); + } as unknown as ClientWidgetApi); }); it("tracks connection state", async () => { diff --git a/test/components/views/voip/VoiceChannelRadio-test.tsx b/test/components/views/voip/VoiceChannelRadio-test.tsx index c02545ab70..b26d7436cc 100644 --- a/test/components/views/voip/VoiceChannelRadio-test.tsx +++ b/test/components/views/voip/VoiceChannelRadio-test.tsx @@ -24,6 +24,8 @@ import { stubClient, mkStubRoom, wrapInMatrixClientContext } from "../../../test import _VoiceChannelRadio from "../../../../src/components/views/voip/VoiceChannelRadio"; import VoiceChannelStore, { VoiceChannelEvent } from "../../../../src/stores/VoiceChannelStore"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; +import { mocked } from "jest-mock"; +import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; const VoiceChannelRadio = wrapInMatrixClientContext(_VoiceChannelRadio); @@ -64,17 +66,20 @@ class StubVoiceChannelStore extends EventEmitter { } describe("VoiceChannelRadio", () => { - const room = mkStubRoom("!1:example.org"); - room.isCallRoom.mockReturnValue(true); + const cli = mocked(MatrixClientPeg.get()); + const room = mkStubRoom("!1:example.org", "voice channel", cli); + room.isCallRoom = () => true; beforeEach(() => { stubClient(); DMRoomMap.makeShared(); // Stub out the VoiceChannelStore - jest.spyOn(VoiceChannelStore, "instance", "get").mockReturnValue(new StubVoiceChannelStore()); + jest.spyOn(VoiceChannelStore, "instance", "get") + .mockReturnValue(new StubVoiceChannelStore() as unknown as VoiceChannelStore); }); it("shows when connecting voice", async () => { + // @ts-ignore - TS doesn't like mounting this for some reason, but is fine with it elsewhere const radio = mount(); expect(radio.children().children().exists()).toEqual(false); @@ -85,6 +90,7 @@ describe("VoiceChannelRadio", () => { it("hides when disconnecting voice", () => { VoiceChannelStore.instance.connect("!1:example.org"); + // @ts-ignore - TS doesn't like mounting this for some reason, but is fine with it elsewhere const radio = mount(); expect(radio.children().children().exists()).toEqual(true); @@ -96,6 +102,7 @@ describe("VoiceChannelRadio", () => { describe("disconnect button", () => { it("works", () => { VoiceChannelStore.instance.connect("!1:example.org"); + // @ts-ignore - TS doesn't like mounting this for some reason, but is fine with it elsewhere const radio = mount(); act(() => { @@ -108,6 +115,7 @@ describe("VoiceChannelRadio", () => { describe("video button", () => { it("works", () => { VoiceChannelStore.instance.connect("!1:example.org"); + // @ts-ignore - TS doesn't like mounting this for some reason, but is fine with it elsewhere const radio = mount(); act(() => { @@ -125,6 +133,7 @@ describe("VoiceChannelRadio", () => { describe("audio button", () => { it("works", () => { VoiceChannelStore.instance.connect("!1:example.org"); + // @ts-ignore - TS doesn't like mounting this for some reason, but is fine with it elsewhere const radio = mount(); act(() => {