2022-10-20 19:48:25 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-10-20 19:48:25 +08:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 21:57:16 +08:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-10-20 19:48:25 +08:00
|
|
|
*/
|
|
|
|
|
2024-10-15 00:11:58 +08:00
|
|
|
import { getByTestId, render, screen } from "jest-matrix-react";
|
2022-10-20 19:48:25 +08:00
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
import { mocked } from "jest-mock";
|
2023-08-09 15:18:41 +08:00
|
|
|
import { MatrixClient, PendingEventOrdering, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
2022-10-20 19:48:25 +08:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import ThreadListContextMenu, {
|
|
|
|
ThreadListContextMenuProps,
|
|
|
|
} from "../../../../src/components/views/context_menus/ThreadListContextMenu";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
|
|
|
import { stubClient } from "../../../test-utils/test-utils";
|
|
|
|
import { mkThread } from "../../../test-utils/threads";
|
|
|
|
|
|
|
|
describe("ThreadListContextMenu", () => {
|
|
|
|
const ROOM_ID = "!123:matrix.org";
|
|
|
|
|
|
|
|
let room: Room;
|
|
|
|
let mockClient: MatrixClient;
|
|
|
|
let event: MatrixEvent;
|
|
|
|
|
|
|
|
function getComponent(props: Partial<ThreadListContextMenuProps>) {
|
|
|
|
return render(<ThreadListContextMenu mxEvent={event} {...props} />);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
|
|
|
stubClient();
|
2023-06-06 01:12:23 +08:00
|
|
|
mockClient = mocked(MatrixClientPeg.safeGet());
|
2022-10-20 19:48:25 +08:00
|
|
|
|
|
|
|
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
|
|
|
|
const res = mkThread({
|
|
|
|
room,
|
|
|
|
client: mockClient,
|
2023-02-17 01:21:44 +08:00
|
|
|
authorId: mockClient.getUserId()!,
|
|
|
|
participantUserIds: [mockClient.getUserId()!],
|
2022-10-20 19:48:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
event = res.rootEvent;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render the permalink", async () => {
|
|
|
|
const { container } = getComponent({});
|
|
|
|
|
|
|
|
const btn = getByTestId(container, "threadlist-dropdown-button");
|
|
|
|
await userEvent.click(btn);
|
|
|
|
expect(screen.queryByTestId("copy-thread-link")).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does render the permalink", async () => {
|
|
|
|
const { container } = getComponent({
|
|
|
|
permalinkCreator: new RoomPermalinkCreator(room, room.roomId, false),
|
|
|
|
});
|
|
|
|
|
|
|
|
const btn = getByTestId(container, "threadlist-dropdown-button");
|
|
|
|
await userEvent.click(btn);
|
|
|
|
expect(screen.queryByTestId("copy-thread-link")).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|