2022-10-24 06:50:21 +00:00
|
|
|
/*
|
|
|
|
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 { render } from "@testing-library/react";
|
|
|
|
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
2022-11-10 18:01:19 +00:00
|
|
|
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
|
2022-10-24 06:50:21 +00:00
|
|
|
import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import RoomHeaderButtons from "../../../../src/components/views/right_panel/RoomHeaderButtons";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import { stubClient } from "../../../test-utils";
|
|
|
|
|
|
|
|
describe("RoomHeaderButtons-test.tsx", function () {
|
|
|
|
const ROOM_ID = "!roomId:example.org";
|
|
|
|
let room: Room;
|
|
|
|
let client: MatrixClient;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
|
|
|
stubClient();
|
|
|
|
client = MatrixClientPeg.get();
|
2022-11-10 18:01:19 +00:00
|
|
|
room = new Room(ROOM_ID, client, client.getUserId() ?? "", {
|
2022-10-24 06:50:21 +00:00
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
|
2022-12-13 15:09:15 +00:00
|
|
|
if (name === "feature_threadstable") return true;
|
2022-10-24 06:50:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-10 18:01:19 +00:00
|
|
|
function getComponent(room?: Room) {
|
2022-10-24 06:50:21 +00:00
|
|
|
return render(<RoomHeaderButtons room={room} excludedRightPanelPhaseButtons={[]} />);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getThreadButton(container) {
|
|
|
|
return container.querySelector(".mx_RightPanel_threadsButton");
|
|
|
|
}
|
|
|
|
|
|
|
|
function isIndicatorOfType(container, type: "red" | "gray") {
|
|
|
|
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator").className.includes(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
it("shows the thread button", () => {
|
|
|
|
const { container } = getComponent(room);
|
|
|
|
expect(getThreadButton(container)).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hides the thread button", () => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false);
|
|
|
|
const { container } = getComponent(room);
|
|
|
|
expect(getThreadButton(container)).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("room wide notification does not change the thread button", () => {
|
|
|
|
room.setUnreadNotificationCount(NotificationCountType.Highlight, 1);
|
|
|
|
room.setUnreadNotificationCount(NotificationCountType.Total, 1);
|
|
|
|
|
|
|
|
const { container } = getComponent(room);
|
|
|
|
|
|
|
|
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("room wide notification does not change the thread button", () => {
|
|
|
|
const { container } = getComponent(room);
|
|
|
|
|
|
|
|
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 1);
|
|
|
|
expect(isIndicatorOfType(container, "gray")).toBe(true);
|
|
|
|
|
|
|
|
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 1);
|
|
|
|
expect(isIndicatorOfType(container, "red")).toBe(true);
|
|
|
|
|
|
|
|
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 0);
|
|
|
|
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 0);
|
|
|
|
|
|
|
|
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
|
|
|
|
});
|
2022-11-10 18:01:19 +00:00
|
|
|
|
|
|
|
it("does not explode without a room", () => {
|
|
|
|
client.canSupport.set(Feature.ThreadUnreadNotifications, ServerSupport.Unsupported);
|
|
|
|
expect(() => getComponent()).not.toThrow();
|
|
|
|
});
|
2022-10-24 06:50:21 +00:00
|
|
|
});
|