mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
test(settings): follow the redesigned settings and admin pages
The tests now look for what the pages show after the redesign: the admin Settings tab is Security and Services, MCP Access and User Defaults are MCP and Defaults, notification channels and the 2FA rule are rows with a named switch, hints sit behind the info mark, each addon type card counts its own addons, OAuth scopes and the AI sharing note are shown in full, and the 2FA disable password is the field beside the code. The phone's MCP admin header keeps its own title, MCP Access. The mail pill test renders with translations, so it finds From mail rather than the key.
This commit is contained in:
@@ -426,9 +426,10 @@ describe('AddonManager', () => {
|
||||
expect(paperlessRow.querySelector('svg')).toBeInTheDocument();
|
||||
expect(isOn(subToggle('Paperless-ngx'))).toBe(true);
|
||||
expect(isOn(subToggle('Nextcloud'))).toBe(false);
|
||||
// Documents and Journey are the addons; an enabled provider is a shelf row
|
||||
// and must not turn 1/2 into 2/2.
|
||||
expect(screen.getByText('1/2')).toBeInTheDocument();
|
||||
// Documents and Journey are the addons, one per type card; an enabled
|
||||
// provider is a shelf row and must not turn the trip card's 1/1 into 2/2.
|
||||
expect(screen.getByText('1/1')).toBeInTheDocument();
|
||||
expect(screen.getByText('0/1')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-ADMIN-ADDON-034: document providers stay hidden while Documents itself is off', async () => {
|
||||
|
||||
@@ -395,10 +395,11 @@ describe('DefaultUserSettingsTab', () => {
|
||||
render(<DefaultUserSettingsTab />);
|
||||
await screen.findByText('3D buildings & terrain');
|
||||
|
||||
// 3D defaults to on, quality mode to off when neither is stored
|
||||
const threeD = within(screen.getByText('3D buildings & terrain').closest('div') as HTMLElement);
|
||||
// 3D defaults to on, quality mode to off when neither is stored. The row
|
||||
// (label left, control right) holds the On/Off pair.
|
||||
const threeD = within(screen.getByText('3D buildings & terrain').closest('.flex-wrap') as HTMLElement);
|
||||
expect(isActive(threeD.getByRole('button', { name: 'On' }))).toBe(true);
|
||||
const quality = within(screen.getByText('High-quality mode').closest('div') as HTMLElement);
|
||||
const quality = within(screen.getByText('High-quality mode').closest('.flex-wrap') as HTMLElement);
|
||||
expect(isActive(quality.getByRole('button', { name: 'Off' }))).toBe(true);
|
||||
|
||||
await user.click(threeD.getByRole('button', { name: 'Off' }));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// FE-PLANNER-BKPARTS-001 to FE-PLANNER-BKPARTS-006
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { fireEvent, render, screen } from '../../../../tests/helpers/render';
|
||||
|
||||
import { buildReservation, buildTripFile } from '../../../../tests/helpers/factories';
|
||||
import { downloadFile, openFile } from '../../../utils/fileDownload';
|
||||
|
||||
@@ -27,6 +27,13 @@ beforeEach(() => {
|
||||
seedStore(useSettingsStore, { settings: buildSettings() });
|
||||
});
|
||||
|
||||
/** The password field of the 2FA disable panel: the one beside the code field. */
|
||||
function mfaDisablePassword(): HTMLInputElement {
|
||||
const input = screen.getByPlaceholderText('6-digit code').parentElement?.querySelector<HTMLInputElement>('input[type="password"]');
|
||||
if (!input) throw new Error('no password field beside the 2FA code');
|
||||
return input;
|
||||
}
|
||||
|
||||
describe('AccountTab', () => {
|
||||
it('FE-COMP-ACCOUNT-001: renders without crashing', () => {
|
||||
render(<AccountTab />);
|
||||
@@ -374,12 +381,9 @@ describe('AccountTab – MFA', () => {
|
||||
http.get('/api/auth/me', () => HttpResponse.json({ user: buildUser() })),
|
||||
);
|
||||
render(<><ToastContainer /><AccountTab /></>);
|
||||
// When mfa_enabled + !oidcOnlyMode, there are 4 password inputs total:
|
||||
// 3 in Change Password section + 1 in MFA disable section (last one)
|
||||
const passwordInputs = document.querySelectorAll('input[type="password"]');
|
||||
const mfaPasswordInput = passwordInputs[passwordInputs.length - 1] as HTMLInputElement;
|
||||
await user.type(mfaPasswordInput, 'mypassword');
|
||||
// The disable panel asks for the password right beside the code field.
|
||||
const codeInput = screen.getByPlaceholderText('6-digit code');
|
||||
await user.type(mfaDisablePassword(), 'mypassword');
|
||||
await user.type(codeInput, '123456');
|
||||
await user.click(screen.getByRole('button', { name: 'Disable 2FA' }));
|
||||
expect(await screen.findByText('Two-factor authentication disabled')).toBeInTheDocument();
|
||||
@@ -799,8 +803,7 @@ describe('AccountTab – MFA error paths', () => {
|
||||
);
|
||||
render(<><ToastContainer /><AccountTab /></>);
|
||||
|
||||
const passwordInputs = document.querySelectorAll('input[type="password"]');
|
||||
await user.type(passwordInputs[passwordInputs.length - 1], 'mypassword');
|
||||
await user.type(mfaDisablePassword(), 'mypassword');
|
||||
await user.type(screen.getByPlaceholderText('6-digit code'), '123456');
|
||||
await user.click(screen.getByRole('button', { name: 'Disable 2FA' }));
|
||||
|
||||
|
||||
@@ -427,8 +427,7 @@ describe('IntegrationsTab', () => {
|
||||
expect(screen.getByText(/clid-abc/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-INTEGRATIONS-022: scope expansion toggle shows more/fewer scopes', async () => {
|
||||
const user = userEvent.setup();
|
||||
it('FE-COMP-INTEGRATIONS-022: every scope of a client is shown, none folded behind a +N', async () => {
|
||||
const scopes = ['trips:read', 'trips:write', 'places:read', 'places:write', 'budget:read', 'budget:write', 'packing:read'];
|
||||
server.use(
|
||||
http.get('/api/oauth/clients', () =>
|
||||
@@ -442,11 +441,8 @@ describe('IntegrationsTab', () => {
|
||||
enableMcp();
|
||||
render(<IntegrationsTab />);
|
||||
await screen.findByText('Big App');
|
||||
// "+2 more" button visible (7 scopes, 5 shown)
|
||||
const moreBtn = screen.getByText(/^\+\d+$/);
|
||||
await user.click(moreBtn);
|
||||
// Show less / collapse button now visible
|
||||
expect(screen.getByText('−')).toBeInTheDocument();
|
||||
for (const scope of scopes) expect(screen.getByText(scope)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/^\+\d+$/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-INTEGRATIONS-023: active OAuth sessions section renders when sessions exist', async () => {
|
||||
|
||||
@@ -172,10 +172,10 @@ describe('AiConnectPanel', () => {
|
||||
expect(screen.getByRole('button', { name: /Connect OpenRouter/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-AI-CONNECT-PANEL-008: the sharing details fold out', async () => {
|
||||
const user = userEvent.setup();
|
||||
it('FE-COMP-AI-CONNECT-PANEL-008: the sharing details are said in full, not folded behind a button', () => {
|
||||
render(<AiConnectPanel scope="user" onConnected={vi.fn()} />);
|
||||
await user.click(screen.getByRole('button', { name: /What gets shared\?/ }));
|
||||
expect(screen.getByText('What gets shared?')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: /What gets shared\?/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Not your password, your files or your other trips.')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
@@ -169,7 +169,8 @@ describe('AdminPage', () => {
|
||||
// Other tabs
|
||||
expect(screen.getByRole('button', { name: /personalization/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /addons/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /settings/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /^security$/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /^services$/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -359,7 +360,7 @@ describe('AdminPage', () => {
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
|
||||
expect(screen.queryByRole('button', { name: /mcp access/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: /^mcp$/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows MCP Tokens tab button when MCP addon is enabled', async () => {
|
||||
@@ -375,7 +376,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('button', { name: /mcp access/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /^mcp$/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -395,7 +396,7 @@ describe('AdminPage', () => {
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
const heading = await screen.findByRole('heading', { name: /authentication methods/i });
|
||||
const card = heading.closest<HTMLElement>('section');
|
||||
@@ -512,12 +513,12 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
const mfaHeading = await screen.findByRole('heading', { name: /require two-factor/i });
|
||||
const mfaCard = mfaHeading.closest<HTMLElement>('section');
|
||||
const mfaToggle = within(mfaCard!).getByRole('button');
|
||||
fireEvent.click(mfaToggle);
|
||||
// The 2FA rule is a row of the sign-in card: its label left, its switch right.
|
||||
const mfaLabel = await screen.findByText('Require two-factor authentication (2FA)', { selector: 'label' });
|
||||
const mfaRow = mfaLabel.closest<HTMLElement>('.flex-wrap');
|
||||
fireEvent.click(within(mfaRow!).getByRole('button'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(capturedBody).toEqual(expect.objectContaining({ require_mfa: true }));
|
||||
@@ -551,7 +552,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
await screen.findByText('Transit Provider');
|
||||
await waitFor(() => expect(transitTrigger()).toHaveTextContent('Transitous'));
|
||||
@@ -577,7 +578,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
await screen.findByText('Transit Provider');
|
||||
|
||||
// A real change first, so the counter is proven to move at all.
|
||||
@@ -606,7 +607,7 @@ describe('AdminPage', () => {
|
||||
seedStore(useAuthStore, { isAuthenticated: true, user: buildAdmin() });
|
||||
render(<AdminPage />);
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
await screen.findByText('Transit Provider');
|
||||
await waitFor(() => expect(transitTrigger()).toHaveTextContent('Google'));
|
||||
}
|
||||
@@ -634,7 +635,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
const rotateBtn = await screen.findByRole('button', { name: /^rotate$/i });
|
||||
fireEvent.click(rotateBtn);
|
||||
@@ -805,9 +806,9 @@ describe('AdminPage', () => {
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /^notifications$/i }));
|
||||
|
||||
// AdminNotificationsPanel heading for admin notifications
|
||||
// The admin matrix sits in the admin alerts card, under its targets
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('heading', { name: /^notifications$/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: /^admin alerts$/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -826,9 +827,9 @@ describe('AdminPage', () => {
|
||||
seedStore(useAuthStore, { isAuthenticated: true, user: buildAdmin() });
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /mcp access/i })).toBeInTheDocument());
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^mcp$/i })).toBeInTheDocument());
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /mcp access/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^mcp$/i }));
|
||||
|
||||
expect(screen.getByTestId('mcp-tokens-panel')).toBeInTheDocument();
|
||||
});
|
||||
@@ -881,7 +882,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
// Maps is the first 'Enter key...' input (Unsplash is the second).
|
||||
const keyInput = (await screen.findAllByPlaceholderText('Enter key...'))[0];
|
||||
@@ -912,7 +913,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
// Find the file types input by placeholder
|
||||
const fileTypesInput = await screen.findByPlaceholderText(/jpg,png,pdf/i);
|
||||
@@ -942,7 +943,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
// Wait for OIDC section to appear
|
||||
const oidcHeading = await screen.findByRole('heading', { name: /single sign-on/i });
|
||||
@@ -1089,7 +1090,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
const rotateBtn = await screen.findByRole('button', { name: /^rotate$/i });
|
||||
fireEvent.click(rotateBtn);
|
||||
@@ -1143,7 +1144,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
// Wait for the API Keys section to appear
|
||||
const apiKeysHeading = await screen.findByRole('heading', { name: /^api keys$/i });
|
||||
@@ -1175,7 +1176,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
const apiKeysHeading = await screen.findByRole('heading', { name: /^api keys$/i });
|
||||
const apiKeysCard = apiKeysHeading.closest<HTMLElement>('section');
|
||||
@@ -1209,7 +1210,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
const apiKeysHeading = await screen.findByRole('heading', { name: /^api keys$/i });
|
||||
const apiKeysCard = apiKeysHeading.closest<HTMLElement>('section');
|
||||
@@ -1241,7 +1242,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^services$/i }));
|
||||
|
||||
// Wait for the API Keys section
|
||||
const apiKeysHeading = await screen.findByRole('heading', { name: /^api keys$/i });
|
||||
@@ -1334,7 +1335,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
const rotateBtn = await screen.findByRole('button', { name: /^rotate$/i });
|
||||
fireEvent.click(rotateBtn);
|
||||
@@ -1453,13 +1454,9 @@ describe('AdminPage', () => {
|
||||
// Wait for notifications tab to load
|
||||
await screen.findByPlaceholderText('mail.example.com');
|
||||
|
||||
// Find the webhook panel heading ('Webhook') — exact match to avoid 'Admin Webhook'
|
||||
const webhookHeading = screen.getByRole('heading', { name: /^webhook$/i });
|
||||
// Each channel is a settings card, found as the section around its heading.
|
||||
const webhookCard = webhookHeading.closest<HTMLElement>('section');
|
||||
// Find the toggle button in webhook card
|
||||
const webhookToggle = within(webhookCard!).getByRole('button');
|
||||
fireEvent.click(webhookToggle);
|
||||
// Each channel is a row of the channels card, its switch named after it;
|
||||
// the exact name keeps it apart from the Admin Webhook target.
|
||||
fireEvent.click(screen.getByRole('button', { name: /^webhook$/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(appSettingsCalled).toBe(true);
|
||||
@@ -1536,18 +1533,15 @@ describe('AdminPage', () => {
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /^notifications$/i }));
|
||||
|
||||
// Wait for the AdminNotificationsPanel matrix to appear
|
||||
// The panel heading is t('admin.tabs.notifications') = 'Notifications'
|
||||
// The channel column header is t('settings.notificationPreferences.email') = 'Email' (CSS uppercases it)
|
||||
// Find the AdminNotificationsPanel by its h2 heading role='heading'
|
||||
const matrixHeading = await screen.findByRole('heading', { name: /^notifications$/i });
|
||||
// Wait for the AdminNotificationsPanel matrix to appear. It sits bare in the
|
||||
// admin alerts card (t('admin.notifications.adminAlerts') = 'Admin alerts'),
|
||||
// whose h2 heading finds it.
|
||||
const matrixHeading = await screen.findByRole('heading', { name: /^admin alerts$/i });
|
||||
const matrixCard = matrixHeading.closest<HTMLElement>('section');
|
||||
|
||||
// The matrix toggle button is inside the card (not a checkbox — it's a button toggle)
|
||||
const matrixToggle = matrixCard?.querySelector('button');
|
||||
if (matrixToggle) {
|
||||
fireEvent.click(matrixToggle);
|
||||
}
|
||||
// The matrix switch is named after its event and channel; the card's first
|
||||
// buttons belong to the webhook and ntfy targets above the matrix.
|
||||
fireEvent.click(within(matrixCard!).getByRole('button', { name: /, email$/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(prefUpdateCalled).toBe(true);
|
||||
@@ -1561,7 +1555,7 @@ describe('AdminPage', () => {
|
||||
render(<AdminPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: /^users$/i })).toBeInTheDocument());
|
||||
fireEvent.click(screen.getByRole('button', { name: /settings/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^security$/i }));
|
||||
|
||||
// Wait for the OIDC section — heading is 'Single Sign-On (OIDC)'
|
||||
const oidcHeading = await screen.findByRole('heading', { name: /single sign-on/i });
|
||||
@@ -1792,7 +1786,7 @@ describe('AdminPage', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /^plugins$/i }));
|
||||
expect(screen.getByTestId('plugins-panel')).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /user defaults/i }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^defaults$/i }));
|
||||
expect(screen.getByTestId('default-user-settings')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,6 +42,28 @@ function card(heading: string | RegExp): HTMLElement {
|
||||
return screen.getByRole('heading', { name: heading }).closest<HTMLElement>('section')!;
|
||||
}
|
||||
|
||||
/** The labels of the channels card's switch rows, top to bottom: its first block of rows, not the SMTP section under it. */
|
||||
function channelRows(): string[] {
|
||||
const rows = card('Channels').querySelector('.divide-y');
|
||||
if (!rows) throw new Error('the channels card has no rows');
|
||||
return Array.from(rows.querySelectorAll('label'), l => l.textContent ?? '');
|
||||
}
|
||||
|
||||
/** A channel's row in the channels card (label and hint left, switch right). */
|
||||
function channelRow(label: string): HTMLElement {
|
||||
const row = within(card('Channels'))
|
||||
.getAllByText(label)
|
||||
.find(node => node.tagName === 'LABEL')
|
||||
?.closest<HTMLElement>('.flex-wrap');
|
||||
if (!row) throw new Error(`no channel row for ${label}`);
|
||||
return row;
|
||||
}
|
||||
|
||||
/** A channel's switch: each row's switch carries the channel's name. */
|
||||
function channelSwitch(label: string): HTMLElement {
|
||||
return within(channelRow(label)).getByRole('button', { name: label });
|
||||
}
|
||||
|
||||
const EMAIL_ON: SmtpValues = { notification_channels: 'email', smtp_host: 'mail.example.com' };
|
||||
|
||||
/**
|
||||
@@ -68,11 +90,9 @@ describe('AdminNotificationsTab', () => {
|
||||
it('FE-ADMNOT-001: renders every channel panel plus the preference matrix', () => {
|
||||
renderTab();
|
||||
|
||||
// Every channel is a row of the channels card; the SMTP relay is a section of it.
|
||||
expect(channelRows()).toEqual(['Email (SMTP)', 'Webhook', 'Ntfy', 'Web Push', 'In-App', 'Trip Reminders']);
|
||||
expect(screen.getByRole('heading', { name: 'Email (SMTP)' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: /^webhook$/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Ntfy' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'In-App' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Trip Reminders' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Admin Webhook' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Admin Ntfy' })).toBeInTheDocument();
|
||||
expect(screen.getByTestId('admin-notifications-panel')).toBeInTheDocument();
|
||||
@@ -112,7 +132,7 @@ describe('AdminNotificationsTab', () => {
|
||||
);
|
||||
const admin = renderTab({ smtpValues: { notification_channels: 'webhook' } });
|
||||
|
||||
fireEvent.click(within(card('Email (SMTP)')).getAllByRole('button')[0]);
|
||||
fireEvent.click(channelSwitch('Email (SMTP)'));
|
||||
|
||||
await waitFor(() => expect(body).toEqual({ notification_channels: 'email,webhook' }));
|
||||
expect(replaySmtp(admin.setSmtpValues, 0).notification_channels).toBe('email,webhook');
|
||||
@@ -128,7 +148,7 @@ describe('AdminNotificationsTab', () => {
|
||||
);
|
||||
renderTab({ smtpValues: { notification_channels: 'email' } });
|
||||
|
||||
fireEvent.click(within(card('Email (SMTP)')).getAllByRole('button')[0]);
|
||||
fireEvent.click(channelSwitch('Email (SMTP)'));
|
||||
|
||||
await waitFor(() => expect(body).toEqual({ notification_channels: 'none' }));
|
||||
});
|
||||
@@ -143,7 +163,7 @@ describe('AdminNotificationsTab', () => {
|
||||
);
|
||||
renderTab({ smtpValues: { notification_channels: 'email, plugin-gotify' } });
|
||||
|
||||
fireEvent.click(within(card('Ntfy')).getAllByRole('button')[0]);
|
||||
fireEvent.click(channelSwitch('Ntfy'));
|
||||
|
||||
await waitFor(() => expect(body).toEqual({ notification_channels: 'email,ntfy,plugin-gotify' }));
|
||||
});
|
||||
@@ -152,7 +172,7 @@ describe('AdminNotificationsTab', () => {
|
||||
server.use(http.put('/api/auth/app-settings', () => HttpResponse.json({}, { status: 500 })));
|
||||
const admin = renderTab({ smtpValues: { notification_channels: 'email' } });
|
||||
|
||||
fireEvent.click(within(card(/^webhook$/i)).getAllByRole('button')[0]);
|
||||
fireEvent.click(channelSwitch('Webhook'));
|
||||
|
||||
await waitFor(() => expect(admin.toast.error).toHaveBeenCalledWith('Error'));
|
||||
expect(replaySmtp(admin.setSmtpValues, 0).notification_channels).toBe('email,webhook');
|
||||
@@ -269,7 +289,7 @@ describe('AdminNotificationsTab', () => {
|
||||
);
|
||||
const admin = renderTab({ smtpValues: { notify_trip_reminder: 'false' } });
|
||||
|
||||
fireEvent.click(within(card('Trip Reminders')).getByRole('button'));
|
||||
fireEvent.click(channelSwitch('Trip Reminders'));
|
||||
|
||||
await waitFor(() => expect(body).toEqual({ notify_trip_reminder: 'true' }));
|
||||
expect(admin.toast.success).toHaveBeenCalledWith('Trip reminders enabled');
|
||||
@@ -280,7 +300,7 @@ describe('AdminNotificationsTab', () => {
|
||||
server.use(http.get('/api/auth/app-config', () => HttpResponse.json({})));
|
||||
const admin = renderTab({ smtpValues: {} });
|
||||
|
||||
fireEvent.click(within(card('Trip Reminders')).getByRole('button'));
|
||||
fireEvent.click(channelSwitch('Trip Reminders'));
|
||||
|
||||
await waitFor(() => expect(admin.toast.success).toHaveBeenCalledWith('Trip reminders disabled'));
|
||||
expect(replaySmtp(admin.setSmtpValues, 0).notify_trip_reminder).toBe('false');
|
||||
@@ -290,7 +310,7 @@ describe('AdminNotificationsTab', () => {
|
||||
server.use(http.put('/api/auth/app-settings', () => HttpResponse.json({}, { status: 500 })));
|
||||
const admin = renderTab({ smtpValues: {} });
|
||||
|
||||
fireEvent.click(within(card('Trip Reminders')).getByRole('button'));
|
||||
fireEvent.click(channelSwitch('Trip Reminders'));
|
||||
|
||||
await waitFor(() => expect(admin.toast.error).toHaveBeenCalledWith('Error'));
|
||||
expect(replaySmtp(admin.setSmtpValues, 1).notify_trip_reminder).toBe('true');
|
||||
@@ -565,21 +585,20 @@ describe('AdminNotificationsTab', () => {
|
||||
// single stack there instead of leaving half a grid row empty.
|
||||
renderTab({ managed: true });
|
||||
|
||||
expect(screen.getByRole('heading', { name: /^webhook$/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Trip Reminders' })).toBeInTheDocument();
|
||||
expect(channelRows()).toEqual(['Webhook', 'Ntfy', 'Web Push', 'In-App', 'Trip Reminders']);
|
||||
expect(screen.queryByRole('heading', { name: 'Email (SMTP)' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('heading', { name: 'Admin Webhook' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('heading', { name: 'Admin Ntfy' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-ADMNOT-044: Web Push has its own card after Ntfy, before In-App', () => {
|
||||
it('FE-ADMNOT-044: Web Push has its own row after Ntfy, before In-App', () => {
|
||||
renderTab({ smtpValues: { notification_channels: 'email' } });
|
||||
|
||||
const headings = screen.getAllByRole('heading').map(h => h.textContent);
|
||||
expect(headings.indexOf('Web Push')).toBe(headings.indexOf('Ntfy') + 1);
|
||||
expect(headings.indexOf('In-App')).toBe(headings.indexOf('Web Push') + 1);
|
||||
expect(within(card('Web Push')).getByText(/receive notifications on their phones/)).toBeInTheDocument();
|
||||
expect(within(card('Web Push')).getByRole('button', { name: 'Web Push' })).toHaveAttribute('aria-pressed', 'false');
|
||||
const rows = channelRows();
|
||||
expect(rows.indexOf('Web Push')).toBe(rows.indexOf('Ntfy') + 1);
|
||||
expect(rows.indexOf('In-App')).toBe(rows.indexOf('Web Push') + 1);
|
||||
expect(within(channelRow('Web Push')).getByText(/receive notifications on their phones/)).toBeInTheDocument();
|
||||
expect(channelSwitch('Web Push')).toHaveAttribute('aria-pressed', 'false');
|
||||
});
|
||||
|
||||
it('FE-ADMNOT-045: switching Web Push on adds push to the list and keeps the rest', async () => {
|
||||
@@ -592,7 +611,7 @@ describe('AdminNotificationsTab', () => {
|
||||
);
|
||||
const admin = renderTab({ smtpValues: { notification_channels: 'email,plugin-gotify' } });
|
||||
|
||||
fireEvent.click(within(card('Web Push')).getByRole('button', { name: 'Web Push' }));
|
||||
fireEvent.click(channelSwitch('Web Push'));
|
||||
|
||||
await waitFor(() => expect(body).toEqual({ notification_channels: 'email,push,plugin-gotify' }));
|
||||
expect(replaySmtp(admin.setSmtpValues, 0).notification_channels).toBe('email,push,plugin-gotify');
|
||||
@@ -608,7 +627,7 @@ describe('AdminNotificationsTab', () => {
|
||||
);
|
||||
renderTab({ smtpValues: { notification_channels: 'email,push' } });
|
||||
|
||||
const toggle = within(card('Web Push')).getByRole('button', { name: 'Web Push' });
|
||||
const toggle = channelSwitch('Web Push');
|
||||
expect(toggle).toHaveAttribute('aria-pressed', 'true');
|
||||
fireEvent.click(toggle);
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ describe('AdminSettingsTab', () => {
|
||||
it('FE-ADMSET-016: require-MFA toggle flips the current value', () => {
|
||||
const admin = renderTab({ requireMfa: false });
|
||||
|
||||
fireEvent.click(within(card(/require two-factor/i)).getByRole('button'));
|
||||
fireEvent.click(toggleFor('Require two-factor authentication (2FA)'));
|
||||
|
||||
expect(admin.handleToggleRequireMfa).toHaveBeenCalledWith(true);
|
||||
});
|
||||
@@ -494,7 +494,8 @@ describe('AdminSettingsTab', () => {
|
||||
// A key alone does not put Google behind the search; the server ignores the
|
||||
// switch under another provider, and the row must not promise otherwise.
|
||||
renderTab({ placesGoogleOnly: true, hasMapsKey: true, placesProvider: 'openstreetmap' });
|
||||
const hint = toggleFor('Search with Google only').closest<HTMLElement>('.flex-wrap')!.querySelector('p')!;
|
||||
// The hint sits behind the row's info mark, in the page for a screen reader.
|
||||
const hint = toggleFor('Search with Google only').closest<HTMLElement>('.flex-wrap')!.querySelector('.sr-only')!;
|
||||
expect(hint.textContent).not.toMatch(/Every search and every suggestion goes to Google Places/);
|
||||
expect(hint.textContent).not.toMatch(/Needs a Google Maps API key/);
|
||||
expect(hint.textContent).toMatch(/provider/i);
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('MAdminMcpTokensPanel', () => {
|
||||
it('FE-MOB-MCPTOK-001: renders the section header and both sub-section titles', async () => {
|
||||
renderPanel();
|
||||
|
||||
expect(screen.getByText('MCP')).toBeInTheDocument();
|
||||
expect(screen.getByText('MCP Access')).toBeInTheDocument();
|
||||
expect(screen.getByText('Manage OAuth sessions and API tokens across all users')).toBeInTheDocument();
|
||||
expect(screen.getByText('OAuth Sessions')).toBeInTheDocument();
|
||||
expect(screen.getByText('API Tokens')).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user