Docker / Docker Buildx (push) Has been cancelled
Build Debian package / Build package (release) Has been cancelled
Build and Deploy / prepare (release) Has been cancelled
Deploy release / Deploy to Cloudflare Pages (release) Has been cancelled
Build and Deploy / Trigger Pro pipeline (release) Has been cancelled
Build and Deploy / Windows arm64 (release) Has been cancelled
Build and Deploy / Windows x64 (release) Has been cancelled
Build and Deploy / macOS (release) Has been cancelled
Build and Deploy / Linux amd64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / Linux arm64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / ${{ needs.prepare.outputs.deploy == 'true' && 'Deploy' || 'Deploy (dry-run)' }} (release) Has been cancelled
Build and Deploy / Deploy builds to ESS (release) Has been cancelled
79 lines
3.0 KiB
TypeScript
79 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 defaultDispatcher from "../../../src/dispatcher/dispatcher";
|
|
import { Action } from "../../../src/dispatcher/actions";
|
|
import { showCreateNewRoom } from "../../../src/utils/space";
|
|
import { hasCreateRoomRights, createRoom, hasAccessToNotificationMenu } from "../../../src/viewmodels/room-list/utils";
|
|
|
|
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);
|
|
});
|
|
});
|