mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-18 06:35:35 +08:00
be281fd735
* Use RelationType enum instead of hardcoded value * Fix threads replies fallback to target last reply * Only unsubscribe from threads events if needed * fix strict null check * fix strict null checks * strict null checks * fix typing * Unsubscribe listeners if new thread is `null` Co-authored-by: Faye Duxovni <fayed@element.io> * Update strict null checks * Type HTMLElement as nullable * Add thread fallback integration test * lint fix * Update snapshots * Add test after changing thread * Remove test comment * update snapshot * fix room context test utility * Add ThreadListContextMenu test * lint fix * fix thread rendering Co-authored-by: Faye Duxovni <fayed@element.io> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
85 lines
2.9 KiB
TypeScript
85 lines
2.9 KiB
TypeScript
/*
|
|
Copyright 2022 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.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { getByTestId, render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { mocked } from "jest-mock";
|
|
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
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();
|
|
mockClient = mocked(MatrixClientPeg.get());
|
|
|
|
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
});
|
|
|
|
const res = mkThread({
|
|
room,
|
|
client: mockClient,
|
|
authorId: mockClient.getUserId(),
|
|
participantUserIds: [mockClient.getUserId()],
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|