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
This commit is contained in:
Travis Ralston 2022-03-22 16:40:09 -06:00
parent 953e3148d1
commit 03c80707c9
3 changed files with 34 additions and 10 deletions

View file

@ -226,6 +226,7 @@ function createRoomState(room: Room, narrow: boolean): IRoomState {
matrixClientIsReady: false, matrixClientIsReady: false,
timelineRenderingType: TimelineRenderingType.Room, timelineRenderingType: TimelineRenderingType.Room,
liveTimeline: undefined, liveTimeline: undefined,
resizing: false,
narrow, narrow,
}; };
} }

View file

@ -17,11 +17,10 @@ limitations under the License.
import React from "react"; import React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { act } from "react-dom/test-utils"; import { act } from "react-dom/test-utils";
import { MatrixWidgetType } from "matrix-widget-api"; import { ClientWidgetApi, MatrixWidgetType } from "matrix-widget-api";
import "../../../skinned-sdk"; import "../../../skinned-sdk";
import { stubClient, mkStubRoom } from "../../../test-utils"; import { stubClient, mkStubRoom } from "../../../test-utils";
import PlatformPeg from "../../../../src/PlatformPeg";
import RoomTile from "../../../../src/components/views/rooms/RoomTile"; import RoomTile from "../../../../src/components/views/rooms/RoomTile";
import SettingsStore from "../../../../src/settings/SettingsStore"; import SettingsStore from "../../../../src/settings/SettingsStore";
import WidgetStore from "../../../../src/stores/WidgetStore"; 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 { DefaultTagID } from "../../../../src/stores/room-list/models";
import DMRoomMap from "../../../../src/utils/DMRoomMap"; import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { VOICE_CHANNEL_ID } from "../../../../src/utils/VoiceChannelUtils"; 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", () => { describe("RoomTile", () => {
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false }); jest.spyOn(PlatformPeg, 'get')
SettingsStore.getValue = setting => setting === "feature_voice_rooms"; .mockReturnValue({ overrideBrowserShortcuts: () => false } as unknown as BasePlatform);
const cli = mocked(MatrixClientPeg.get());
beforeEach(() => { beforeEach(() => {
const realGetValue = SettingsStore.getValue;
jest.spyOn(SettingsStore, 'getValue').mockImplementation((name, roomId) => {
if (name === "feature_voice_rooms") {
return true;
}
return realGetValue(name, roomId);
});
stubClient(); stubClient();
DMRoomMap.makeShared(); DMRoomMap.makeShared();
}); });
describe("voice rooms", () => { describe("voice rooms", () => {
const room = mkStubRoom("!1:example.org"); const room = mkStubRoom("!1:example.org", "voice room", cli);
room.isCallRoom.mockReturnValue(true); room.isCallRoom = () => true;
// Set up mocks to simulate the remote end of the widget API // Set up mocks to simulate the remote end of the widget API
let messageSent; let messageSent;
@ -72,7 +86,7 @@ describe("RoomTile", () => {
send: messageSendMock, send: messageSendMock,
reply: () => {}, reply: () => {},
}, },
}); } as unknown as ClientWidgetApi);
}); });
it("tracks connection state", async () => { it("tracks connection state", async () => {

View file

@ -24,6 +24,8 @@ import { stubClient, mkStubRoom, wrapInMatrixClientContext } from "../../../test
import _VoiceChannelRadio from "../../../../src/components/views/voip/VoiceChannelRadio"; import _VoiceChannelRadio from "../../../../src/components/views/voip/VoiceChannelRadio";
import VoiceChannelStore, { VoiceChannelEvent } from "../../../../src/stores/VoiceChannelStore"; import VoiceChannelStore, { VoiceChannelEvent } from "../../../../src/stores/VoiceChannelStore";
import DMRoomMap from "../../../../src/utils/DMRoomMap"; import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { mocked } from "jest-mock";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
const VoiceChannelRadio = wrapInMatrixClientContext(_VoiceChannelRadio); const VoiceChannelRadio = wrapInMatrixClientContext(_VoiceChannelRadio);
@ -64,17 +66,20 @@ class StubVoiceChannelStore extends EventEmitter {
} }
describe("VoiceChannelRadio", () => { describe("VoiceChannelRadio", () => {
const room = mkStubRoom("!1:example.org"); const cli = mocked(MatrixClientPeg.get());
room.isCallRoom.mockReturnValue(true); const room = mkStubRoom("!1:example.org", "voice channel", cli);
room.isCallRoom = () => true;
beforeEach(() => { beforeEach(() => {
stubClient(); stubClient();
DMRoomMap.makeShared(); DMRoomMap.makeShared();
// Stub out the VoiceChannelStore // 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 () => { 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(<VoiceChannelRadio />); const radio = mount(<VoiceChannelRadio />);
expect(radio.children().children().exists()).toEqual(false); expect(radio.children().children().exists()).toEqual(false);
@ -85,6 +90,7 @@ describe("VoiceChannelRadio", () => {
it("hides when disconnecting voice", () => { it("hides when disconnecting voice", () => {
VoiceChannelStore.instance.connect("!1:example.org"); 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(<VoiceChannelRadio />); const radio = mount(<VoiceChannelRadio />);
expect(radio.children().children().exists()).toEqual(true); expect(radio.children().children().exists()).toEqual(true);
@ -96,6 +102,7 @@ describe("VoiceChannelRadio", () => {
describe("disconnect button", () => { describe("disconnect button", () => {
it("works", () => { it("works", () => {
VoiceChannelStore.instance.connect("!1:example.org"); 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(<VoiceChannelRadio />); const radio = mount(<VoiceChannelRadio />);
act(() => { act(() => {
@ -108,6 +115,7 @@ describe("VoiceChannelRadio", () => {
describe("video button", () => { describe("video button", () => {
it("works", () => { it("works", () => {
VoiceChannelStore.instance.connect("!1:example.org"); 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(<VoiceChannelRadio />); const radio = mount(<VoiceChannelRadio />);
act(() => { act(() => {
@ -125,6 +133,7 @@ describe("VoiceChannelRadio", () => {
describe("audio button", () => { describe("audio button", () => {
it("works", () => { it("works", () => {
VoiceChannelStore.instance.connect("!1:example.org"); 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(<VoiceChannelRadio />); const radio = mount(<VoiceChannelRadio />);
act(() => { act(() => {