2021-10-14 15:27:35 +02:00
|
|
|
/*
|
|
|
|
Copyright 2021 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.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import React from "react";
|
2022-09-22 16:08:14 +02:00
|
|
|
import { render, screen, fireEvent } from "@testing-library/react";
|
|
|
|
import { mocked } from "jest-mock";
|
2022-12-12 12:24:14 +01:00
|
|
|
import "focus-visible"; // to fix context menus
|
2021-10-14 15:27:35 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import ThreadPanel, { ThreadFilterType, ThreadPanelHeader } from "../../../src/components/structures/ThreadPanel";
|
|
|
|
import { _t } from "../../../src/languageHandler";
|
|
|
|
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
|
|
|
|
import { RoomPermalinkCreator } from "../../../src/utils/permalinks/Permalinks";
|
|
|
|
import { createTestClient, mkStubRoom } from "../../test-utils";
|
2022-09-22 16:08:14 +02:00
|
|
|
import { shouldShowFeedback } from "../../../src/utils/Feedback";
|
|
|
|
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
|
|
|
|
|
|
|
jest.mock("../../../src/utils/Feedback");
|
2021-10-14 15:27:35 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("ThreadPanel", () => {
|
2022-09-22 16:08:14 +02:00
|
|
|
describe("Feedback prompt", () => {
|
|
|
|
const cli = createTestClient();
|
|
|
|
const room = mkStubRoom("!room:server", "room", cli);
|
|
|
|
mocked(cli.getRoom).mockReturnValue(room);
|
|
|
|
|
|
|
|
it("should show feedback prompt if feedback is enabled", () => {
|
|
|
|
mocked(shouldShowFeedback).mockReturnValue(true);
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
render(
|
|
|
|
<MatrixClientContext.Provider value={cli}>
|
|
|
|
<ThreadPanel
|
|
|
|
roomId="!room:server"
|
|
|
|
onClose={jest.fn()}
|
|
|
|
resizeNotifier={new ResizeNotifier()}
|
|
|
|
permalinkCreator={new RoomPermalinkCreator(room)}
|
|
|
|
/>
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
2022-09-22 16:08:14 +02:00
|
|
|
expect(screen.queryByText("Give feedback")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should hide feedback prompt if feedback is disabled", () => {
|
|
|
|
mocked(shouldShowFeedback).mockReturnValue(false);
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
render(
|
|
|
|
<MatrixClientContext.Provider value={cli}>
|
|
|
|
<ThreadPanel
|
|
|
|
roomId="!room:server"
|
|
|
|
onClose={jest.fn()}
|
|
|
|
resizeNotifier={new ResizeNotifier()}
|
|
|
|
permalinkCreator={new RoomPermalinkCreator(room)}
|
|
|
|
/>
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
2022-09-22 16:08:14 +02:00
|
|
|
expect(screen.queryByText("Give feedback")).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("Header", () => {
|
|
|
|
it("expect that All filter for ThreadPanelHeader properly renders Show: All threads", () => {
|
2022-09-22 16:08:14 +02:00
|
|
|
const { asFragment } = render(
|
2021-10-14 15:27:35 +02:00
|
|
|
<ThreadPanelHeader
|
2022-02-24 09:44:34 +01:00
|
|
|
empty={false}
|
2021-10-14 15:27:35 +02:00
|
|
|
filterOption={ThreadFilterType.All}
|
2022-12-12 12:24:14 +01:00
|
|
|
setFilterOption={() => undefined}
|
|
|
|
/>,
|
2021-10-14 15:27:35 +02:00
|
|
|
);
|
2022-09-22 16:08:14 +02:00
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2021-10-14 15:27:35 +02:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("expect that My filter for ThreadPanelHeader properly renders Show: My threads", () => {
|
2022-09-22 16:08:14 +02:00
|
|
|
const { asFragment } = render(
|
2021-10-14 15:27:35 +02:00
|
|
|
<ThreadPanelHeader
|
2022-02-24 09:44:34 +01:00
|
|
|
empty={false}
|
2021-10-14 15:27:35 +02:00
|
|
|
filterOption={ThreadFilterType.My}
|
2022-12-12 12:24:14 +01:00
|
|
|
setFilterOption={() => undefined}
|
|
|
|
/>,
|
2021-10-14 15:27:35 +02:00
|
|
|
);
|
2022-09-22 16:08:14 +02:00
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2021-10-14 15:27:35 +02:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("expect that ThreadPanelHeader properly opens a context menu when clicked on the button", () => {
|
2022-09-22 16:08:14 +02:00
|
|
|
const { container } = render(
|
2021-10-14 15:27:35 +02:00
|
|
|
<ThreadPanelHeader
|
2022-02-24 09:44:34 +01:00
|
|
|
empty={false}
|
2021-10-14 15:27:35 +02:00
|
|
|
filterOption={ThreadFilterType.All}
|
2022-12-12 12:24:14 +01:00
|
|
|
setFilterOption={() => undefined}
|
|
|
|
/>,
|
2021-10-14 15:27:35 +02:00
|
|
|
);
|
2022-09-22 16:08:14 +02:00
|
|
|
const found = container.querySelector(".mx_ThreadPanel_dropdown");
|
|
|
|
expect(found).toBeTruthy();
|
|
|
|
expect(screen.queryByRole("menu")).toBeFalsy();
|
|
|
|
fireEvent.click(found);
|
|
|
|
expect(screen.queryByRole("menu")).toBeTruthy();
|
2021-10-14 15:27:35 +02:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("expect that ThreadPanelHeader has the correct option selected in the context menu", () => {
|
2022-09-22 16:08:14 +02:00
|
|
|
const { container } = render(
|
2021-10-14 15:27:35 +02:00
|
|
|
<ThreadPanelHeader
|
2022-02-24 09:44:34 +01:00
|
|
|
empty={false}
|
2021-10-14 15:27:35 +02:00
|
|
|
filterOption={ThreadFilterType.All}
|
2022-12-12 12:24:14 +01:00
|
|
|
setFilterOption={() => undefined}
|
|
|
|
/>,
|
2021-10-14 15:27:35 +02:00
|
|
|
);
|
2022-09-22 16:08:14 +02:00
|
|
|
fireEvent.click(container.querySelector(".mx_ThreadPanel_dropdown"));
|
|
|
|
const found = screen.queryAllByRole("menuitemradio");
|
|
|
|
expect(found).toHaveLength(2);
|
|
|
|
const foundButton = screen.queryByRole("menuitemradio", { checked: true });
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(foundButton.textContent).toEqual(`${_t("All threads")}${_t("Shows all threads from current room")}`);
|
2021-10-14 15:27:35 +02:00
|
|
|
expect(foundButton).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|