* Move Room List to ListView - Also remove Space/Enter handing from keyboard navigation we can just leave the default behaviour of those keys and handle via onClick * Update rooms when the primary filter changes Otherwise when changing spaces, the filter does not reset until the next update to the RVS is made. * Fix stickyRow/scrollIntoView when switiching space or changing filters - Also remove the rest of space/enter keyboard handling use * Remove the rest of space/enter keyboard handling use * Remove useCombinedRef and add @radix-ui/react-compose-refs as we already depend on it - Also remove eact-virtualized dep * Update RoomList unit test * Update snapshots and unit tests * Fix e2e tests * Remove react-virtualized from tests * Fix e2e flake * Update more screenshots * Fix e2e test case where were should scroll to the top when the active room is no longer in the list * Move from gitpkg to package-patch * Update to latest react virtuoso release/api. Also pass spaceId to the room list and scroll the activeIndex into view when spaceId or primaryFilter change. * Use listbox/option roles to improve ScreenReader experience * Change onKeyDown e.stopPropogation to cover context menu * lint * Remove unneeded exposure of the listView ref Also move scrollIntoViewOnChange to useCallback * Update unit test and snapshot * Fix e2e tests and update screenshots * Fix unit test and snapshot * Update more unit tests * Fix keyboard shortcuts and e2e test * Fix another e2e and unit test * lint * Improve the naming for RoomResult and the documentation on it's fields meaning. Also update the login in RoomList to check for any change in filters, this is a bit more future proof for when we introduce multi select than using activePrimaryFilter. * Put back and fix landmark tests * Fix test import * Add comment regarding context object getting rendered. * onKeyDown should be optional * Use SpaceKey type on RoomResult * lint
93 lines
3.5 KiB
TypeScript
93 lines
3.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 React from "react";
|
|
import { render, screen } from "jest-matrix-react";
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
import { type RoomListViewState } from "../../../../../../src/components/viewmodels/roomlist/RoomListViewModel";
|
|
import { EmptyRoomList } from "../../../../../../src/components/views/rooms/RoomListPanel/EmptyRoomList";
|
|
import { FilterKey } from "../../../../../../src/stores/room-list-v3/skip-list/filters";
|
|
|
|
describe("<EmptyRoomList />", () => {
|
|
let vm: RoomListViewState;
|
|
|
|
beforeEach(() => {
|
|
vm = {
|
|
isLoadingRooms: false,
|
|
roomsResult: { spaceId: "home", rooms: [] },
|
|
primaryFilters: [],
|
|
createRoom: jest.fn(),
|
|
createChatRoom: jest.fn(),
|
|
canCreateRoom: true,
|
|
activeIndex: undefined,
|
|
};
|
|
});
|
|
|
|
test("should render the default placeholder when there is no filter", async () => {
|
|
const user = userEvent.setup();
|
|
|
|
const { asFragment } = render(<EmptyRoomList vm={vm} />);
|
|
expect(screen.getByText("No chats yet")).toBeInTheDocument();
|
|
expect(asFragment()).toMatchSnapshot();
|
|
|
|
await user.click(screen.getByRole("button", { name: "Start chat" }));
|
|
expect(vm.createChatRoom).toHaveBeenCalled();
|
|
|
|
await user.click(screen.getByRole("button", { name: "New room" }));
|
|
expect(vm.createRoom).toHaveBeenCalled();
|
|
});
|
|
|
|
test("should not render the new room button if the user doesn't have the rights to create a room", async () => {
|
|
const newState = { ...vm, canCreateRoom: false };
|
|
|
|
const { asFragment } = render(<EmptyRoomList vm={newState} />);
|
|
expect(screen.queryByRole("button", { name: "New room" })).toBeNull();
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
it.each([
|
|
{ key: FilterKey.UnreadFilter, name: "unread", action: "Show all chats" },
|
|
{ key: FilterKey.MentionsFilter, name: "mention", action: "See all activity" },
|
|
{ key: FilterKey.InvitesFilter, name: "invite", action: "See all activity" },
|
|
{ key: FilterKey.LowPriorityFilter, name: "low priority", action: "See all activity" },
|
|
])("should display the empty state for the $name filter", async ({ key, name, action }) => {
|
|
const user = userEvent.setup();
|
|
const activePrimaryFilter = {
|
|
toggle: jest.fn(),
|
|
active: true,
|
|
name,
|
|
key,
|
|
};
|
|
const newState = {
|
|
...vm,
|
|
activePrimaryFilter,
|
|
};
|
|
|
|
const { asFragment } = render(<EmptyRoomList vm={newState} />);
|
|
await user.click(screen.getByRole("button", { name: action }));
|
|
expect(activePrimaryFilter.toggle).toHaveBeenCalled();
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
it.each([
|
|
{ key: FilterKey.FavouriteFilter, name: "favourite" },
|
|
{ key: FilterKey.PeopleFilter, name: "people" },
|
|
{ key: FilterKey.RoomsFilter, name: "rooms" },
|
|
])("should display empty state for filter $name", ({ name, key }) => {
|
|
const activePrimaryFilter = {
|
|
toggle: jest.fn(),
|
|
active: true,
|
|
name,
|
|
key,
|
|
};
|
|
const newState = { ...vm, activePrimaryFilter };
|
|
const { asFragment } = render(<EmptyRoomList vm={newState} />);
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
});
|