Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add test to ensure the behavior is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Jan 23, 2023
1 parent 87b9c95 commit e35c1f6
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions test/components/structures/ThreadView-test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Copyright 2022-2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,8 @@ import ThreadView from "../../../src/components/structures/ThreadView";
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
import RoomContext from "../../../src/contexts/RoomContext";
import { SdkContextClass } from "../../../src/contexts/SDKContext";
import { Action } from "../../../src/dispatcher/actions";
import dispatcher from "../../../src/dispatcher/dispatcher";
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
import DMRoomMap from "../../../src/utils/DMRoomMap";
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
Expand All @@ -47,7 +49,7 @@ describe("ThreadView", () => {

let changeEvent: (event: MatrixEvent) => void;

function TestThreadView() {
function TestThreadView({ initialEvent }: { initialEvent?: MatrixEvent }) {
const [event, setEvent] = useState(rootEvent);
changeEvent = setEvent;

Expand All @@ -58,15 +60,21 @@ describe("ThreadView", () => {
canSendMessages: true,
})}
>
<ThreadView room={room} onClose={jest.fn()} mxEvent={event} resizeNotifier={new ResizeNotifier()} />
<ThreadView
room={room}
onClose={jest.fn()}
mxEvent={event}
initialEvent={initialEvent}
resizeNotifier={new ResizeNotifier()}
/>
</RoomContext.Provider>
,
</MatrixClientContext.Provider>
);
}

async function getComponent(): Promise<RenderResult> {
const renderResult = render(<TestThreadView />);
async function getComponent(initialEvent?: MatrixEvent): Promise<RenderResult> {
const renderResult = render(<TestThreadView initialEvent={initialEvent} />);

await waitFor(() => {
expect(() => getByTestId(renderResult.container, "spinner")).toThrow();
Expand Down Expand Up @@ -171,4 +179,17 @@ describe("ThreadView", () => {
unmount();
await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull());
});

it("clears highlight message in the room view store", async () => {
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
const mock = jest.spyOn(dispatcher, "dispatch");
const { unmount } = await getComponent(rootEvent);
mock.mockClear();
unmount();
expect(mock).toHaveBeenCalledWith({
action: Action.ViewRoom,
room_id: room.roomId,
metricsTrigger: undefined,
});
});
});

0 comments on commit e35c1f6

Please sign in to comment.