Conform more of the code base to strict null checking (#10147)
* Conform more of the code base to strict null checking * More strict fixes * More strict work * Fix missing optional type * Iterate
This commit is contained in:
parent
fa036a5080
commit
da7aa4055e
380 changed files with 682 additions and 694 deletions
|
@ -83,7 +83,7 @@ describe("avatarUrlForRoom", () => {
|
|||
|
||||
it("should return null if there is no other member in the room", () => {
|
||||
mocked(dmRoomMap).getUserIdForRoomId.mockReturnValue("@user:example.com");
|
||||
mocked(room.getAvatarFallbackMember).mockReturnValue(null);
|
||||
mocked(room.getAvatarFallbackMember).mockReturnValue(undefined);
|
||||
expect(avatarUrlForRoom(room, 128, 128)).toBeNull();
|
||||
});
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ function renderComponent(component: TestRenderer.ReactTestRenderer): string {
|
|||
}
|
||||
|
||||
if (!Array.isArray(object) && object["type"] !== undefined && typeof object["children"] !== undefined) {
|
||||
return serializeObject(object.children);
|
||||
return serializeObject(object.children!);
|
||||
}
|
||||
|
||||
if (!Array.isArray(object)) {
|
||||
|
@ -80,7 +80,7 @@ function renderComponent(component: TestRenderer.ReactTestRenderer): string {
|
|||
.join("");
|
||||
};
|
||||
|
||||
return serializeObject(component.toJSON());
|
||||
return serializeObject(component.toJSON()!);
|
||||
}
|
||||
|
||||
describe("TextForEvent", () => {
|
||||
|
@ -219,12 +219,12 @@ describe("TextForEvent", () => {
|
|||
};
|
||||
|
||||
beforeAll(() => {
|
||||
mockClient = createTestClient();
|
||||
mockClient = createTestClient() as Mocked<MatrixClient>;
|
||||
MatrixClientPeg.get = () => mockClient;
|
||||
mockClient.getRoom.mockClear().mockReturnValue(mockRoom);
|
||||
mockRoom.getMember
|
||||
.mockClear()
|
||||
.mockImplementation((userId) => [userA, userB, userC].find((u) => u.userId === userId));
|
||||
.mockImplementation((userId) => [userA, userB, userC].find((u) => u.userId === userId) || null);
|
||||
(SettingsStore.getValue as jest.Mock).mockReturnValue(true);
|
||||
});
|
||||
|
||||
|
|
|
@ -45,9 +45,7 @@ describe("UserActivity", function () {
|
|||
|
||||
afterEach(function () {
|
||||
userActivity.stop();
|
||||
userActivity = null;
|
||||
clock.uninstall();
|
||||
clock = null;
|
||||
});
|
||||
|
||||
it("should return the same shared instance", function () {
|
||||
|
|
|
@ -49,7 +49,7 @@ describe("<RoomSearchView/>", () => {
|
|||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client.supportsThreads = jest.fn().mockReturnValue(true);
|
||||
room = new Room("!room:server", client, client.getUserId());
|
||||
room = new Room("!room:server", client, client.getUserId()!);
|
||||
mocked(client.getRoom).mockReturnValue(room);
|
||||
permalinkCreator = new RoomPermalinkCreator(room, room.roomId);
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe("<RoomSearchView/>", () => {
|
|||
result: {
|
||||
room_id: room.roomId,
|
||||
event_id: "$2",
|
||||
sender: client.getUserId(),
|
||||
sender: client.getUserId()!,
|
||||
origin_server_ts: 1,
|
||||
content: { body: "Foo Test Bar", msgtype: "m.text" },
|
||||
type: EventType.RoomMessage,
|
||||
|
@ -103,7 +103,7 @@ describe("<RoomSearchView/>", () => {
|
|||
{
|
||||
room_id: room.roomId,
|
||||
event_id: "$1",
|
||||
sender: client.getUserId(),
|
||||
sender: client.getUserId()!,
|
||||
origin_server_ts: 1,
|
||||
content: { body: "Before", msgtype: "m.text" },
|
||||
type: EventType.RoomMessage,
|
||||
|
@ -113,7 +113,7 @@ describe("<RoomSearchView/>", () => {
|
|||
{
|
||||
room_id: room.roomId,
|
||||
event_id: "$3",
|
||||
sender: client.getUserId(),
|
||||
sender: client.getUserId()!,
|
||||
origin_server_ts: 1,
|
||||
content: { body: "After", msgtype: "m.text" },
|
||||
type: EventType.RoomMessage,
|
||||
|
@ -154,7 +154,7 @@ describe("<RoomSearchView/>", () => {
|
|||
result: {
|
||||
room_id: room.roomId,
|
||||
event_id: "$2",
|
||||
sender: client.getUserId(),
|
||||
sender: client.getUserId()!,
|
||||
origin_server_ts: 1,
|
||||
content: { body: "Foo Test Bar", msgtype: "m.text" },
|
||||
type: EventType.RoomMessage,
|
||||
|
@ -192,7 +192,7 @@ describe("<RoomSearchView/>", () => {
|
|||
result: {
|
||||
room_id: room.roomId,
|
||||
event_id: "$2",
|
||||
sender: client.getUserId(),
|
||||
sender: client.getUserId()!,
|
||||
origin_server_ts: 1,
|
||||
content: { body: "Foo Test Bar", msgtype: "m.text" },
|
||||
type: EventType.RoomMessage,
|
||||
|
@ -221,7 +221,7 @@ describe("<RoomSearchView/>", () => {
|
|||
result: {
|
||||
room_id: room.roomId,
|
||||
event_id: "$4",
|
||||
sender: client.getUserId(),
|
||||
sender: client.getUserId()!,
|
||||
origin_server_ts: 4,
|
||||
content: { body: "Potato", msgtype: "m.text" },
|
||||
type: EventType.RoomMessage,
|
||||
|
|
|
@ -43,20 +43,20 @@ describe("<TabbedView />", () => {
|
|||
|
||||
it("renders first tab as active tab when no initialTabId", () => {
|
||||
const { container } = render(getComponent());
|
||||
expect(getActiveTab(container).textContent).toEqual(generalTab.label);
|
||||
expect(getActiveTabBody(container).textContent).toEqual("general");
|
||||
expect(getActiveTab(container)?.textContent).toEqual(generalTab.label);
|
||||
expect(getActiveTabBody(container)?.textContent).toEqual("general");
|
||||
});
|
||||
|
||||
it("renders first tab as active tab when initialTabId is not valid", () => {
|
||||
const { container } = render(getComponent({ initialTabId: "bad-tab-id" }));
|
||||
expect(getActiveTab(container).textContent).toEqual(generalTab.label);
|
||||
expect(getActiveTabBody(container).textContent).toEqual("general");
|
||||
expect(getActiveTab(container)?.textContent).toEqual(generalTab.label);
|
||||
expect(getActiveTabBody(container)?.textContent).toEqual("general");
|
||||
});
|
||||
|
||||
it("renders initialTabId tab as active when valid", () => {
|
||||
const { container } = render(getComponent({ initialTabId: securityTab.id }));
|
||||
expect(getActiveTab(container).textContent).toEqual(securityTab.label);
|
||||
expect(getActiveTabBody(container).textContent).toEqual("security");
|
||||
expect(getActiveTab(container)?.textContent).toEqual(securityTab.label);
|
||||
expect(getActiveTabBody(container)?.textContent).toEqual("security");
|
||||
});
|
||||
|
||||
it("renders without error when there are no tabs", () => {
|
||||
|
@ -71,8 +71,8 @@ describe("<TabbedView />", () => {
|
|||
fireEvent.click(getByTestId(getTabTestId(securityTab)));
|
||||
});
|
||||
|
||||
expect(getActiveTab(container).textContent).toEqual(securityTab.label);
|
||||
expect(getActiveTabBody(container).textContent).toEqual("security");
|
||||
expect(getActiveTab(container)?.textContent).toEqual(securityTab.label);
|
||||
expect(getActiveTabBody(container)?.textContent).toEqual("security");
|
||||
});
|
||||
|
||||
it("calls onchange on on tab click", () => {
|
||||
|
@ -90,29 +90,29 @@ describe("<TabbedView />", () => {
|
|||
// start with middle tab active
|
||||
const { container, rerender } = render(getComponent({ initialTabId: labsTab.id }));
|
||||
|
||||
expect(getActiveTab(container).textContent).toEqual(labsTab.label);
|
||||
expect(getActiveTab(container)?.textContent).toEqual(labsTab.label);
|
||||
|
||||
rerender(getComponent({ tabs: [labsTab, generalTab, securityTab] }));
|
||||
|
||||
// labs tab still active
|
||||
expect(getActiveTab(container).textContent).toEqual(labsTab.label);
|
||||
expect(getActiveTab(container)?.textContent).toEqual(labsTab.label);
|
||||
});
|
||||
|
||||
it("does not reactivate inititalTabId on rerender", () => {
|
||||
const { container, getByTestId, rerender } = render(getComponent());
|
||||
|
||||
expect(getActiveTab(container).textContent).toEqual(generalTab.label);
|
||||
expect(getActiveTab(container)?.textContent).toEqual(generalTab.label);
|
||||
|
||||
// make security tab active
|
||||
act(() => {
|
||||
fireEvent.click(getByTestId(getTabTestId(securityTab)));
|
||||
});
|
||||
expect(getActiveTab(container).textContent).toEqual(securityTab.label);
|
||||
expect(getActiveTab(container)?.textContent).toEqual(securityTab.label);
|
||||
|
||||
// rerender with new tab location
|
||||
rerender(getComponent({ tabLocation: TabLocation.TOP }));
|
||||
|
||||
// still security tab
|
||||
expect(getActiveTab(container).textContent).toEqual(securityTab.label);
|
||||
expect(getActiveTab(container)?.textContent).toEqual(securityTab.label);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -101,7 +101,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
|
||||
it("renders a map with markers", () => {
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent();
|
||||
expect(component.find("Map").props()).toEqual(
|
||||
|
@ -116,7 +116,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
it("does not render any own beacon status when user is not live sharing", () => {
|
||||
// default event belongs to alice, we are bob
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent();
|
||||
expect(component.find("DialogOwnBeaconStatus").html()).toBeNull();
|
||||
|
@ -125,7 +125,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
it("renders own beacon status when user is live sharing", () => {
|
||||
// default event belongs to alice
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
// mock own beacon store to show default event as alice's live beacon
|
||||
jest.spyOn(OwnBeaconStore.instance, "getLiveBeaconIds").mockReturnValue([beacon.identifier]);
|
||||
|
@ -141,7 +141,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
|
||||
it("updates markers on changes to beacons", () => {
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent();
|
||||
expect(component.find("BeaconMarker").length).toEqual(1);
|
||||
|
@ -161,7 +161,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
|
||||
it("does not update bounds or center on changing beacons", () => {
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent();
|
||||
expect(component.find("BeaconMarker").length).toEqual(1);
|
||||
|
@ -200,7 +200,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
it("renders map without markers when no live beacons remain", () => {
|
||||
const onFinished = jest.fn();
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent({ onFinished });
|
||||
expect(component.find("BeaconMarker").length).toEqual(1);
|
||||
|
@ -233,7 +233,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
describe("sidebar", () => {
|
||||
it("opens sidebar on view list button click", () => {
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent();
|
||||
|
||||
|
@ -244,7 +244,7 @@ describe("<BeaconViewDialog />", () => {
|
|||
|
||||
it("closes sidebar on close button click", () => {
|
||||
const room = setupRoom([defaultEvent]);
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent))!;
|
||||
beacon.addLocations([location1]);
|
||||
const component = getComponent();
|
||||
|
||||
|
|
|
@ -76,9 +76,9 @@ describe("InviteDialog", () => {
|
|||
});
|
||||
|
||||
it("should label with space name", () => {
|
||||
mockClient.getRoom(roomId).isSpaceRoom = jest.fn().mockReturnValue(true);
|
||||
mockClient.getRoom(roomId).getType = jest.fn().mockReturnValue(RoomType.Space);
|
||||
mockClient.getRoom(roomId).name = "Space";
|
||||
mockClient.getRoom(roomId)!.isSpaceRoom = jest.fn().mockReturnValue(true);
|
||||
mockClient.getRoom(roomId)!.getType = jest.fn().mockReturnValue(RoomType.Space);
|
||||
mockClient.getRoom(roomId)!.name = "Space";
|
||||
render(<InviteDialog kind={KIND_INVITE} roomId={roomId} onFinished={jest.fn()} />);
|
||||
|
||||
expect(screen.queryByText("Invite to Space")).toBeTruthy();
|
||||
|
|
|
@ -80,7 +80,10 @@ describe("<MBeaconBody />", () => {
|
|||
wrappingComponentProps: { value: mockClient },
|
||||
});
|
||||
|
||||
const modalSpy = jest.spyOn(Modal, "createDialog").mockReturnValue(undefined);
|
||||
const modalSpy = jest.spyOn(Modal, "createDialog").mockReturnValue({
|
||||
finished: Promise.resolve([true]),
|
||||
close: () => {},
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
@ -169,7 +172,7 @@ describe("<MBeaconBody />", () => {
|
|||
const room = makeRoomWithStateEvents([aliceBeaconInfo1], { roomId, mockClient });
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo1 });
|
||||
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo1));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo1))!;
|
||||
// update alice's beacon with a new edition
|
||||
// beacon instance emits
|
||||
act(() => {
|
||||
|
@ -190,7 +193,7 @@ describe("<MBeaconBody />", () => {
|
|||
const aliceBeaconInfo = makeBeaconInfoEvent(aliceId, roomId, { isLive: true }, "$alice-room1-1");
|
||||
|
||||
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo))!;
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||
|
||||
act(() => {
|
||||
|
@ -240,7 +243,7 @@ describe("<MBeaconBody />", () => {
|
|||
|
||||
it("renders a live beacon with a location correctly", () => {
|
||||
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo))!;
|
||||
beaconInstance.addLocations([location1]);
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||
|
||||
|
@ -249,7 +252,7 @@ describe("<MBeaconBody />", () => {
|
|||
|
||||
it("opens maximised map view on click when beacon has a live location", () => {
|
||||
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo))!;
|
||||
beaconInstance.addLocations([location1]);
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||
|
||||
|
@ -274,7 +277,7 @@ describe("<MBeaconBody />", () => {
|
|||
|
||||
it("renders a live beacon with a location correctly", () => {
|
||||
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo))!;
|
||||
beaconInstance.addLocations([location1]);
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||
|
||||
|
@ -283,7 +286,7 @@ describe("<MBeaconBody />", () => {
|
|||
|
||||
it("opens maximised map view on click when beacon has a live location", () => {
|
||||
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo))!;
|
||||
beaconInstance.addLocations([location1]);
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||
|
||||
|
@ -299,7 +302,7 @@ describe("<MBeaconBody />", () => {
|
|||
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo))!;
|
||||
act(() => {
|
||||
beaconInstance.addLocations([location1]);
|
||||
component.setProps({});
|
||||
|
@ -345,7 +348,7 @@ describe("<MBeaconBody />", () => {
|
|||
|
||||
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []) => {
|
||||
const room = makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent));
|
||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent))!;
|
||||
beaconInstance.addLocations(locationEvents);
|
||||
};
|
||||
const mockGetRelationsForEvent = (locationEvents: MatrixEvent[] = []) => {
|
||||
|
|
|
@ -69,7 +69,7 @@ describe("<MImageBody/>", () => {
|
|||
const props = {
|
||||
onHeightChanged: jest.fn(),
|
||||
onMessageAllowed: jest.fn(),
|
||||
permalinkCreator: new RoomPermalinkCreator(new Room(encryptedMediaEvent.getRoomId(), cli, cli.getUserId())),
|
||||
permalinkCreator: new RoomPermalinkCreator(new Room(encryptedMediaEvent.getRoomId()!, cli, cli.getUserId()!)),
|
||||
};
|
||||
|
||||
it("should show error when encrypted media cannot be downloaded", async () => {
|
||||
|
|
|
@ -83,7 +83,7 @@ describe("<PinnedMessagesCard />", () => {
|
|||
};
|
||||
|
||||
const mountPins = async (room: Room): Promise<ReactWrapper<ComponentProps<typeof PinnedMessagesCard>>> => {
|
||||
let pins: ReactWrapper<ComponentProps<typeof PinnedMessagesCard>>;
|
||||
let pins!: ReactWrapper<ComponentProps<typeof PinnedMessagesCard>>;
|
||||
await act(async () => {
|
||||
pins = mount(
|
||||
<PinnedMessagesCard
|
||||
|
|
|
@ -53,7 +53,7 @@ describe("NewRoomIntro", () => {
|
|||
describe("for a DM Room", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
|
||||
const room = new Room(roomId, client, client.getUserId());
|
||||
const room = new Room(roomId, client, client.getUserId()!);
|
||||
room.name = "test_room";
|
||||
renderNewRoomIntro(client, room);
|
||||
});
|
||||
|
@ -67,7 +67,7 @@ describe("NewRoomIntro", () => {
|
|||
describe("for a DM LocalRoom", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
|
||||
const localRoom = new LocalRoom(roomId, client, client.getUserId());
|
||||
const localRoom = new LocalRoom(roomId, client, client.getUserId()!);
|
||||
localRoom.name = "test_room";
|
||||
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
|
||||
renderNewRoomIntro(client, localRoom);
|
||||
|
|
|
@ -61,7 +61,7 @@ const setupMainMenu = async (client: MatrixClient, testSpace: Room): Promise<Ren
|
|||
|
||||
expect(wrapper.container.textContent).toBe("Test Space");
|
||||
act(() => {
|
||||
wrapper.container.querySelector<HTMLElement>('[aria-label="Test Space menu"]').click();
|
||||
wrapper.container.querySelector<HTMLElement>('[aria-label="Test Space menu"]')?.click();
|
||||
});
|
||||
|
||||
return wrapper;
|
||||
|
@ -77,7 +77,7 @@ const setupPlusMenu = async (client: MatrixClient, testSpace: Room): Promise<Ren
|
|||
|
||||
expect(wrapper.container.textContent).toBe("Test Space");
|
||||
act(() => {
|
||||
wrapper.container.querySelector<HTMLElement>('[aria-label="Add"]').click();
|
||||
wrapper.container.querySelector<HTMLElement>('[aria-label="Add"]')?.click();
|
||||
});
|
||||
|
||||
return wrapper;
|
||||
|
@ -92,7 +92,7 @@ const checkMenuLabels = (items: NodeListOf<Element>, labelArray: Array<string>)
|
|||
expect(items).toHaveLength(labelArray.length);
|
||||
|
||||
const checkLabel = (item: Element, label: string) => {
|
||||
expect(item.querySelector(".mx_IconizedContextMenu_label").textContent).toBe(label);
|
||||
expect(item.querySelector(".mx_IconizedContextMenu_label")?.textContent).toBe(label);
|
||||
};
|
||||
|
||||
labelArray.forEach((label, index) => {
|
||||
|
|
|
@ -84,9 +84,9 @@ describe("<RoomPreviewBar />", () => {
|
|||
const getActions = (wrapper: RenderResult) =>
|
||||
wrapper.container.querySelector<HTMLDivElement>(".mx_RoomPreviewBar_actions");
|
||||
const getPrimaryActionButton = (wrapper: RenderResult) =>
|
||||
getActions(wrapper).querySelector(".mx_AccessibleButton_kind_primary");
|
||||
getActions(wrapper)?.querySelector(".mx_AccessibleButton_kind_primary");
|
||||
const getSecondaryActionButton = (wrapper: RenderResult) =>
|
||||
getActions(wrapper).querySelector(".mx_AccessibleButton_kind_secondary");
|
||||
getActions(wrapper)?.querySelector(".mx_AccessibleButton_kind_secondary");
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
|
@ -102,17 +102,17 @@ describe("<RoomPreviewBar />", () => {
|
|||
const component = getComponent({ joining: true });
|
||||
|
||||
expect(isSpinnerRendered(component)).toBeTruthy();
|
||||
expect(getMessage(component).textContent).toEqual("Joining …");
|
||||
expect(getMessage(component)?.textContent).toEqual("Joining …");
|
||||
});
|
||||
it("renders rejecting message", () => {
|
||||
const component = getComponent({ rejecting: true });
|
||||
expect(isSpinnerRendered(component)).toBeTruthy();
|
||||
expect(getMessage(component).textContent).toEqual("Rejecting invite …");
|
||||
expect(getMessage(component)?.textContent).toEqual("Rejecting invite …");
|
||||
});
|
||||
it("renders loading message", () => {
|
||||
const component = getComponent({ loading: true });
|
||||
expect(isSpinnerRendered(component)).toBeTruthy();
|
||||
expect(getMessage(component).textContent).toEqual("Loading …");
|
||||
expect(getMessage(component)?.textContent).toEqual("Loading …");
|
||||
});
|
||||
|
||||
it("renders not logged in message", () => {
|
||||
|
@ -120,7 +120,7 @@ describe("<RoomPreviewBar />", () => {
|
|||
const component = getComponent({ loading: true });
|
||||
|
||||
expect(isSpinnerRendered(component)).toBeFalsy();
|
||||
expect(getMessage(component).textContent).toEqual("Join the conversation with an account");
|
||||
expect(getMessage(component)?.textContent).toEqual("Join the conversation with an account");
|
||||
});
|
||||
|
||||
it("should send room oob data to start login", async () => {
|
||||
|
@ -136,8 +136,8 @@ describe("<RoomPreviewBar />", () => {
|
|||
const dispatcherSpy = jest.fn();
|
||||
const dispatcherRef = defaultDispatcher.register(dispatcherSpy);
|
||||
|
||||
expect(getMessage(component).textContent).toEqual("Join the conversation with an account");
|
||||
fireEvent.click(getPrimaryActionButton(component));
|
||||
expect(getMessage(component)?.textContent).toEqual("Join the conversation with an account");
|
||||
fireEvent.click(getPrimaryActionButton(component)!);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(dispatcherSpy).toHaveBeenCalledWith(
|
||||
|
@ -268,14 +268,14 @@ describe("<RoomPreviewBar />", () => {
|
|||
|
||||
it("joins room on primary button click", () => {
|
||||
const component = getComponent({ inviterName, room, onJoinClick, onRejectClick });
|
||||
fireEvent.click(getPrimaryActionButton(component));
|
||||
fireEvent.click(getPrimaryActionButton(component)!);
|
||||
|
||||
expect(onJoinClick).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects invite on secondary button click", () => {
|
||||
const component = getComponent({ inviterName, room, onJoinClick, onRejectClick });
|
||||
fireEvent.click(getSecondaryActionButton(component));
|
||||
fireEvent.click(getSecondaryActionButton(component)!);
|
||||
|
||||
expect(onRejectClick).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -331,7 +331,7 @@ describe("<RoomPreviewBar />", () => {
|
|||
await new Promise(setImmediate);
|
||||
expect(getPrimaryActionButton(component)).toBeTruthy();
|
||||
expect(getSecondaryActionButton(component)).toBeFalsy();
|
||||
fireEvent.click(getPrimaryActionButton(component));
|
||||
fireEvent.click(getPrimaryActionButton(component)!);
|
||||
expect(onJoinClick).toHaveBeenCalled();
|
||||
};
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ describe("RolesRoomSettingsTab", () => {
|
|||
};
|
||||
|
||||
const getVoiceBroadcastsSelect = (): HTMLElement => {
|
||||
return renderTab().container.querySelector("select[label='Voice broadcasts']");
|
||||
return renderTab().container.querySelector("select[label='Voice broadcasts']")!;
|
||||
};
|
||||
|
||||
const getVoiceBroadcastsSelectedOption = (): HTMLElement => {
|
||||
return renderTab().container.querySelector("select[label='Voice broadcasts'] option:checked");
|
||||
return renderTab().container.querySelector("select[label='Voice broadcasts'] option:checked")!;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -65,7 +65,7 @@ describe("RolesRoomSettingsTab", () => {
|
|||
state_key: "",
|
||||
content: {
|
||||
users: {
|
||||
[cli.getUserId()]: 100,
|
||||
[cli.getUserId()!]: 100,
|
||||
"@admin:server": 100,
|
||||
},
|
||||
},
|
||||
|
@ -108,19 +108,19 @@ describe("RolesRoomSettingsTab", () => {
|
|||
};
|
||||
|
||||
const getStartCallSelect = (tab: RenderResult): HTMLElement => {
|
||||
return tab.container.querySelector("select[label='Start Element Call calls']");
|
||||
return tab.container.querySelector("select[label='Start Element Call calls']")!;
|
||||
};
|
||||
|
||||
const getStartCallSelectedOption = (tab: RenderResult): HTMLElement => {
|
||||
return tab.container.querySelector("select[label='Start Element Call calls'] option:checked");
|
||||
return tab.container.querySelector("select[label='Start Element Call calls'] option:checked")!;
|
||||
};
|
||||
|
||||
const getJoinCallSelect = (tab: RenderResult): HTMLElement => {
|
||||
return tab.container.querySelector("select[label='Join Element Call calls']");
|
||||
return tab.container.querySelector("select[label='Join Element Call calls']")!;
|
||||
};
|
||||
|
||||
const getJoinCallSelectedOption = (tab: RenderResult): HTMLElement => {
|
||||
return tab.container.querySelector("select[label='Join Element Call calls'] option:checked");
|
||||
return tab.container.querySelector("select[label='Join Element Call calls'] option:checked")!;
|
||||
};
|
||||
|
||||
describe("Element Call enabled", () => {
|
||||
|
|
|
@ -790,12 +790,12 @@ describe("SpaceStore", () => {
|
|||
event: true,
|
||||
type: EventType.SpaceChild,
|
||||
room: spaceId,
|
||||
user: client.getUserId(),
|
||||
user: client.getUserId()!,
|
||||
skey: childId,
|
||||
content: { via: [], canonical: true },
|
||||
ts: Date.now(),
|
||||
});
|
||||
const spaceRoom = client.getRoom(spaceId);
|
||||
const spaceRoom = client.getRoom(spaceId)!;
|
||||
mocked(spaceRoom.currentState).getStateEvents.mockImplementation(
|
||||
testUtils.mockStateEventImplementation([childEvent]),
|
||||
);
|
||||
|
@ -808,7 +808,7 @@ describe("SpaceStore", () => {
|
|||
event: true,
|
||||
type: EventType.RoomMember,
|
||||
room: spaceId,
|
||||
user: client.getUserId(),
|
||||
user: client.getUserId()!,
|
||||
skey: user.userId,
|
||||
content: { membership: "join" },
|
||||
ts: Date.now(),
|
||||
|
@ -1313,8 +1313,8 @@ describe("SpaceStore", () => {
|
|||
callback: (...args: any[]) => void,
|
||||
): () => void {
|
||||
callback();
|
||||
emitter.addListener(eventName, callback);
|
||||
return () => emitter.removeListener(eventName, callback);
|
||||
emitter?.addListener(eventName, callback);
|
||||
return () => emitter?.removeListener(eventName, callback);
|
||||
}
|
||||
|
||||
let metaSpaces;
|
||||
|
|
|
@ -172,8 +172,8 @@ describe("RecentAlgorithm", () => {
|
|||
room: room1.roomId,
|
||||
event: true,
|
||||
msg: `hello world`,
|
||||
rootEventId: rootEvent.getId(),
|
||||
replyToEventId: rootEvent.getId(),
|
||||
rootEventId: rootEvent.getId()!,
|
||||
replyToEventId: rootEvent.getId()!,
|
||||
// replies are 1ms after each other
|
||||
ts: 50,
|
||||
});
|
||||
|
|
|
@ -130,7 +130,7 @@ describe("StopGapWidgetDriver", () => {
|
|||
const aliceMobile = new DeviceInfo("aliceMobile");
|
||||
const bobDesktop = new DeviceInfo("bobDesktop");
|
||||
|
||||
mocked(client.crypto.deviceList).downloadKeys.mockResolvedValue({
|
||||
mocked(client.crypto!.deviceList).downloadKeys.mockResolvedValue({
|
||||
"@alice:example.org": { aliceWeb, aliceMobile },
|
||||
"@bob:example.org": { bobDesktop },
|
||||
});
|
||||
|
|
|
@ -69,12 +69,12 @@ export const makeThreadEvents = ({
|
|||
ts,
|
||||
});
|
||||
|
||||
const rootEventId = rootEvent.getId();
|
||||
const rootEventId = rootEvent.getId()!;
|
||||
const events = [rootEvent];
|
||||
|
||||
for (let i = 1; i < length; i++) {
|
||||
const prevEvent = events[i - 1];
|
||||
const replyToEventId = prevEvent.getId();
|
||||
const replyToEventId = prevEvent.getId()!;
|
||||
const user = participantUserIds[i % participantUserIds.length];
|
||||
events.push(
|
||||
makeThreadEvent({
|
||||
|
@ -95,7 +95,7 @@ export const makeThreadEvents = ({
|
|||
[RelationType.Thread]: {
|
||||
latest_event: events[events.length - 1],
|
||||
count: length,
|
||||
current_user_participated: [...participantUserIds, authorId].includes(currentUserId),
|
||||
current_user_participated: [...participantUserIds, authorId].includes(currentUserId!),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -126,7 +126,7 @@ export const mkThread = ({
|
|||
participantUserIds,
|
||||
length,
|
||||
ts,
|
||||
currentUserId: client.getUserId(),
|
||||
currentUserId: client.getUserId()!,
|
||||
});
|
||||
expect(rootEvent).toBeTruthy();
|
||||
|
||||
|
@ -134,7 +134,7 @@ export const mkThread = ({
|
|||
room?.reEmitter.reEmit(evt, [MatrixEventEvent.BeforeRedaction]);
|
||||
}
|
||||
|
||||
const thread = room.createThread(rootEvent.getId(), rootEvent, events, true);
|
||||
const thread = room.createThread(rootEvent.getId()!, rootEvent, events, true);
|
||||
// So that we do not have to mock the thread loading
|
||||
thread.initialEventsFetched = true;
|
||||
|
||||
|
|
|
@ -432,7 +432,7 @@ describe("EventUtils", () => {
|
|||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
|
||||
room = new Room(ROOM_ID, client, client.getUserId(), {
|
||||
room = new Room(ROOM_ID, client, client.getUserId()!, {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
});
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import type * as MegolmExportEncryptionExport from "../../src/utils/MegolmExport
|
|||
|
||||
const webCrypto = new Crypto();
|
||||
|
||||
function getRandomValues<T extends ArrayBufferView>(buf: T): T {
|
||||
function getRandomValues<T extends ArrayBufferView | null>(buf: T): T {
|
||||
// @ts-ignore fussy generics
|
||||
return nodeCrypto.randomFillSync(buf);
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ cissyYBxjsfsAn
|
|||
|
||||
// TODO find a subtlecrypto shim which doesn't break this test
|
||||
it.skip("should decrypt a range of inputs", function () {
|
||||
function next(i: number): unknown {
|
||||
function next(i: number): Promise<string | undefined> | undefined {
|
||||
if (i >= TEST_VECTORS.length) {
|
||||
return;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ cissyYBxjsfsAn
|
|||
return next(i + 1);
|
||||
});
|
||||
}
|
||||
return next(0);
|
||||
next(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ jest.mock("../../src/settings/SettingsStore", () => ({
|
|||
|
||||
const mockPromptBeforeInviteUnknownUsers = (value: boolean) => {
|
||||
mocked(SettingsStore.getValue).mockImplementation(
|
||||
(settingName: string, roomId: string = null, _excludeDefault = false): any => {
|
||||
(settingName: string, roomId: string, _excludeDefault = false): any => {
|
||||
if (settingName === "promptBeforeInviteUnknownUsers" && roomId === ROOMID) {
|
||||
return value;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ const mockPromptBeforeInviteUnknownUsers = (value: boolean) => {
|
|||
|
||||
const mockCreateTrackedDialog = (callbackName: "onInviteAnyways" | "onGiveUp") => {
|
||||
mocked(Modal.createDialog).mockImplementation((...rest: Parameters<ModalManager["createDialog"]>): any => {
|
||||
rest[1][callbackName]();
|
||||
rest[1]![callbackName]();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ describe("Singleflight", () => {
|
|||
});
|
||||
|
||||
it("should throw for bad context variables", () => {
|
||||
const permutations: [Object, string][] = [
|
||||
const permutations: [Object | null, string | null][] = [
|
||||
[null, null],
|
||||
[{}, null],
|
||||
[null, "test"],
|
||||
|
|
|
@ -44,9 +44,9 @@ function assertLocalRoom(room: LocalRoom, targets: Member[], encrypted: boolean)
|
|||
expect(roomCreateEvent.getContent()["room_version"]).toBe(KNOWN_SAFE_ROOM_VERSION);
|
||||
|
||||
// check that the user and all targets are joined
|
||||
expect(room.getMember("@userId:matrix.org").membership).toBe("join");
|
||||
expect(room.getMember("@userId:matrix.org")?.membership).toBe("join");
|
||||
targets.forEach((target: Member) => {
|
||||
expect(room.getMember(target.userId).membership).toBe("join");
|
||||
expect(room.getMember(target.userId)?.membership).toBe("join");
|
||||
});
|
||||
|
||||
if (encrypted) {
|
||||
|
|
|
@ -104,7 +104,7 @@ describe("HTMLExport", () => {
|
|||
/** set a mock fetch response for an MXC */
|
||||
function mockMxc(mxc: string, body: string) {
|
||||
const media = mediaFromMxc(mxc, client);
|
||||
fetchMock.get(media.srcHttp, body);
|
||||
fetchMock.get(media.srcHttp!, body);
|
||||
}
|
||||
|
||||
it("should have an SDK-branded destination file name", () => {
|
||||
|
@ -286,7 +286,7 @@ describe("HTMLExport", () => {
|
|||
|
||||
// Ensure that the attachment is present
|
||||
const files = getFiles(exporter);
|
||||
const file = files[Object.keys(files).find((k) => k.endsWith(".txt"))];
|
||||
const file = files[Object.keys(files).find((k) => k.endsWith(".txt"))!];
|
||||
expect(file).not.toBeUndefined();
|
||||
|
||||
// Ensure that the attachment has the expected content
|
||||
|
|
|
@ -26,12 +26,8 @@ describe("isLocalRoom", () => {
|
|||
|
||||
beforeEach(() => {
|
||||
const client = createTestClient();
|
||||
room = new Room("!room:example.com", client, client.getUserId());
|
||||
localRoom = new LocalRoom(LOCAL_ROOM_ID_PREFIX + "test", client, client.getUserId());
|
||||
});
|
||||
|
||||
it("should return false for null", () => {
|
||||
expect(isLocalRoom(null)).toBe(false);
|
||||
room = new Room("!room:example.com", client, client.getUserId()!);
|
||||
localRoom = new LocalRoom(LOCAL_ROOM_ID_PREFIX + "test", client, client.getUserId()!);
|
||||
});
|
||||
|
||||
it("should return false for a Room", () => {
|
||||
|
|
|
@ -59,6 +59,7 @@ describe("isRoomReady", () => {
|
|||
beforeEach(() => {
|
||||
mocked(client.getRoom).mockImplementation((roomId: string) => {
|
||||
if (roomId === room1.roomId) return room1;
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ describe("notifications", () => {
|
|||
}),
|
||||
});
|
||||
accountDataStore = {};
|
||||
accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId);
|
||||
accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId!);
|
||||
mocked(SettingsStore).getValue.mockReturnValue(false);
|
||||
});
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ describe("Permalinks", function () {
|
|||
|
||||
jest.spyOn(room, "getCanonicalAlias").mockReturnValue(null);
|
||||
jest.spyOn(room, "getJoinedMembers").mockReturnValue(members);
|
||||
jest.spyOn(room, "getMember").mockImplementation((userId) => members.find((m) => m.userId === userId));
|
||||
jest.spyOn(room, "getMember").mockImplementation((userId) => members.find((m) => m.userId === userId) || null);
|
||||
|
||||
return room;
|
||||
}
|
||||
|
@ -369,22 +369,22 @@ describe("Permalinks", function () {
|
|||
|
||||
it("should correctly parse room permalinks with a via argument", () => {
|
||||
const result = parsePermalink("https://matrix.to/#/!room_id:server?via=some.org");
|
||||
expect(result.roomIdOrAlias).toBe("!room_id:server");
|
||||
expect(result.viaServers).toEqual(["some.org"]);
|
||||
expect(result?.roomIdOrAlias).toBe("!room_id:server");
|
||||
expect(result?.viaServers).toEqual(["some.org"]);
|
||||
});
|
||||
|
||||
it("should correctly parse room permalink via arguments", () => {
|
||||
const result = parsePermalink("https://matrix.to/#/!room_id:server?via=foo.bar&via=bar.foo");
|
||||
expect(result.roomIdOrAlias).toBe("!room_id:server");
|
||||
expect(result.viaServers).toEqual(["foo.bar", "bar.foo"]);
|
||||
expect(result?.roomIdOrAlias).toBe("!room_id:server");
|
||||
expect(result?.viaServers).toEqual(["foo.bar", "bar.foo"]);
|
||||
});
|
||||
|
||||
it("should correctly parse event permalink via arguments", () => {
|
||||
const result = parsePermalink(
|
||||
"https://matrix.to/#/!room_id:server/$event_id/some_thing_here/foobar" + "?via=m1.org&via=m2.org",
|
||||
);
|
||||
expect(result.eventId).toBe("$event_id/some_thing_here/foobar");
|
||||
expect(result.roomIdOrAlias).toBe("!room_id:server");
|
||||
expect(result.viaServers).toEqual(["m1.org", "m2.org"]);
|
||||
expect(result?.eventId).toBe("$event_id/some_thing_here/foobar");
|
||||
expect(result?.roomIdOrAlias).toBe("!room_id:server");
|
||||
expect(result?.viaServers).toEqual(["m1.org", "m2.org"]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -37,8 +37,8 @@ describe("pillify", () => {
|
|||
beforeEach(() => {
|
||||
stubClient();
|
||||
const cli = MatrixClientPeg.get();
|
||||
(cli.getRoom as jest.Mock).mockReturnValue(new Room(roomId, cli, cli.getUserId()));
|
||||
cli.pushRules.global = {
|
||||
(cli.getRoom as jest.Mock).mockReturnValue(new Room(roomId, cli, cli.getUserId()!));
|
||||
cli.pushRules!.global = {
|
||||
override: [
|
||||
{
|
||||
rule_id: ".m.rule.roomnotif",
|
||||
|
@ -79,7 +79,7 @@ describe("pillify", () => {
|
|||
const containers: Element[] = [];
|
||||
pillifyLinks([container], event, containers);
|
||||
expect(containers).toHaveLength(1);
|
||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill").textContent).toBe("!@room");
|
||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
||||
});
|
||||
|
||||
it("should not double up pillification on repeated calls", () => {
|
||||
|
@ -90,6 +90,6 @@ describe("pillify", () => {
|
|||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks([container], event, containers);
|
||||
expect(containers).toHaveLength(1);
|
||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill").textContent).toBe("!@room");
|
||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ import { createTestClient, mkEvent } from "../../test-utils";
|
|||
|
||||
describe("getRoomFunctionalMembers", () => {
|
||||
const client = createTestClient();
|
||||
const room = new Room("!room:example.com", client, client.getUserId());
|
||||
const room = new Room("!room:example.com", client, client.getUserId()!);
|
||||
|
||||
it("should return an empty array if no functional members state event exists", () => {
|
||||
expect(getFunctionalMembers(room)).toHaveLength(0);
|
||||
|
|
|
@ -44,7 +44,7 @@ describe("tooltipify", () => {
|
|||
expect(containers).toHaveLength(1);
|
||||
const anchor = root.querySelector("a");
|
||||
expect(anchor?.getAttribute("href")).toEqual("/foo");
|
||||
const tooltip = anchor.querySelector(".mx_TextWithTooltip_target");
|
||||
const tooltip = anchor!.querySelector(".mx_TextWithTooltip_target");
|
||||
expect(tooltip).toBeDefined();
|
||||
});
|
||||
|
||||
|
@ -75,7 +75,7 @@ describe("tooltipify", () => {
|
|||
expect(containers).toHaveLength(1);
|
||||
const anchor = root.querySelector("a");
|
||||
expect(anchor?.getAttribute("href")).toEqual("/foo");
|
||||
const tooltip = anchor.querySelector(".mx_TextWithTooltip_target");
|
||||
const tooltip = anchor!.querySelector(".mx_TextWithTooltip_target");
|
||||
expect(tooltip).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { Optional } from "matrix-events-sdk";
|
||||
|
||||
import { VoiceRecording } from "../../../src/audio/VoiceRecording";
|
||||
import SdkConfig from "../../../src/SdkConfig";
|
||||
|
@ -188,7 +189,7 @@ describe("VoiceBroadcastRecorder", () => {
|
|||
itShouldNotEmitAChunkRecordedEvent();
|
||||
|
||||
describe("and calling stop", () => {
|
||||
let stopPayload: ChunkRecordedPayload;
|
||||
let stopPayload: Optional<ChunkRecordedPayload>;
|
||||
|
||||
beforeEach(async () => {
|
||||
stopPayload = await voiceBroadcastRecorder.stop();
|
||||
|
@ -213,7 +214,7 @@ describe("VoiceBroadcastRecorder", () => {
|
|||
});
|
||||
|
||||
describe("and calling stop() with recording.stop error)", () => {
|
||||
let stopPayload: ChunkRecordedPayload;
|
||||
let stopPayload: Optional<ChunkRecordedPayload>;
|
||||
|
||||
beforeEach(async () => {
|
||||
mocked(voiceRecording.stop).mockRejectedValue("Error");
|
||||
|
|
|
@ -44,6 +44,7 @@ describe("VoiceBroadcastRecordingsStore", () => {
|
|||
if (roomId === room.roomId) {
|
||||
return room;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
infoEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
|
|
|
@ -33,17 +33,18 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
const itShouldReturnNull = () => {
|
||||
it("should return null", () => {
|
||||
expect(
|
||||
findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId(), client.getDeviceId()),
|
||||
findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId()!, client.getDeviceId()!),
|
||||
).toBeNull();
|
||||
});
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
client = stubClient();
|
||||
room = new Room(roomId, client, client.getUserId());
|
||||
room = new Room(roomId, client, client.getUserId()!);
|
||||
jest.spyOn(room.currentState, "getStateEvents");
|
||||
mocked(client.getRoom).mockImplementation((getRoomId: string) => {
|
||||
if (getRoomId === roomId) return room;
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -58,7 +59,7 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
event: true,
|
||||
type: VoiceBroadcastInfoEventType,
|
||||
room: roomId,
|
||||
user: client.getUserId(),
|
||||
user: client.getUserId()!,
|
||||
content: {},
|
||||
}),
|
||||
]);
|
||||
|
@ -73,7 +74,7 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
client.getUserId(),
|
||||
client.getUserId()!,
|
||||
client.getDeviceId(),
|
||||
),
|
||||
]);
|
||||
|
@ -87,7 +88,7 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
const event = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Stopped,
|
||||
client.getUserId(),
|
||||
client.getUserId()!,
|
||||
"JKL123",
|
||||
);
|
||||
room.currentState.setStateEvents([event]);
|
||||
|
@ -103,7 +104,7 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
event = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
client.getUserId(),
|
||||
client.getUserId()!,
|
||||
client.getDeviceId(),
|
||||
);
|
||||
room.currentState.setStateEvents([event]);
|
||||
|
@ -112,10 +113,10 @@ describe("findRoomLiveVoiceBroadcastFromUserAndDevice", () => {
|
|||
it("should return this event", () => {
|
||||
expect(room.currentState.getStateEvents).toHaveBeenCalledWith(
|
||||
VoiceBroadcastInfoEventType,
|
||||
client.getUserId(),
|
||||
client.getUserId()!,
|
||||
);
|
||||
|
||||
expect(findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId(), client.getDeviceId())).toBe(
|
||||
expect(findRoomLiveVoiceBroadcastFromUserAndDevice(room, client.getUserId()!, client.getDeviceId()!)).toBe(
|
||||
event,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -85,7 +85,7 @@ describe("shouldDisplayAsVoiceBroadcastTile", () => {
|
|||
user: senderId,
|
||||
content: {},
|
||||
});
|
||||
event.getContent = () => undefined;
|
||||
event.getContent = () => ({} as any);
|
||||
});
|
||||
|
||||
itShouldReturnFalse();
|
||||
|
@ -119,7 +119,7 @@ describe("shouldDisplayAsVoiceBroadcastTile", () => {
|
|||
redacted_because: {} as unknown as IEvent,
|
||||
},
|
||||
});
|
||||
event.getContent = () => undefined;
|
||||
event.getContent = () => ({} as any);
|
||||
});
|
||||
|
||||
itShouldReturnTrue();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue