You've already forked element-web
mirror of
https://github.com/element-hq/element-web.git
synced 2025-08-09 14:42:51 +03:00
* feat: add `utils.hasAccessToNotificationMenu` * feat(room list item view model): use `hasAccessToNotificationMenu` to compute `showHoverMenu` * feat(room list item menu view model): add notification options menu attributes * feat(room list item menu view): add notification options * test: add tests for `utils.hasAccessToNotificationMenu` * test(room list item view model): add test for `showHoverMenu` * test(room list item menu view model): add tests for new attributes * test(room list item menu view): add tests for notification options menu * chore: update i18n * test(e2e): update screenshots * test(e2e): add tests for notification options menu
83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
/*
|
|
* Copyright 2025 New Vector Ltd.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
* Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { mocked } from "jest-mock";
|
|
|
|
import type { MatrixClient, Room, RoomState } from "matrix-js-sdk/src/matrix";
|
|
import { createTestClient, mkStubRoom } from "../../../../test-utils";
|
|
import { shouldShowComponent } from "../../../../../src/customisations/helpers/UIComponents";
|
|
import {
|
|
hasCreateRoomRights,
|
|
createRoom,
|
|
hasAccessToNotificationMenu,
|
|
} from "../../../../../src/components/viewmodels/roomlist/utils";
|
|
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher";
|
|
import { Action } from "../../../../../src/dispatcher/actions";
|
|
import { showCreateNewRoom } from "../../../../../src/utils/space";
|
|
|
|
jest.mock("../../../../../src/customisations/helpers/UIComponents", () => ({
|
|
shouldShowComponent: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("../../../../../src/utils/space", () => ({
|
|
showCreateNewRoom: jest.fn(),
|
|
}));
|
|
|
|
describe("utils", () => {
|
|
let matrixClient: MatrixClient;
|
|
let space: Room;
|
|
|
|
beforeEach(() => {
|
|
matrixClient = createTestClient();
|
|
space = mkStubRoom("spaceId", "spaceName", matrixClient);
|
|
});
|
|
|
|
describe("createRoom", () => {
|
|
it("should fire Action.CreateRoom when createRoom is called without a space", async () => {
|
|
const spy = jest.spyOn(defaultDispatcher, "fire");
|
|
await createRoom();
|
|
|
|
expect(spy).toHaveBeenCalledWith(Action.CreateRoom);
|
|
});
|
|
|
|
it("should call showCreateNewRoom when createRoom is called in a space", async () => {
|
|
await createRoom(space);
|
|
expect(showCreateNewRoom).toHaveBeenCalledWith(space);
|
|
});
|
|
});
|
|
|
|
describe("hasCreateRoomRights", () => {
|
|
it("should return false when UIComponent.CreateRooms is disabled", () => {
|
|
mocked(shouldShowComponent).mockReturnValue(false);
|
|
expect(hasCreateRoomRights(matrixClient, space)).toBe(false);
|
|
});
|
|
|
|
it("should return true when UIComponent.CreateRooms is enabled and no space", () => {
|
|
mocked(shouldShowComponent).mockReturnValue(true);
|
|
expect(hasCreateRoomRights(matrixClient)).toBe(true);
|
|
});
|
|
|
|
it("should return false in space when UIComponent.CreateRooms is enabled and the user doesn't have the rights", () => {
|
|
mocked(shouldShowComponent).mockReturnValue(true);
|
|
jest.spyOn(space.getLiveTimeline(), "getState").mockReturnValue({
|
|
maySendStateEvent: jest.fn().mockReturnValue(true),
|
|
} as unknown as RoomState);
|
|
|
|
expect(hasCreateRoomRights(matrixClient)).toBe(true);
|
|
});
|
|
});
|
|
|
|
it("hasAccessToNotificationMenu", () => {
|
|
mocked(shouldShowComponent).mockReturnValue(true);
|
|
const room = mkStubRoom("roomId", "roomName", matrixClient);
|
|
const isGuest = false;
|
|
const isArchived = false;
|
|
|
|
expect(hasAccessToNotificationMenu(room, isGuest, isArchived)).toBe(true);
|
|
});
|
|
});
|