Skip to content

Commit 8ad5d3b

Browse files
committed
Write test for matrixchat
1 parent b6c3f46 commit 8ad5d3b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/unit-tests/components/structures/MatrixChat-test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import AutoDiscoveryUtils from "../../../../src/utils/AutoDiscoveryUtils";
6868
import { type ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
6969
import Modal from "../../../../src/Modal.tsx";
7070
import { SetupEncryptionStore } from "../../../../src/stores/SetupEncryptionStore.ts";
71+
import RoomListStore from "../../../../src/stores/room-list/RoomListStore.ts";
7172

7273
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
7374
completeAuthorizationCodeGrant: jest.fn(),
@@ -154,6 +155,7 @@ describe("<MatrixChat />", () => {
154155
whoami: jest.fn(),
155156
logout: jest.fn(),
156157
getDeviceId: jest.fn(),
158+
forget: () => Promise.resolve(),
157159
});
158160
let mockClient: Mocked<MatrixClient>;
159161
const serverConfig = {
@@ -675,6 +677,34 @@ describe("<MatrixChat />", () => {
675677
jest.restoreAllMocks();
676678
});
677679

680+
describe("forget_room", () => {
681+
it("should dispatch after_forget_room action on successful forget", async () => {
682+
await clearAllModals();
683+
await getComponentAndWaitForReady();
684+
685+
// Mock out the old room list store
686+
jest.spyOn(RoomListStore.instance, "manualRoomUpdate").mockImplementation(async () => {});
687+
688+
// Register a mock function to the dispatcher
689+
const fn = jest.fn();
690+
defaultDispatcher.register(fn);
691+
692+
// Forge the room
693+
defaultDispatcher.dispatch({
694+
action: "forget_room",
695+
room_id: roomId,
696+
});
697+
698+
// On success, we expect the following action to have been dispatched.
699+
await waitFor(() => {
700+
expect(fn).toHaveBeenCalledWith({
701+
action: Action.AfterForgetRoom,
702+
room: room,
703+
});
704+
});
705+
});
706+
});
707+
678708
describe("leave_room", () => {
679709
beforeEach(async () => {
680710
await clearAllModals();

0 commit comments

Comments
 (0)