Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions playwright/e2e/left-panel/room-list-panel/room-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ test.describe("Room list", () => {
});

test("should render a message preview", { tag: "@screenshot" }, async ({ page, app, user, bot }) => {
const roomListView = getRoomList(page);
await app.settings.openUserSettings("Preferences");
await page.getByRole("switch", { name: "Show message previews" }).click();
await app.closeDialog();

await page.getByRole("button", { name: "Room Options" }).click();
await page.getByRole("menuitemcheckbox", { name: "Show message previews" }).click();
const roomListView = getRoomList(page);

const roomId = await app.client.createRoom({ name: "activity" });

Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we update the test to include the whole settings pane in the screenshot, otherwise this screenshot loses efficacy by adding yet more settings to it

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 0 additions & 12 deletions src/components/viewmodels/roomlist/RoomListHeaderViewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { useMatrixClientContext } from "../../../contexts/MatrixClientContext";
import type { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
import { createRoom, hasCreateRoomRights } from "./utils";
import { type SortOption, useSorter } from "./useSorter";
import { useMessagePreviewToggle } from "./useMessagePreviewToggle";

/**
* Hook to get the active space and its title.
Expand Down Expand Up @@ -127,14 +126,6 @@ export interface RoomListHeaderViewState {
* The currently active sort option.
*/
activeSortOption: SortOption;
/**
* Whether message previews must be shown or not.
*/
shouldShowMessagePreview: boolean;
/**
* A function to turn on/off message previews.
*/
toggleMessagePreview: () => void;
}

/**
Expand All @@ -157,7 +148,6 @@ export function useRoomListHeaderViewModel(): RoomListHeaderViewState {
/* Actions */

const { activeSortOption, sort } = useSorter();
const { shouldShowMessagePreview, toggleMessagePreview } = useMessagePreviewToggle();

const createChatRoom = useCallback((e: Event) => {
defaultDispatcher.fire(Action.CreateChat);
Expand Down Expand Up @@ -230,7 +220,5 @@ export function useRoomListHeaderViewModel(): RoomListHeaderViewState {
openSpaceSettings,
activeSortOption,
sort,
shouldShowMessagePreview,
toggleMessagePreview,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Please see LICENSE files in the repository root for full details.
*/

import { IconButton, Menu, MenuTitle, CheckboxMenuItem, Tooltip, RadioMenuItem } from "@vector-im/compound-web";
import { IconButton, Menu, MenuTitle, Tooltip, RadioMenuItem } from "@vector-im/compound-web";
import React, { type Ref, type JSX, useState, useCallback } from "react";
import FilterIcon from "@vector-im/compound-design-tokens/assets/web/icons/filter";

Expand Down Expand Up @@ -63,12 +63,6 @@ export function RoomListOptionsMenu({ vm }: Props): JSX.Element {
checked={vm.activeSortOption === SortOption.AToZ}
onSelect={onAtoZSelected}
/>
<MenuTitle title={_t("room_list|appearance")} />
<CheckboxMenuItem
label={_t("room_list|show_message_previews")}
onSelect={vm.toggleMessagePreview}
checked={vm.shouldShowMessagePreview}
/>
</Menu>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
};

public render(): React.ReactNode {
const roomListSettings = PreferencesUserSettingsTab.ROOM_LIST_SETTINGS;

const browserTimezoneLabel: string = _t("settings|preferences|default_timezone", {
timezone: TimezoneHandler.shortBrowserTimezone(),
});
Expand All @@ -263,11 +261,11 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
<SpellCheckSection />
</SettingsSubsection>

{roomListSettings.length > 0 && (
<SettingsSubsection heading={_t("settings|preferences|room_list_heading")}>
{this.renderGroup(roomListSettings)}
</SettingsSubsection>
)}
<SettingsSubsection heading={_t("settings|preferences|room_list_heading")}>
{this.renderGroup(PreferencesUserSettingsTab.ROOM_LIST_SETTINGS)}
{/* The settings is on device level where the other room list settings are on account level */}
<SettingsFlag name="RoomList.showMessagePreview" level={SettingLevel.DEVICE} />
</SettingsSubsection>

<SettingsSubsection heading={_t("common|spaces")}>
{this.renderGroup(PreferencesUserSettingsTab.SPACES_SETTINGS, SettingLevel.ACCOUNT)}
Expand Down
3 changes: 1 addition & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,6 @@
"room_list": {
"add_room_label": "Add room",
"add_space_label": "Add space",
"appearance": "Appearance",
"breadcrumbs_empty": "No recently visited rooms",
"breadcrumbs_label": "Recently visited rooms",
"empty": {
Expand Down Expand Up @@ -2152,7 +2151,6 @@
},
"room_options": "Room Options",
"show_less": "Show less",
"show_message_previews": "Show message previews",
"show_n_more": {
"one": "Show %(count)s more",
"other": "Show %(count)s more"
Expand Down Expand Up @@ -2982,6 +2980,7 @@
"show_chat_effects": "Show chat effects (animations when receiving e.g. confetti)",
"show_displayname_changes": "Show display name changes",
"show_join_leave": "Show join/leave messages (invites/removes/bans unaffected)",
"show_message_previews": "Show message previews",
"show_nsfw_content": "Show NSFW content",
"show_read_receipts": "Show read receipts sent by other users",
"show_redaction_placeholder": "Show a placeholder for removed messages",
Expand Down
1 change: 1 addition & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ export const SETTINGS: Settings = {
"RoomList.showMessagePreview": {
supportedLevels: [SettingLevel.DEVICE],
default: false,
displayName: _td("settings|show_message_previews"),
},
"RightPanel.phasesGlobal": {
supportedLevels: [SettingLevel.DEVICE],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";
Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading
Loading