Files
TREK/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx
T
Maurice 5caa890523 feat(mobile): notification defaults, SSO unlink, wanderer and place names on the phone
- Admin notifications: the defaults every user's cells start as, one row per
  event with a pill per channel cycling On, Off and Blocked
  (MAdminNotificationDefaults); the grid's constants are shared with the
  desktop panel in notificationDefaultsModel.
- Editing a user offers "Remove SSO link" behind a confirm sheet, as on the
  desktop, once SSO is set up and never for yourself.
- Settings: the wanderer connection (MWandererConnectionSection, on
  useWandererConnection) and the language of place names under General.
- MSetCard takes a brand mark as its icon, not only a lucide icon.
2026-11-14 11:14:09 +01:00

58 lines
2.6 KiB
TypeScript

// FE-MOB-ANOTIFDEF-001 to FE-MOB-ANOTIFDEF-003
import { http, HttpResponse } from 'msw';
import { describe, expect, it } from 'vitest';
import MAdminNotificationDefaults from '../../../../src/mobile/screens/admin/MAdminNotificationDefaults';
import { server } from '../../../helpers/msw/server';
import { fireEvent, render, waitFor } from '../../../helpers/render';
const matrix = (defaults: Record<string, Record<string, string>>) => ({
defaults,
channels: [
{ id: 'inapp', labelKey: 'settings.notificationPreferences.inapp', active: true, configured: true },
{ id: 'email', labelKey: 'settings.notificationPreferences.email', active: true, configured: true },
],
event_types: ['trip_invite', 'booking_change'],
implemented_combos: { trip_invite: ['inapp', 'email'], booking_change: ['inapp'] },
});
const cells = () => Array.from(document.querySelectorAll('button[data-state]')) as HTMLElement[];
describe('MAdminNotificationDefaults (#1536)', () => {
it('FE-MOB-ANOTIFDEF-001: one pill per channel an event is sent on, each in its state', async () => {
server.use(
http.get('/api/admin/notification-preferences/defaults', () =>
HttpResponse.json(matrix({ trip_invite: { inapp: 'on', email: 'blocked' }, booking_change: { inapp: 'off' } }))
)
);
render(<MAdminNotificationDefaults />);
await waitFor(() => expect(cells()).toHaveLength(3));
expect(cells().map((b) => b.getAttribute('data-state'))).toEqual(['on', 'blocked', 'off']);
});
it('FE-MOB-ANOTIFDEF-002: a tap cycles the cell to its next state and saves it', async () => {
const sent: unknown[] = [];
server.use(
http.get('/api/admin/notification-preferences/defaults', () =>
HttpResponse.json(matrix({ trip_invite: { inapp: 'on', email: 'on' }, booking_change: { inapp: 'on' } }))
),
http.put('/api/admin/notification-preferences/defaults', async ({ request }) => {
sent.push(await request.json());
return HttpResponse.json(
matrix({ trip_invite: { inapp: 'on', email: 'off' }, booking_change: { inapp: 'on' } })
);
})
);
render(<MAdminNotificationDefaults />);
await waitFor(() => expect(cells()).toHaveLength(3));
fireEvent.click(cells()[1]);
await waitFor(() => expect(sent).toHaveLength(1));
await waitFor(() => expect(cells()[1].getAttribute('data-state')).toBe('off'));
});
it('FE-MOB-ANOTIFDEF-003: nothing is drawn until the defaults are loaded', () => {
server.use(http.get('/api/admin/notification-preferences/defaults', () => new Promise(() => {})));
render(<MAdminNotificationDefaults />);
expect(cells()).toHaveLength(0);
});
});