New room list: move message preview in user settings (#30023)

* feat: move message preview settings to user settings

* test: update tests

* test(e2e): update preference screenshots

* test(e2e): update room list tests

* fix: display message preview settings only for new room list

* test(e2e): display all preference settings in screenshot

* test: update snapshot
This commit is contained in:
Florian Duros
2025-06-05 16:14:09 +02:00
committed by GitHub
parent ad71e7bdc4
commit 140afea791
11 changed files with 20 additions and 114 deletions

View File

@@ -13,7 +13,7 @@ import { range } from "lodash";
import { useRoomListHeaderViewModel } from "../../../../../src/components/viewmodels/roomlist/RoomListHeaderViewModel";
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
import { mkStubRoom, stubClient, withClientContextRenderOptions } from "../../../../test-utils";
import SettingsStore, { type CallbackFn } from "../../../../../src/settings/SettingsStore";
import SettingsStore from "../../../../../src/settings/SettingsStore";
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher";
import { Action } from "../../../../../src/dispatcher/actions";
import {
@@ -24,7 +24,6 @@ import {
showSpaceSettings,
} from "../../../../../src/utils/space";
import { createRoom, hasCreateRoomRights } from "../../../../../src/components/viewmodels/roomlist/utils";
import { SettingLevel } from "../../../../../src/settings/SettingLevel";
import RoomListStoreV3 from "../../../../../src/stores/room-list-v3/RoomListStoreV3";
import { SortOption } from "../../../../../src/components/viewmodels/roomlist/useSorter";
import { SortingAlgorithm } from "../../../../../src/stores/room-list-v3/skip-list/sorters";
@@ -238,38 +237,4 @@ describe("useRoomListHeaderViewModel", () => {
expect(vm.current.activeSortOption).toEqual(SortOption.AToZ);
});
});
describe("message preview toggle", () => {
it("should return shouldShowMessagePreview based on setting", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation(() => true);
const { result: vm } = render();
expect(vm.current.shouldShowMessagePreview).toEqual(true);
});
it("should update when setting changes", async () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation(() => true);
let watchFn: CallbackFn;
jest.spyOn(SettingsStore, "watchSetting").mockImplementation((settingName, _roomId, fn) => {
if (settingName === "RoomList.showMessagePreview") watchFn = fn;
return "";
});
const { result: vm } = render();
expect(vm.current.shouldShowMessagePreview).toEqual(true);
jest.spyOn(SettingsStore, "getValue").mockImplementation(() => false);
act(() => watchFn("RoomList.showMessagePreview", "", SettingLevel.DEVICE, false, false));
expect(vm.current.shouldShowMessagePreview).toEqual(false);
});
it("should change setting on toggle", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation(() => true);
const fn = jest.spyOn(SettingsStore, "setValue").mockImplementation(async () => {});
const { result: vm } = render();
expect(vm.current.shouldShowMessagePreview).toEqual(true);
act(() => vm.current.toggleMessagePreview());
expect(fn).toHaveBeenCalledWith("RoomList.showMessagePreview", null, "device", false);
});
});
});

View File

@@ -32,8 +32,6 @@ describe("<RoomListHeaderView />", () => {
canAccessSpaceSettings: true,
sort: jest.fn(),
activeSortOption: SortOption.Activity,
shouldShowMessagePreview: false,
toggleMessagePreview: jest.fn(),
createRoom: jest.fn(),
createVideoRoom: jest.fn(),
createChatRoom: jest.fn(),

View File

@@ -91,48 +91,4 @@ describe("<RoomListOptionsMenu />", () => {
expect(vm.sort).toHaveBeenCalledWith("Recency");
});
it("should show message previews disabled", async () => {
const user = userEvent.setup();
const vm = {
shouldShowMessagePreview: false,
} as unknown as RoomListHeaderViewState;
render(<RoomListOptionsMenu vm={vm} />);
await user.click(screen.getByRole("button", { name: "Room Options" }));
expect(screen.getByRole("menuitemcheckbox", { name: "Show message previews" })).not.toBeChecked();
});
it("should show message previews enabled", async () => {
const user = userEvent.setup();
const vm = {
shouldShowMessagePreview: true,
} as unknown as RoomListHeaderViewState;
render(<RoomListOptionsMenu vm={vm} />);
await user.click(screen.getByRole("button", { name: "Room Options" }));
expect(screen.getByRole("menuitemcheckbox", { name: "Show message previews" })).toBeChecked();
});
it("should toggle message previews", async () => {
const user = userEvent.setup();
const vm = {
toggleMessagePreview: jest.fn(),
} as unknown as RoomListHeaderViewState;
render(<RoomListOptionsMenu vm={vm} />);
await user.click(screen.getByRole("button", { name: "Room Options" }));
await user.click(screen.getByRole("menuitemcheckbox", { name: "Show message previews" }));
expect(vm.toggleMessagePreview).toHaveBeenCalled();
});
});