mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-10-31 16:23:03 +00:00
a430501271
* add loading state to view model and spinner to room list vieqw * Update snapshots and add loading test * avoid nested ternary operator * Add room list skeleton loading state * Fix loading logic - Create RoomListStoreV3Event as to not conflict with loading event definition in Create RoomListStoreEvent. - Add a loaded event - Use it to determine loaded state in useFilteredRooms rather than the update event which gets fired in other cases. * Fix isLoadingRooms logic * update snapshots and fix test * Forcing an empty commit to fix PR * Fix _components.pcss order * Fix test that wasn't doing anything * fix tests
74 lines
2.5 KiB
TypeScript
74 lines
2.5 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 { SortOption } from "../../../../../../src/components/viewmodels/roomlist/useSorter";
|
|
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,
|
|
sort: jest.fn(),
|
|
activeSortOption: SortOption.Activity,
|
|
createRoom: jest.fn(),
|
|
createChatRoom: jest.fn(),
|
|
canCreateRoom: true,
|
|
toggleMessagePreview: jest.fn(),
|
|
shouldShowMessagePreview: false,
|
|
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();
|
|
});
|
|
});
|