From bf30f94bf1ea9b69ac74bfcf114c1b3135ecaf55 Mon Sep 17 00:00:00 2001 From: hazre Date: Wed, 15 Apr 2026 19:10:33 +0200 Subject: [PATCH] Remove copy settings links from dynamic settings rows --- .changeset/remove-dynamic-settings-links.md | 5 + .../settings/account/Profile.test.tsx | 122 ++++++++++++++++++ src/app/features/settings/account/Profile.tsx | 1 + .../emojis-stickers/GlobalPacks.test.tsx | 69 ++++++++++ .../settings/emojis-stickers/GlobalPacks.tsx | 2 + .../notifications/KeywordMessages.test.tsx | 71 ++++++++++ .../notifications/KeywordMessages.tsx | 1 + 7 files changed, 271 insertions(+) create mode 100644 .changeset/remove-dynamic-settings-links.md create mode 100644 src/app/features/settings/account/Profile.test.tsx create mode 100644 src/app/features/settings/emojis-stickers/GlobalPacks.test.tsx create mode 100644 src/app/features/settings/notifications/KeywordMessages.test.tsx diff --git a/.changeset/remove-dynamic-settings-links.md b/.changeset/remove-dynamic-settings-links.md new file mode 100644 index 000000000..93a2d76e5 --- /dev/null +++ b/.changeset/remove-dynamic-settings-links.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Hide copied settings links on dynamic rows diff --git a/src/app/features/settings/account/Profile.test.tsx b/src/app/features/settings/account/Profile.test.tsx new file mode 100644 index 000000000..e58495b8e --- /dev/null +++ b/src/app/features/settings/account/Profile.test.tsx @@ -0,0 +1,122 @@ +import { render, within } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; +import { ScreenSize, ScreenSizeProvider } from '$hooks/useScreenSize'; +import { SettingsLinkProvider } from '$features/settings/SettingsLinkContext'; +import { Profile } from './Profile'; + +const mockMatrixClient = { + getUserId: () => '@alice:example.org', + setAvatarUrl: vi.fn(), + setDisplayName: vi.fn(), + setExtendedProfileProperty: vi.fn(), + setPresence: vi.fn(), +}; + +vi.mock('$hooks/useMatrixClient', () => ({ + useMatrixClient: () => mockMatrixClient, +})); + +vi.mock('$hooks/useUserProfile', () => ({ + useUserProfile: () => ({ + displayName: 'Alice', + extended: { + 'example.favorite': 'Blue', + }, + }), +})); + +vi.mock('$hooks/useMediaAuthentication', () => ({ + useMediaAuthentication: () => false, +})); + +vi.mock('$hooks/useCapabilities', () => ({ + useCapabilities: () => ({}), +})); + +vi.mock('$hooks/useUserPresence', () => ({ + useUserPresence: () => undefined, +})); + +vi.mock('$hooks/useFilePicker', () => ({ + useFilePicker: () => vi.fn(), +})); + +vi.mock('$hooks/useObjectURL', () => ({ + useObjectURL: () => undefined, +})); + +vi.mock('$hooks/useAsyncCallback', () => ({ + AsyncStatus: { + Idle: 'idle', + Loading: 'loading', + Success: 'success', + Error: 'error', + }, + useAsyncCallback: (callback: (...args: unknown[]) => unknown) => [ + { status: 'idle' }, + callback, + vi.fn(), + ], +})); + +vi.mock('$components/user-avatar', () => ({ + UserAvatar: () =>
Avatar
, +})); + +vi.mock('jotai', async () => { + const actual = await vi.importActual('jotai'); + return { + ...actual, + useSetAtom: () => vi.fn(), + }; +}); + +vi.mock('./TimezoneEditor', () => ({ + TimezoneEditor: () =>
Timezone
, +})); + +vi.mock('./PronounEditor', () => ({ + PronounEditor: () =>
Pronouns
, +})); + +vi.mock('./BioEditor', () => ({ + BioEditor: () =>
Bio
, +})); + +vi.mock('./NameColorEditor', () => ({ + NameColorEditor: () =>
Name Color
, +})); + +vi.mock('./StatusEditor', () => ({ + StatusEditor: () =>
Status
, +})); + +vi.mock('./AnimalCosmetics', () => ({ + AnimalCosmetics: () =>
Animal Cosmetics
, +})); + +describe('Profile', () => { + it('does not show copy settings links for custom profile fields', () => { + const { container } = render( + + + + + + ); + + const displayNameTile = container.querySelector('[data-settings-focus="display-name"]'); + expect(displayNameTile).not.toBeNull(); + expect( + within(displayNameTile as HTMLElement).getByRole('button', { name: /copy settings link/i }) + ).toBeInTheDocument(); + + const customFieldTile = container.querySelector( + '[data-settings-focus="profile-field-example-favorite"]' + ); + expect(customFieldTile).not.toBeNull(); + expect( + within(customFieldTile as HTMLElement).queryByRole('button', { name: /copy settings link/i }) + ).not.toBeInTheDocument(); + }); +}); diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index da2d140f6..8ee4d9b35 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -658,6 +658,7 @@ function ProfileExtended({ profile, userId }: Readonly) { undefined, +} as never; + +vi.mock('$hooks/useImagePacks', () => ({ + useGlobalImagePacks: () => [globalPack], + useRoomsImagePacks: () => [], +})); + +vi.mock('$hooks/useMediaAuthentication', () => ({ + useMediaAuthentication: () => false, +})); + +vi.mock('$hooks/useMatrixClient', () => ({ + useMatrixClient: () => ({ + getRoom: () => undefined, + getAccountData: () => undefined, + setAccountData: vi.fn(), + }), +})); + +vi.mock('jotai', async () => { + const actual = await vi.importActual('jotai'); + return { + ...actual, + useAtomValue: () => [], + }; +}); + +describe('GlobalPacks', () => { + it('does not show copy settings links for individual pack rows', () => { + const { container } = render( + + + + + + ); + + const selectorTile = container.querySelector('[data-settings-focus="select-pack"]'); + expect(selectorTile).not.toBeNull(); + expect( + within(selectorTile as HTMLElement).getByRole('button', { name: /copy settings link/i }) + ).toBeInTheDocument(); + + const packTile = container.querySelector('[data-settings-focus="selected-pack-pack-1"]'); + expect(packTile).not.toBeNull(); + expect(screen.getByText('Animals')).toBeInTheDocument(); + expect( + within(packTile as HTMLElement).queryByRole('button', { name: /copy settings link/i }) + ).not.toBeInTheDocument(); + }); +}); diff --git a/src/app/features/settings/emojis-stickers/GlobalPacks.tsx b/src/app/features/settings/emojis-stickers/GlobalPacks.tsx index 224ed4934..622c12927 100644 --- a/src/app/features/settings/emojis-stickers/GlobalPacks.tsx +++ b/src/app/features/settings/emojis-stickers/GlobalPacks.tsx @@ -187,6 +187,7 @@ function GlobalPackSelector({ {pack.meta.attribution}} before={ @@ -361,6 +362,7 @@ export function GlobalPacks({ onViewPack }: GlobalPacksProps) { > {pack.meta.name ?? 'Unknown'} diff --git a/src/app/features/settings/notifications/KeywordMessages.test.tsx b/src/app/features/settings/notifications/KeywordMessages.test.tsx new file mode 100644 index 000000000..dde430909 --- /dev/null +++ b/src/app/features/settings/notifications/KeywordMessages.test.tsx @@ -0,0 +1,71 @@ +import { render, within } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; +import { ScreenSize, ScreenSizeProvider } from '$hooks/useScreenSize'; +import { SettingsLinkProvider } from '$features/settings/SettingsLinkContext'; +import { KeywordMessagesNotifications } from './KeywordMessages'; + +vi.mock('$hooks/useAccountData', () => ({ + useAccountData: () => ({ + getContent: () => ({ + global: { + content: [ + { + rule_id: 'kitty', + pattern: 'kitty', + default: false, + actions: [], + }, + ], + }, + }), + }), +})); + +vi.mock('$hooks/useMatrixClient', () => ({ + useMatrixClient: () => ({ + addPushRule: vi.fn(), + deletePushRule: vi.fn(), + setPushRuleActions: vi.fn(), + }), +})); + +vi.mock('$hooks/useNotificationMode', () => ({ + NotificationMode: { + Notify: 'notify', + }, + getNotificationModeActions: () => [], + useNotificationActionsMode: () => 'notify', + useNotificationModeActions: () => () => [], +})); + +vi.mock('$components/setting-menu-selector', () => ({ + SettingMenuSelector: () =>
Mode
, +})); + +vi.mock('./NotificationLevelsHint', () => ({ + NotificationLevelsHint: () =>
Hint
, +})); + +describe('KeywordMessagesNotifications', () => { + it('does not show copy settings links for individual keyword rows', () => { + const { container } = render( + + + + + + ); + + const selectorTile = container.querySelector('[data-settings-focus="select-keyword"]'); + expect(selectorTile).not.toBeNull(); + expect( + within(selectorTile as HTMLElement).getByRole('button', { name: /copy settings link/i }) + ).toBeInTheDocument(); + + const keywordTile = container.querySelector('[data-settings-focus="keyword-kitty"]'); + expect(keywordTile).not.toBeNull(); + expect( + within(keywordTile as HTMLElement).queryByRole('button', { name: /copy settings link/i }) + ).not.toBeInTheDocument(); + }); +}); diff --git a/src/app/features/settings/notifications/KeywordMessages.tsx b/src/app/features/settings/notifications/KeywordMessages.tsx index 7eab66eb7..39de1e238 100644 --- a/src/app/features/settings/notifications/KeywordMessages.tsx +++ b/src/app/features/settings/notifications/KeywordMessages.tsx @@ -214,6 +214,7 @@ export function KeywordMessagesNotifications() { focusId={`keyword-${toSettingsFocusIdPart( pushRule.pattern ?? pushRule.rule_id ?? 'custom-keyword' )}`} + showSettingLinkAction={false} before={} after={} />