From 2b6151f6788b4e22dca2a7cefb92ebc466c9c998 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 8 Apr 2025 11:59:11 +0100 Subject: [PATCH] make some tests go happy --- src/@types/matrix-js-sdk.d.ts | 2 +- src/@types/media_preview.ts | 7 + src/Linkify.tsx | 2 +- .../tabs/user/MediaPreviewSetting.tsx | 15 +- src/hooks/useMediaVisible.ts | 16 +- src/settings/Settings.tsx | 2 +- src/settings/SettingsStore.ts | 8 +- .../MediaPreviewConfigController.ts | 20 +- .../handlers/AccountSettingsHandler.ts | 1 - .../handlers/RoomAccountSettingsHandler.ts | 1 - .../views/avatars/RoomAvatar-test.tsx | 19 +- .../views/messages/HideActionButton-test.tsx | 21 +- .../views/messages/MImageBody-test.tsx | 19 +- .../views/messages/MVideoBody-test.tsx | 27 +- .../views/rooms/RoomPreviewCard-test.tsx | 10 +- .../PreferencesUserSettingsTab-test.tsx.snap | 605 ++++++++++-------- .../unit-tests/hooks/useMediaVisible-test.tsx | 78 ++- 17 files changed, 505 insertions(+), 348 deletions(-) diff --git a/src/@types/matrix-js-sdk.d.ts b/src/@types/matrix-js-sdk.d.ts index e0b5b32e1b..20bf822bba 100644 --- a/src/@types/matrix-js-sdk.d.ts +++ b/src/@types/matrix-js-sdk.d.ts @@ -14,7 +14,7 @@ import type { EncryptedFile } from "matrix-js-sdk/src/types"; import type { EmptyObject } from "matrix-js-sdk/src/matrix"; import type { DeviceClientInformation } from "../utils/device/types.ts"; import type { UserWidget } from "../utils/WidgetUtils-types.ts"; -import { MediaPreviewConfig } from "./media_preview.ts"; +import { type MediaPreviewConfig } from "./media_preview.ts"; // Extend Matrix JS SDK types via Typescript declaration merging to support unspecced event fields and types diff --git a/src/@types/media_preview.ts b/src/@types/media_preview.ts index e8cacbe81f..291fd77781 100644 --- a/src/@types/media_preview.ts +++ b/src/@types/media_preview.ts @@ -1,3 +1,10 @@ +/* +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. +*/ + export enum MediaPreviewValue { On = "on", Private = "private", diff --git a/src/Linkify.tsx b/src/Linkify.tsx index 6738c624a0..1a695f315e 100644 --- a/src/Linkify.tsx +++ b/src/Linkify.tsx @@ -52,7 +52,7 @@ export const transformTags: NonNullable = { // images" preference is disabled. Future work might expose some UI to reveal them // like standalone image events have. // TODO: Is this a private room? - if (!src || SettingsStore.getValue("mediaPreviewConfig").media_previews !== MediaPreviewValue.On ) { + if (!src || SettingsStore.getValue("mediaPreviewConfig").media_previews !== MediaPreviewValue.On) { return { tagName, attribs: {} }; } diff --git a/src/components/views/settings/tabs/user/MediaPreviewSetting.tsx b/src/components/views/settings/tabs/user/MediaPreviewSetting.tsx index 434693c0db..29c57894ed 100644 --- a/src/components/views/settings/tabs/user/MediaPreviewSetting.tsx +++ b/src/components/views/settings/tabs/user/MediaPreviewSetting.tsx @@ -1,8 +1,15 @@ -import React, { ChangeEventHandler } from "react"; +/* +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, { type ChangeEventHandler, useCallback } from "react"; import { Field, HelpMessage, InlineField, Label, RadioInput, Root } from "@vector-im/compound-web"; + import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch"; -import { useCallback } from "react"; -import { MediaPreviewConfig, MediaPreviewValue } from "../../../../../@types/media_preview"; +import { type MediaPreviewConfig, MediaPreviewValue } from "../../../../../@types/media_preview"; import { _t } from "../../../../../languageHandler"; import { useSettingValue } from "../../../../../hooks/useSettings"; import SettingsStore from "../../../../../settings/SettingsStore"; @@ -15,7 +22,7 @@ export function MediaPreviewAccountSettings() { (c: boolean) => { const newValue = { ...currentMediaPreview, - // N.B. Switch is inverted. "Hide avatars..." + // Switch is inverted. "Hide avatars..." invite_avatars: c ? MediaPreviewValue.Off : MediaPreviewValue.On, } satisfies MediaPreviewConfig; SettingsStore.setValue("mediaPreviewConfig", null, SettingLevel.ACCOUNT, newValue); diff --git a/src/hooks/useMediaVisible.ts b/src/hooks/useMediaVisible.ts index c975e6c9eb..b34f561e6c 100644 --- a/src/hooks/useMediaVisible.ts +++ b/src/hooks/useMediaVisible.ts @@ -6,12 +6,12 @@ Please see LICENSE files in the repository root for full details. */ import { useCallback, useMemo } from "react"; +import { JoinRule } from "matrix-js-sdk/src/matrix"; import { SettingLevel } from "../settings/SettingLevel"; import { useSettingValue } from "./useSettings"; import SettingsStore from "../settings/SettingsStore"; import { useMatrixClientContext } from "../contexts/MatrixClientContext"; -import { JoinRule } from "matrix-js-sdk/src/matrix"; import { MediaPreviewValue } from "../@types/media_preview"; const PRIVATE_JOIN_RULES: JoinRule[] = [JoinRule.Invite, JoinRule.Knock, JoinRule.Restricted]; @@ -36,18 +36,19 @@ export function useMediaVisible(eventId: string, roomId: string): [boolean, (vis ); const roomIsPrivate = useMemo(() => { - const joinRule = client.getRoom(roomId)?.getJoinRule(); + const joinRule = client?.getRoom(roomId)?.getJoinRule(); if (PRIVATE_JOIN_RULES.includes(joinRule as JoinRule)) { return true; - } else { // All other join rules, and unknown will default to hiding. + } else { + // All other join rules, and unknown will default to hiding. return false; } - }, [client, roomId]) - + }, [client, roomId]); + const explicitEventVisiblity = eventVisibility[eventId]; // Always prefer the explicit per-event user preference here. - if (eventVisibility[eventId]) { - return [true, setMediaVisible]; + if (explicitEventVisiblity !== undefined) { + return [explicitEventVisiblity, setMediaVisible]; } else if (mediaPreviewSetting.media_previews === MediaPreviewValue.Off) { return [false, setMediaVisible]; } else if (mediaPreviewSetting.media_previews === MediaPreviewValue.On) { @@ -59,5 +60,4 @@ export function useMediaVisible(eventId: string, roomId: string): [boolean, (vis console.warn("Invalid media visibility setting", mediaPreviewSetting.media_previews); return [false, setMediaVisible]; } - } diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index bd833a1b1e..6799a593e9 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -9,8 +9,8 @@ Please see LICENSE files in the repository root for full details. import React, { type ReactNode } from "react"; import { UNSTABLE_MSC4133_EXTENDED_PROFILES } from "matrix-js-sdk/src/matrix"; -import { MediaPreviewConfig } from "../@types/media_preview.ts"; +import { type MediaPreviewConfig } from "../@types/media_preview.ts"; import { _t, _td, type TranslationKey } from "../languageHandler"; import DeviceIsolationModeController from "./controllers/DeviceIsolationModeController.ts"; import { diff --git a/src/settings/SettingsStore.ts b/src/settings/SettingsStore.ts index 2dbe2db218..44449bf7db 100644 --- a/src/settings/SettingsStore.ts +++ b/src/settings/SettingsStore.ts @@ -374,6 +374,10 @@ export default class SettingsStore { roomId: string | null = null, excludeDefault = false, ): Settings[S]["default"] | undefined { + if (settingName === "mediaPreviewConfig") { + console.log("GET VALUE", SETTINGS[settingName]); + } + // Verify that the setting is actually a setting if (!SETTINGS[settingName]) { throw new Error("Setting '" + settingName + "' does not appear to be a setting."); @@ -382,6 +386,7 @@ export default class SettingsStore { const setting = SETTINGS[settingName]; const levelOrder = getLevelOrder(setting); + return SettingsStore.getValueAt(levelOrder[0], settingName, roomId, false, excludeDefault); } @@ -728,8 +733,9 @@ export default class SettingsStore { const showImages = handler.getValue("showImages", null); const showAvatarsOnInvites = handler.getValue("showAvatarsOnInvites", null); + const AccountHandler = LEVEL_HANDLERS[SettingLevel.ACCOUNT]; if (showImages !== null || showAvatarsOnInvites !== null) { - this.setValue("mediaPreviewConfig", null, SettingLevel.ACCOUNT, { + AccountHandler.setValue("mediaPreviewConfig", null, { invite_avatars: showAvatarsOnInvites === false ? MediaPreviewValue.Off : MediaPreviewValue.On, media_previews: showImages === false ? MediaPreviewValue.Off : MediaPreviewValue.On, }); diff --git a/src/settings/controllers/MediaPreviewConfigController.ts b/src/settings/controllers/MediaPreviewConfigController.ts index 65c5025b2d..1f3bc09376 100644 --- a/src/settings/controllers/MediaPreviewConfigController.ts +++ b/src/settings/controllers/MediaPreviewConfigController.ts @@ -5,11 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com Please see LICENSE files in the repository root for full details. */ -import { ClientEvent, MatrixEvent, type MatrixClient } from "matrix-js-sdk/src/matrix"; -import { AccountDataEvents } from "matrix-js-sdk/src/types"; -import { MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, MediaPreviewConfig, MediaPreviewValue } from "../../@types/media_preview.ts"; +import { ClientEvent, type MatrixEvent, type MatrixClient } from "matrix-js-sdk/src/matrix"; +import { type AccountDataEvents } from "matrix-js-sdk/src/types"; -import { SettingLevel } from "../SettingLevel.ts"; +import { + MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, + type MediaPreviewConfig, + MediaPreviewValue, +} from "../../@types/media_preview.ts"; +import { type SettingLevel } from "../SettingLevel.ts"; import MatrixClientBackedController from "./MatrixClientBackedController.ts"; /** @@ -62,12 +66,6 @@ export default class MediaPreviewConfigController extends MatrixClientBackedCont public getValueOverride(level: SettingLevel, roomId: string | null): MediaPreviewConfig { // TODO: Use SettingLevel? if (roomId) { - console.log( - "MediaPreviewConfigController", - "getValueOverride", - this.getRoomValue(roomId), - this.globalSetting, - ); // Use globals for any undefined setting return { ...this.getRoomValue(roomId), @@ -96,7 +94,7 @@ export default class MediaPreviewConfigController extends MatrixClientBackedCont }); return true; } - await this.client.setAccountDataRaw(MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, newValue); + await this.client.setAccountData(MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, newValue); return true; } diff --git a/src/settings/handlers/AccountSettingsHandler.ts b/src/settings/handlers/AccountSettingsHandler.ts index 51b2d5162b..2207bccea0 100644 --- a/src/settings/handlers/AccountSettingsHandler.ts +++ b/src/settings/handlers/AccountSettingsHandler.ts @@ -70,7 +70,6 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa const val = event.getContent()["enabled"]; this.watchers.notifyUpdate("recent_emoji", null, SettingLevel.ACCOUNT, val); } else if (event.getType() === MEDIA_PREVIEW_ACCOUNT_DATA_TYPE) { - console.log("notifyupdate"); this.watchers.notifyUpdate("mediaPreviewConfig", null, SettingLevel.ROOM_ACCOUNT, event.getContent()); } }; diff --git a/src/settings/handlers/RoomAccountSettingsHandler.ts b/src/settings/handlers/RoomAccountSettingsHandler.ts index 5811033da3..71da890c21 100644 --- a/src/settings/handlers/RoomAccountSettingsHandler.ts +++ b/src/settings/handlers/RoomAccountSettingsHandler.ts @@ -58,7 +58,6 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin } else if (event.getType() === ALLOWED_WIDGETS_EVENT_TYPE) { this.watchers.notifyUpdate("allowedWidgets", roomId, SettingLevel.ROOM_ACCOUNT, event.getContent()); } else if (event.getType() === MEDIA_PREVIEW_ACCOUNT_DATA_TYPE) { - console.log("notifyupdate"); this.watchers.notifyUpdate("mediaPreviewConfig", roomId, SettingLevel.ROOM_ACCOUNT, event.getContent()); } }; diff --git a/test/unit-tests/components/views/avatars/RoomAvatar-test.tsx b/test/unit-tests/components/views/avatars/RoomAvatar-test.tsx index 615e24fa69..98eedb8ffb 100644 --- a/test/unit-tests/components/views/avatars/RoomAvatar-test.tsx +++ b/test/unit-tests/components/views/avatars/RoomAvatar-test.tsx @@ -18,10 +18,11 @@ import { LocalRoom } from "../../../../../src/models/LocalRoom"; import * as AvatarModule from "../../../../../src/Avatar"; import { DirectoryMember } from "../../../../../src/utils/direct-messages"; import SettingsStore from "../../../../../src/settings/SettingsStore"; -import { SettingLevel } from "../../../../../src/settings/SettingLevel"; +import { MediaPreviewValue } from "../../../../../src/@types/media_preview"; describe("RoomAvatar", () => { let client: MatrixClient; + let showAvatarsSetting: MediaPreviewValue = MediaPreviewValue.On; filterConsole( // unrelated for this test @@ -34,6 +35,13 @@ describe("RoomAvatar", () => { jest.spyOn(dmRoomMap, "getUserIdForRoomId"); jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); jest.spyOn(AvatarModule, "defaultAvatarUrlForString"); + const origFn = SettingsStore.getValue; + jest.spyOn(SettingsStore, "getValue").mockImplementation((setting, ...args) => { + if (setting === "mediaPreviewConfig") { + return { invite_avatars: showAvatarsSetting, media_previews: MediaPreviewValue.Off}; + } + return origFn(setting, ...args); + }); }); afterAll(() => { @@ -43,12 +51,6 @@ describe("RoomAvatar", () => { afterEach(() => { mocked(DMRoomMap.shared().getUserIdForRoomId).mockReset(); mocked(AvatarModule.defaultAvatarUrlForString).mockClear(); - SettingsStore.setValue( - "showAvatarsOnInvites", - null, - SettingLevel.ACCOUNT, - SettingsStore.getDefaultValue("showAvatarsOnInvites"), - ); }); it("should render as expected for a Room", () => { @@ -73,7 +75,6 @@ describe("RoomAvatar", () => { expect(render().container).toMatchSnapshot(); }); it("should render an avatar for a room the user is invited to", () => { - SettingsStore.setValue("showAvatarsOnInvites", null, SettingLevel.ACCOUNT, true); const room = new Room("!room:example.com", client, client.getSafeUserId()); jest.spyOn(room, "getMxcAvatarUrl").mockImplementation(() => "mxc://example.com/foobar"); room.name = "test room"; @@ -81,7 +82,7 @@ describe("RoomAvatar", () => { expect(render().container).toMatchSnapshot(); }); it("should not render an invite avatar if the user has disabled it", () => { - SettingsStore.setValue("showAvatarsOnInvites", null, SettingLevel.ACCOUNT, false); + showAvatarsSetting = MediaPreviewValue.Off; const room = new Room("!room:example.com", client, client.getSafeUserId()); room.name = "test room"; room.updateMyMembership("invite"); diff --git a/test/unit-tests/components/views/messages/HideActionButton-test.tsx b/test/unit-tests/components/views/messages/HideActionButton-test.tsx index 57e92b02b8..d702d2dd29 100644 --- a/test/unit-tests/components/views/messages/HideActionButton-test.tsx +++ b/test/unit-tests/components/views/messages/HideActionButton-test.tsx @@ -14,14 +14,15 @@ import { HideActionButton } from "../../../../../src/components/views/messages/H import SettingsStore from "../../../../../src/settings/SettingsStore"; import { SettingLevel } from "../../../../../src/settings/SettingLevel"; import type { Settings } from "../../../../../src/settings/Settings"; +import { MediaPreviewValue } from "../../../../../src/@types/media_preview"; function mockSetting( - showImages: Settings["showImages"]["default"], + mediaPreviews: MediaPreviewValue, showMediaEventIds: Settings["showMediaEventIds"]["default"], ) { jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => { - if (settingName === "showImages") { - return showImages; + if (settingName === "mediaPreviewConfig") { + return { media_previews: mediaPreviews, invite_avatars: MediaPreviewValue.Off }; } else if (settingName === "showMediaEventIds") { return showMediaEventIds; } @@ -29,8 +30,10 @@ function mockSetting( }); } +const EVENT_ID = "$foo:bar"; + const event = new MatrixEvent({ - event_id: "$foo:bar", + event_id: EVENT_ID, room_id: "!room:id", sender: "@user:id", type: "m.room.message", @@ -46,22 +49,22 @@ describe("HideActionButton", () => { jest.restoreAllMocks(); }); it("should show button when event is visible by showMediaEventIds setting", async () => { - mockSetting(false, { "$foo:bar": true }); + mockSetting(MediaPreviewValue.Off, { [EVENT_ID]: true }); render(); expect(screen.getByRole("button")).toBeVisible(); }); - it("should show button when event is visible by showImages setting", async () => { - mockSetting(true, {}); + it("should show button when event is visible by mediaPreviewConfig setting", async () => { + mockSetting(MediaPreviewValue.On, {}); render(); expect(screen.getByRole("button")).toBeVisible(); }); it("should hide button when event is hidden by showMediaEventIds setting", async () => { - jest.spyOn(SettingsStore, "getValue").mockReturnValue({ "$foo:bar": false }); + mockSetting(MediaPreviewValue.Off, { [EVENT_ID]: false }); render(); expect(screen.queryByRole("button")).toBeNull(); }); it("should hide button when event is hidden by showImages setting", async () => { - mockSetting(false, {}); + mockSetting(MediaPreviewValue.Off, {}); render(); expect(screen.queryByRole("button")).toBeNull(); }); diff --git a/test/unit-tests/components/views/messages/MImageBody-test.tsx b/test/unit-tests/components/views/messages/MImageBody-test.tsx index b46ae29f3b..ec01d2ed30 100644 --- a/test/unit-tests/components/views/messages/MImageBody-test.tsx +++ b/test/unit-tests/components/views/messages/MImageBody-test.tsx @@ -24,10 +24,12 @@ import { mockClientMethodsDevice, mockClientMethodsServer, mockClientMethodsUser, + withClientContextRenderOptions, } from "../../../../test-utils"; import { MediaEventHelper } from "../../../../../src/utils/MediaEventHelper"; import SettingsStore from "../../../../../src/settings/SettingsStore"; import { SettingLevel } from "../../../../../src/settings/SettingLevel"; +import { MediaPreviewValue } from "../../../../../src/@types/media_preview"; jest.mock("matrix-encrypt-attachment", () => ({ decryptAttachment: jest.fn(), @@ -42,6 +44,7 @@ describe("", () => { ...mockClientMethodsDevice(deviceId), ...mockClientMethodsCrypto(), getRooms: jest.fn().mockReturnValue([]), + getRoom: jest.fn(), getIgnoredUsers: jest.fn(), getVersions: jest.fn().mockResolvedValue({ unstable_features: { @@ -136,19 +139,17 @@ describe("", () => { describe("with image previews/thumbnails disabled", () => { beforeEach(() => { - act(() => { - SettingsStore.setValue("showImages", null, SettingLevel.DEVICE, false); + const origFn = SettingsStore.getValue; + jest.spyOn(SettingsStore, "getValue").mockImplementation((setting, ...args) => { + if (setting === "mediaPreviewConfig") { + return { invite_avatars: MediaPreviewValue.Off, media_previews: MediaPreviewValue.Off}; + } + return origFn(setting, ...args); }); }); afterEach(() => { act(() => { - SettingsStore.setValue( - "showImages", - null, - SettingLevel.DEVICE, - SettingsStore.getDefaultValue("showImages"), - ); SettingsStore.setValue( "showMediaEventIds", null, @@ -167,6 +168,7 @@ describe("", () => { mxEvent={encryptedMediaEvent} mediaEventHelper={new MediaEventHelper(encryptedMediaEvent)} />, + withClientContextRenderOptions(cli) ); expect(screen.getByText("Show image")).toBeInTheDocument(); @@ -183,6 +185,7 @@ describe("", () => { mxEvent={encryptedMediaEvent} mediaEventHelper={new MediaEventHelper(encryptedMediaEvent)} />, + withClientContextRenderOptions(cli) ); expect(screen.getByText("Show image")).toBeInTheDocument(); diff --git a/test/unit-tests/components/views/messages/MVideoBody-test.tsx b/test/unit-tests/components/views/messages/MVideoBody-test.tsx index dd916e8de0..0170af1bcd 100644 --- a/test/unit-tests/components/views/messages/MVideoBody-test.tsx +++ b/test/unit-tests/components/views/messages/MVideoBody-test.tsx @@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details. */ import React, { act } from "react"; -import { EventType, getHttpUriForMxc, type IContent, MatrixEvent } from "matrix-js-sdk/src/matrix"; +import { EventType, getHttpUriForMxc, type IContent, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix"; import { fireEvent, render, screen, type RenderResult } from "jest-matrix-react"; import fetchMock from "fetch-mock-jest"; @@ -20,11 +20,14 @@ import { mockClientMethodsDevice, mockClientMethodsServer, mockClientMethodsUser, + withClientContextRenderOptions, } from "../../../../test-utils"; import MVideoBody from "../../../../../src/components/views/messages/MVideoBody"; import type { IBodyProps } from "../../../../../src/components/views/messages/IBodyProps"; import { SettingLevel } from "../../../../../src/settings/SettingLevel"; import SettingsStore from "../../../../../src/settings/SettingsStore"; +import { MediaPreviewValue } from "../../../../../src/@types/media_preview"; +import { MockedObject } from "jest-mock"; // Needed so we don't throw an error about failing to decrypt. jest.mock("matrix-encrypt-attachment", () => ({ @@ -36,13 +39,15 @@ describe("MVideoBody", () => { const deviceId = "DEADB33F"; const thumbUrl = "https://server/_matrix/media/v3/download/server/encrypted-poster"; + let cli: MockedObject; beforeEach(() => { - const cli = getMockClientWithEventEmitter({ + cli = getMockClientWithEventEmitter({ ...mockClientMethodsUser(userId), ...mockClientMethodsServer(), ...mockClientMethodsDevice(deviceId), ...mockClientMethodsCrypto(), + getRoom: jest.fn(), getRooms: jest.fn().mockReturnValue([]), getIgnoredUsers: jest.fn(), getVersions: jest.fn().mockResolvedValue({ @@ -99,19 +104,17 @@ describe("MVideoBody", () => { describe("with video previews/thumbnails disabled", () => { beforeEach(() => { - act(() => { - SettingsStore.setValue("showImages", null, SettingLevel.DEVICE, false); + const origFn = SettingsStore.getValue; + jest.spyOn(SettingsStore, "getValue").mockImplementation((setting, ...args) => { + if (setting === "mediaPreviewConfig") { + return { invite_avatars: MediaPreviewValue.Off, media_previews: MediaPreviewValue.Off}; + } + return origFn(setting, ...args); }); }); afterEach(() => { act(() => { - SettingsStore.setValue( - "showImages", - null, - SettingLevel.DEVICE, - SettingsStore.getDefaultValue("showImages"), - ); SettingsStore.setValue( "showMediaEventIds", null, @@ -119,6 +122,7 @@ describe("MVideoBody", () => { SettingsStore.getDefaultValue("showMediaEventIds"), ); }); + jest.restoreAllMocks(); }); it("should not download video", async () => { @@ -129,6 +133,7 @@ describe("MVideoBody", () => { mxEvent={encryptedMediaEvent} mediaEventHelper={new MediaEventHelper(encryptedMediaEvent)} />, + withClientContextRenderOptions(cli) ); expect(screen.getByText("Show video")).toBeInTheDocument(); @@ -144,6 +149,7 @@ describe("MVideoBody", () => { mxEvent={encryptedMediaEvent} mediaEventHelper={new MediaEventHelper(encryptedMediaEvent)} />, + withClientContextRenderOptions(cli) ); const placeholderButton = screen.getByRole("button", { name: "Show video" }); @@ -191,6 +197,7 @@ function makeMVideoBody(w: number, h: number): RenderResult { const mockClient = getMockClientWithEventEmitter({ mxcUrlToHttp: jest.fn(), + getRoom: jest.fn(), }); return render( diff --git a/test/unit-tests/components/views/rooms/RoomPreviewCard-test.tsx b/test/unit-tests/components/views/rooms/RoomPreviewCard-test.tsx index 375366e8f9..cabe4c4723 100644 --- a/test/unit-tests/components/views/rooms/RoomPreviewCard-test.tsx +++ b/test/unit-tests/components/views/rooms/RoomPreviewCard-test.tsx @@ -44,9 +44,13 @@ describe("RoomPreviewCard", () => { client.reEmitter.reEmit(room, [RoomStateEvent.Events]); enabledFeatures = []; - jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName): any => - enabledFeatures.includes(settingName) ? true : undefined, - ); + const origFn = SettingsStore.getValue; + jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName): any => { + if (enabledFeatures.includes(settingName)) { + return true; + } + return origFn(settingName); + }); }); afterEach(() => { diff --git a/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap b/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap index 34d89172df..a68ddd8ac5 100644 --- a/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap +++ b/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap @@ -95,33 +95,6 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` /> -
- -
-
-
-
+
+ +
- - Always show message timestamps - - -
-
-
-
-
-
+
+ +
- Enable Emoji suggestions while typing + Use Ctrl + Enter to send a message
- Use Ctrl + Enter to send a message + Surround selected text when typing special characters
- Surround selected text when typing special characters + Show stickers button
- - Show stickers button - - -
-
-
-
-
-
+
+ +
- - Expand code blocks by default - - -
-
-
-
-
-
+
+ +
- - Autoplay GIFs - - -
-
-
-
-
-
-
- -
@@ -903,7 +849,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` >
+
+ +
+
+
+
+
+ +
- Show a placeholder for removed messages + Show join/leave messages (invites/removes/bans unaffected)
- Show read receipts sent by other users + Show display name changes
- Show join/leave messages (invites/removes/bans unaffected) + Show chat effects (animations when receiving e.g. confetti)
- Show display name changes + Show profile picture changes
- Show chat effects (animations when receiving e.g. confetti) + Show avatars in user, room and event mentions
- Show profile picture changes + Enable big emoji in chat
- Show avatars in user, room and event mentions + Jump to the bottom of the timeline when you send a message
- Enable big emoji in chat + Show current profile picture and name for users in message history
-
+
+
+
+

-

+
+
+
- Jump to the bottom of the timeline when you send a message +
+ Hide avatars of room and inviter +
- -
+ aria-checked="false" + aria-disabled="false" + aria-labelledby="mx_LabelledToggleSwitch_dJJz3lHUv9XX" + class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled" + role="switch" + tabindex="0" + > +
+
-
-
- -
+ class="_inline-field_19upo_32" + > +
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
-
+