* feat: move sort and preview into room list header vm * feat: move sort menu into room list header * test: update tests * test:update snapshots * chore: remove secondary filter tests * test(e2e): update screenshots
69 lines
2.2 KiB
TypeScript
69 lines
2.2 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 { render, screen } from "jest-matrix-react";
|
|
import React from "react";
|
|
|
|
import {
|
|
type RoomListViewState,
|
|
useRoomListViewModel,
|
|
} from "../../../../../../src/components/viewmodels/roomlist/RoomListViewModel";
|
|
import { SecondaryFilters } from "../../../../../../src/components/viewmodels/roomlist/useFilteredRooms";
|
|
import { RoomListView } from "../../../../../../src/components/views/rooms/RoomListPanel/RoomListView";
|
|
import { mkRoom, stubClient } from "../../../../../test-utils";
|
|
|
|
jest.mock("../../../../../../src/components/viewmodels/roomlist/RoomListViewModel", () => ({
|
|
useRoomListViewModel: jest.fn(),
|
|
}));
|
|
|
|
describe("<RoomListView />", () => {
|
|
const defaultValue: RoomListViewState = {
|
|
isLoadingRooms: false,
|
|
rooms: [],
|
|
primaryFilters: [],
|
|
activateSecondaryFilter: jest.fn().mockReturnValue({}),
|
|
activeSecondaryFilter: SecondaryFilters.AllActivity,
|
|
createRoom: jest.fn(),
|
|
createChatRoom: jest.fn(),
|
|
canCreateRoom: true,
|
|
activeIndex: undefined,
|
|
};
|
|
const matrixClient = stubClient();
|
|
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it("should render the loading room list", () => {
|
|
mocked(useRoomListViewModel).mockReturnValue({
|
|
...defaultValue,
|
|
isLoadingRooms: true,
|
|
});
|
|
|
|
const roomList = render(<RoomListView />);
|
|
expect(roomList.container.querySelector(".mx_RoomListSkeleton")).not.toBeNull();
|
|
});
|
|
|
|
it("should render an empty room list", () => {
|
|
mocked(useRoomListViewModel).mockReturnValue(defaultValue);
|
|
|
|
render(<RoomListView />);
|
|
expect(screen.getByText("No chats yet")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should render a room list", () => {
|
|
mocked(useRoomListViewModel).mockReturnValue({
|
|
...defaultValue,
|
|
rooms: [mkRoom(matrixClient, "testing room")],
|
|
});
|
|
|
|
render(<RoomListView />);
|
|
expect(screen.getByRole("grid", { name: "Room list" })).toBeInTheDocument();
|
|
});
|
|
});
|