Remove copy settings links from dynamic settings rows

This commit is contained in:
hazre committed 2026-04-15 19:10:33 +02:00
1 parent fcf44ffdd3
commit bf30f94bf1
7 files changed
+271

No files matched your search

@@ -0,0 +1,5 @@
---
default: patch
---
# Hide copied settings links on dynamic rows
@@ -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: () => <div>Avatar</div>,
}));
vi.mock('jotai', async () => {
const actual = await vi.importActual<typeof import('jotai')>('jotai');
return {
...actual,
useSetAtom: () => vi.fn(),
};
});
vi.mock('./TimezoneEditor', () => ({
TimezoneEditor: () => <div>Timezone</div>,
}));
vi.mock('./PronounEditor', () => ({
PronounEditor: () => <div>Pronouns</div>,
}));
vi.mock('./BioEditor', () => ({
BioEditor: () => <div>Bio</div>,
}));
vi.mock('./NameColorEditor', () => ({
NameColorEditor: () => <div>Name Color</div>,
}));
vi.mock('./StatusEditor', () => ({
StatusEditor: () => <div>Status</div>,
}));
vi.mock('./AnimalCosmetics', () => ({
AnimalCosmetics: () => <div>Animal Cosmetics</div>,
}));
describe('Profile', () => {
it('does not show copy settings links for custom profile fields', () => {
const { container } = render(
<ScreenSizeProvider value={ScreenSize.Desktop}>
<SettingsLinkProvider value={{ section: 'account', baseUrl: 'https://app.example' }}>
<Profile />
</SettingsLinkProvider>
</ScreenSizeProvider>
);
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();
});
});
@@ -658,6 +658,7 @@ function ProfileExtended({ profile, userId }: Readonly<ProfileProps>) {
<SettingTile
key={key}
focusId={`profile-field-${toSettingsFocusIdPart(key)}`}
showSettingLinkAction={false}
title={key.split('.').pop() || key}
description={key}
after={
@@ -0,0 +1,69 @@
import { render, screen, 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 { GlobalPacks } from './GlobalPacks';
const globalPack = {
id: 'pack-1',
meta: {
name: 'Animals',
attribution: 'Cute pack',
},
address: {
roomId: '!room:example',
stateKey: 'pack',
},
deleted: false,
getAvatarUrl: () => 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<typeof import('jotai')>('jotai');
return {
...actual,
useAtomValue: () => [],
};
});
describe('GlobalPacks', () => {
it('does not show copy settings links for individual pack rows', () => {
const { container } = render(
<ScreenSizeProvider value={ScreenSize.Desktop}>
<SettingsLinkProvider value={{ section: 'emojis', baseUrl: 'https://app.example' }}>
<GlobalPacks onViewPack={vi.fn()} />
</SettingsLinkProvider>
</ScreenSizeProvider>
);
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();
});
});
@@ -187,6 +187,7 @@ function GlobalPackSelector({
<SettingTile
title={pack.meta.name ?? 'Unknown'}
focusId={`room-pack-${toSettingsFocusIdPart(pack.id)}`}
showSettingLinkAction={false}
description={<span className={LineClamp2}>{pack.meta.attribution}</span>}
before={
<Box alignItems="Center" gap="300">
@@ -361,6 +362,7 @@ export function GlobalPacks({ onViewPack }: GlobalPacksProps) {
>
<SettingTile
focusId={`selected-pack-${toSettingsFocusIdPart(pack.id)}`}
showSettingLinkAction={false}
title={
<span style={{ textDecoration: removed ? 'line-through' : undefined }}>
{pack.meta.name ?? 'Unknown'}
@@ -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: () => <div>Mode</div>,
}));
vi.mock('./NotificationLevelsHint', () => ({
NotificationLevelsHint: () => <div>Hint</div>,
}));
describe('KeywordMessagesNotifications', () => {
it('does not show copy settings links for individual keyword rows', () => {
const { container } = render(
<ScreenSizeProvider value={ScreenSize.Desktop}>
<SettingsLinkProvider value={{ section: 'notifications', baseUrl: 'https://app.example' }}>
<KeywordMessagesNotifications />
</SettingsLinkProvider>
</ScreenSizeProvider>
);
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();
});
});
@@ -214,6 +214,7 @@ export function KeywordMessagesNotifications() {
focusId={`keyword-${toSettingsFocusIdPart(
pushRule.pattern ?? pushRule.rule_id ?? 'custom-keyword'
)}`}
showSettingLinkAction={false}
before={<KeywordCross pushRule={pushRule} />}
after={<KeywordModeSwitcher pushRule={pushRule} />}
/>