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,
timelineRenderingType: TimelineRenderingType.Room,
liveTimeline: undefined,
resizing: false,
narrow,
};
}

View file

@ -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 () => {

View file

@ -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(<VoiceChannelRadio />);
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(<VoiceChannelRadio />);
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(<VoiceChannelRadio />);
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(<VoiceChannelRadio />);
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(<VoiceChannelRadio />);
act(() => {