diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index c17d67368..ce7770fc5 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -57,6 +57,21 @@ "desktop": ["src/pages/admin/AdminSettingsTab.tsx"], "mobile": ["src/mobile/screens/admin/MAdminSettingsSection.tsx"] }, + { + "feature": "Wanderer connection", + "hooks": ["src/components/Settings/useWandererConnection.ts"], + "desktop": ["src/components/Settings/WandererConnectionSection.tsx"], + "mobile": ["src/mobile/screens/settings/MWandererConnectionSection.tsx"] + }, + { + "feature": "Admin notification defaults", + "hooks": [ + "src/pages/admin/useNotificationDefaults.ts", + "src/pages/admin/notificationDefaultsModel.ts" + ], + "desktop": ["src/pages/admin/AdminNotificationDefaultsPanel.tsx"], + "mobile": ["src/mobile/screens/admin/MAdminNotificationDefaults.tsx"] + }, { "feature": "Admin Google daily limit", "hooks": ["src/components/Admin/useGoogleQuota.ts"], diff --git a/client/src/mobile/screens/admin/MAdminNotificationDefaults.tsx b/client/src/mobile/screens/admin/MAdminNotificationDefaults.tsx new file mode 100644 index 000000000..95b15cc61 --- /dev/null +++ b/client/src/mobile/screens/admin/MAdminNotificationDefaults.tsx @@ -0,0 +1,86 @@ +import type { NotificationDefault } from '@trek/shared'; +import { EVENT_LABEL_KEYS, channelLabel } from '../../../components/Settings/notificationLabels'; +import { useTranslation } from '../../../i18n'; +import { + DEFAULT_ICON, + DEFAULT_LABEL_KEYS, + NEXT_DEFAULT, + defaultChannels, + defaultOf, +} from '../../../pages/admin/notificationDefaultsModel'; +import { useNotificationDefaults } from '../../../pages/admin/useNotificationDefaults'; +import { MAdminCard, MAdminCardHead } from './MAdminUi'; + +const TONE: Record = { + on: 'border-transparent bg-m-act text-m-actfg', + off: 'border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-m-muted', + blocked: + 'border-transparent bg-[color:color-mix(in_srgb,var(--m-st-danger)_14%,transparent)] text-[color:var(--m-st-danger)]', +}; + +/** + * What every user's notification cells start as (#1536), the phone's form of the + * desktop grid: one row per event with a pill per channel, each tap cycling + * On → Off → Blocked. Off is a default a user may still turn on, Blocked is off + * for everyone and locked in their settings. + */ +export default function MAdminNotificationDefaults() { + const { t } = useTranslation(); + const { matrix, saving, cycle } = useNotificationDefaults(); + if (!matrix) return null; + const channels = defaultChannels(matrix); + + return ( + + + {/* The key to the pills below, in the same three looks. */} +
+ {(['on', 'off', 'blocked'] as const).map((state) => { + const Icon = DEFAULT_ICON[state]; + return ( + + + {t(DEFAULT_LABEL_KEYS[state])} + + ); + })} +
+
+ {matrix.event_types.map((eventType) => { + const implemented = matrix.implemented_combos[eventType] ?? []; + const eventLabel = t(EVENT_LABEL_KEYS[eventType]) || eventType; + return ( +
+
{eventLabel}
+
+ {channels + .filter((ch) => implemented.includes(ch.id)) + .map((ch) => { + const state = defaultOf(matrix, eventType, ch.id); + const Icon = DEFAULT_ICON[state]; + return ( + + ); + })} +
+
+ ); + })} +
+
+ ); +} diff --git a/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx b/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx index 003b54b53..bfa99c61b 100644 --- a/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx +++ b/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx @@ -4,6 +4,7 @@ import { SWITCH_ONLY_CHANNELS, useNotificationChannels } from '../../../componen import { useAdminNotificationSettings } from '../../../components/Admin/useAdminNotificationSettings' import MToggle from '../../components/MToggle' import MAdminNotifyMatrix from './MAdminNotifyMatrix' +import MAdminNotificationDefaults from './MAdminNotificationDefaults' import { MAdminButton, MAdminCard, MAdminCardHead, MAdminField, MAdminInput, MAdminRow } from './MAdminUi' interface MAdminNotificationsSectionProps { @@ -204,6 +205,8 @@ export default function MAdminNotificationsSection({ admin, t }: MAdminNotificat + {/* What each user's cells start as, below the admin's own channels as on the desktop tab. */} + ) } diff --git a/client/src/mobile/screens/admin/MAdminSheets.tsx b/client/src/mobile/screens/admin/MAdminSheets.tsx index 4d4f1ca13..2ebdf00f0 100644 --- a/client/src/mobile/screens/admin/MAdminSheets.tsx +++ b/client/src/mobile/screens/admin/MAdminSheets.tsx @@ -1,11 +1,12 @@ import { useState } from 'react' -import { AlertTriangle, CheckCircle, ExternalLink, Fingerprint, ShieldOff, Trash2, UserPlus, UserCog, Download, KeyRound, RotateCcw } from 'lucide-react' +import { AlertTriangle, CheckCircle, ExternalLink, Fingerprint, ShieldOff, Trash2, Unlink, UserPlus, UserCog, Download, KeyRound, RotateCcw } from 'lucide-react' import { useAdminUserActions } from '../../../components/Admin/useAdminUserActions' import type { TranslationFn } from '../../../types' import type { useAdmin } from '../../../pages/admin/useAdmin' import MSheet from '../../components/MSheet' import MSegmented from '../../components/MSegmented' import MAdminResetMfaSheet from './MAdminResetMfaSheet' +import MConfirmSheet from '../settings/MConfirmSheet' import { MAdminButton, MAdminField, MAdminInput, MAdminSecretInput, MAdminSheetFrame } from './MAdminUi' import { NO_AUTOFILL } from '../../../utils/noAutofill' @@ -33,6 +34,7 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) { updateInfo, showUpdateModal, setShowUpdateModal, showRotateJwtModal, setShowRotateJwtModal, rotatingJwt, handleCreateUser, handleSaveUser, handleDeleteUser, + oidcConfigured, } = admin const roleOptions = [ @@ -43,6 +45,7 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) { const [showResetPasskeys, setShowResetPasskeys] = useState(false) const [resettingPk, setResettingPk] = useState(false) const [showResetMfa, setShowResetMfa] = useState(false) + const [showUnlinkSso, setShowUnlinkSso] = useState(false) const userActions = useAdminUserActions(admin, t) const { rotateJwt } = userActions @@ -176,6 +179,13 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) { {t('admin.mfa.reset')} )} + {/* Unlinking single sign-on, as on the desktop: only once SSO is set up, and never for yourself. */} + {oidcConfigured && editingUser.id !== currentUser?.id && ( + setShowUnlinkSso(true)}> + + {t('admin.sso.unlink')} + + )} + {/* Unlink single sign-on confirm */} + setShowUnlinkSso(false)} + title={t('admin.sso.unlink')} + message={`${t('admin.sso.unlinkHint')} ${t('admin.sso.unlinkConfirm', { name: editingUser?.username ?? '' })}`} + confirmLabel={t('admin.sso.unlink')} + cancelLabel={t('common.cancel')} + danger + onConfirm={() => { + setShowUnlinkSso(false) + if (editingUser) void userActions.unlinkSso(editingUser) + }} + /> + {/* Reset two-factor confirm */} setLangOpen(true)} /> + {/* Place names (#1799): searches can answer in another language than the app. */} +
+ +
+ l.value === settings.place_language)?.label ?? t('settings.placeLanguageApp')} + trailing={chevron} + onClick={() => setPlaceLangOpen(true)} + /> + {t('settings.temperature')} + setPlaceLangOpen(false)} + title={t('settings.placeLanguage')} + value={settings.place_language || ''} + onSelect={(v) => save('place_language', v)} + options={[ + { value: '', label: t('settings.placeLanguageApp') }, + ...SUPPORTED_LANGUAGES.map((l) => ({ value: l.value, label: l.label })), + ]} + /> setLangOpen(false)} diff --git a/client/src/mobile/screens/settings/MSettingsIntegrations.tsx b/client/src/mobile/screens/settings/MSettingsIntegrations.tsx index c933d6a28..5923948f3 100644 --- a/client/src/mobile/screens/settings/MSettingsIntegrations.tsx +++ b/client/src/mobile/screens/settings/MSettingsIntegrations.tsx @@ -2,6 +2,7 @@ import MPhotoProvidersSection from './MPhotoProvidersSection' import MAirTrailConnectionSection from './MAirTrailConnectionSection' import MMailImportSection from './MMailImportSection' import MDawarichConnectionSection from './MDawarichConnectionSection' +import MWandererConnectionSection from './MWandererConnectionSection' import MLlmConnectionSection from './MLlmConnectionSection' import MAiConnectionSection from './MAiConnectionSection' import MSettingsMcp from './MSettingsMcp' @@ -14,7 +15,7 @@ import { useIntegrationGates } from '../../../components/Settings/useIntegration * function audit is rebuilt natively in the mobile design language. */ export default function MSettingsIntegrations() { - const { mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, aiConnectionEnabled, ownParsing, dawarichEnabled, managed } = useIntegrationGates({ reloadAddons: true }) + const { mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, aiConnectionEnabled, ownParsing, dawarichEnabled, wandererEnabled, managed } = useIntegrationGates({ reloadAddons: true }) return ( <> @@ -26,6 +27,7 @@ export default function MSettingsIntegrations() { {!managed && } {airtrailEnabled && !managed && } {dawarichEnabled && !managed && } + {wandererEnabled && !managed && } {aiConnectionEnabled && !managed && } {/* Which model reads a booking, and what that costs, comes with the instance on a managed install. The per-user fallback exists for people who supply their diff --git a/client/src/mobile/screens/settings/MSettingsUi.tsx b/client/src/mobile/screens/settings/MSettingsUi.tsx index b8b2c8798..4dbdd2d61 100644 --- a/client/src/mobile/screens/settings/MSettingsUi.tsx +++ b/client/src/mobile/screens/settings/MSettingsUi.tsx @@ -1,5 +1,4 @@ -import React, { ReactNode } from 'react' -import type { LucideIcon } from 'lucide-react' +import React, { ComponentType, ReactNode } from 'react' import MHintLabel from '../../components/MHintLabel' /** @@ -10,7 +9,8 @@ import MHintLabel from '../../components/MHintLabel' interface MSetCardProps { title: string - icon: LucideIcon + /** A lucide icon or a brand mark drawn the same way (WandererMark). */ + icon: ComponentType<{ size?: number; strokeWidth?: number; className?: string }> badge?: ReactNode className?: string children: ReactNode diff --git a/client/src/mobile/screens/settings/MWandererConnectionSection.tsx b/client/src/mobile/screens/settings/MWandererConnectionSection.tsx new file mode 100644 index 000000000..22ef39ef5 --- /dev/null +++ b/client/src/mobile/screens/settings/MWandererConnectionSection.tsx @@ -0,0 +1,112 @@ +import { Loader2, Plug, Save, Unplug } from 'lucide-react'; +import { useWandererConnection } from '../../../components/Settings/useWandererConnection'; +import WandererWatchRow from '../../../components/Settings/WandererWatchRow'; +import WandererMark from '../../../components/Tours/wanderer/WandererMark'; +import { useTranslation } from '../../../i18n'; +import MToggle from '../../components/MToggle'; +import { MSetButton, MSetCard, MSetHint, MSetInput, MSetRow } from './MSettingsUi'; + +/** + * Phone twin of components/Settings/WandererConnectionSection: the reader's own + * wanderer trail database, from which Tours imports trails. Presentation only; + * saving, testing and disconnecting live in `useWandererConnection`, and the + * background check of the imported trails is the shared WandererWatchRow. + */ +export default function MWandererConnectionSection() { + const { t } = useTranslation(); + const S = useWandererConnection(); + const probe = S.probe ?? (S.lastCheck ? { ok: false, message: S.lastCheck } : null); + + return ( + + {S.connected ? t('wanderer.connected') : t('wanderer.notConnected')} + + } + > + {t('wanderer.intro')} + +
+ S.setUrl(event.target.value)} + /> +
+ S.setToken(event.target.value)} + /> + {S.tokenInvalid ? ( + {t('wanderer.tokenInvalid')} + ) : ( + {t('wanderer.tokenHint')} + )} +
+
+ + + } + /> + +
+ void S.save()}> + {t('common.save')} + + void S.test()} + > + {S.testing ? : } + {t('wanderer.test.button')} + + {S.connected && ( + void S.disconnect()}> + {t('wanderer.disconnect')} + + )} +
+ + {probe && ( +

+ {probe.message} +

+ )} + +
+ +
+
+ ); +} diff --git a/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx b/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx index 274318106..55599dff3 100644 --- a/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx +++ b/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx @@ -1,4 +1,4 @@ -import { Check, Lock, Minus, UsersRound } from 'lucide-react' +import { UsersRound } from 'lucide-react' import type { NotificationDefault } from '@trek/shared' import { useTranslation } from '../../i18n' import { Tooltip } from '../../components/shared/Tooltip' @@ -6,19 +6,13 @@ import { SettingsCard } from '../../components/Settings/settingsKit' import { fs } from '../../components/shared/DialogShell' import { EVENT_LABEL_KEYS, channelLabel } from '../../components/Settings/notificationLabels' import { useNotificationDefaults } from './useNotificationDefaults' +import { DEFAULT_ICON as ICON, DEFAULT_LABEL_KEYS as LABEL_KEYS, NEXT_DEFAULT as NEXT, defaultChannels, defaultOf } from './notificationDefaultsModel' -const NEXT: Record = { on: 'off', off: 'blocked', blocked: 'on' } -const ICON = { on: Check, off: Minus, blocked: Lock } as const const TONE: Record = { on: 'bg-accent text-accent-text border-transparent', off: 'bg-surface-card text-content-muted border-edge', blocked: 'bg-danger-soft text-danger border-transparent', } -const LABEL_KEYS: Record = { - on: 'admin.notificationDefaults.on', - off: 'admin.notificationDefaults.off', - blocked: 'admin.notificationDefaults.blocked', -} /** * What every user's notification cells start as (#1536). One cell per event and @@ -30,7 +24,7 @@ export default function AdminNotificationDefaultsPanel() { const { matrix, saving, cycle } = useNotificationDefaults() if (!matrix) return null - const channels = matrix.channels.filter(ch => matrix.event_types.some(evt => matrix.implemented_combos[evt]?.includes(ch.id))) + const channels = defaultChannels(matrix) const columns = `minmax(0, 1fr) ${channels.map(() => '76px').join(' ')}` return ( @@ -63,7 +57,7 @@ export default function AdminNotificationDefaultsPanel() { {t(EVENT_LABEL_KEYS[eventType]) || eventType} {channels.map(ch => { if (!implemented.includes(ch.id)) return — - const state = matrix.defaults[eventType]?.[ch.id] ?? 'on' + const state = defaultOf(matrix, eventType, ch.id) const Icon = ICON[state] const label = `${t(EVENT_LABEL_KEYS[eventType]) || eventType}, ${channelLabel(ch, t)}: ${t(LABEL_KEYS[state])}` return ( diff --git a/client/src/pages/admin/notificationDefaultsModel.ts b/client/src/pages/admin/notificationDefaultsModel.ts new file mode 100644 index 000000000..6b3894e29 --- /dev/null +++ b/client/src/pages/admin/notificationDefaultsModel.ts @@ -0,0 +1,33 @@ +import type { NotificationDefault } from '@trek/shared'; +import { Check, Lock, Minus } from 'lucide-react'; +import type { NotificationDefaultsMatrix } from './useNotificationDefaults'; + +/** + * The notification defaults grid (#1536) as both views draw it, the desktop + * AdminNotificationDefaultsPanel and the phone MAdminNotificationDefaults: each + * cell cycles On → Off → Blocked, Off a default a user may still turn on, + * Blocked off for everyone. + */ +export const NEXT_DEFAULT: Record = { + on: 'off', + off: 'blocked', + blocked: 'on', +}; +export const DEFAULT_ICON = { on: Check, off: Minus, blocked: Lock } as const; +export const DEFAULT_LABEL_KEYS: Record = { + on: 'admin.notificationDefaults.on', + off: 'admin.notificationDefaults.off', + blocked: 'admin.notificationDefaults.blocked', +}; + +/** The channels at least one event can be sent on; a channel nothing uses gets no column. */ +export function defaultChannels(matrix: NotificationDefaultsMatrix): NotificationDefaultsMatrix['channels'] { + return matrix.channels.filter((ch) => + matrix.event_types.some((evt) => matrix.implemented_combos[evt]?.includes(ch.id)) + ); +} + +/** A cell's current default; a cell the server does not list starts on. */ +export function defaultOf(matrix: NotificationDefaultsMatrix, eventType: string, channel: string): NotificationDefault { + return matrix.defaults[eventType]?.[channel] ?? 'on'; +} diff --git a/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx b/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx new file mode 100644 index 000000000..7ef13e3a7 --- /dev/null +++ b/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx @@ -0,0 +1,57 @@ +// 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>) => ({ + 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(); + 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(); + 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(); + expect(cells()).toHaveLength(0); + }); +}); diff --git a/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx b/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx index da79a125c..6b696a886 100644 --- a/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx +++ b/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx @@ -10,6 +10,9 @@ import { useTranslation } from '../../../../src/i18n'; import type { useAdmin } from '../../../../src/pages/admin/useAdmin'; import MAdminNotificationsSection from '../../../../src/mobile/screens/admin/MAdminNotificationsSection'; +// The defaults grid loads its own data and has its own suite (MAdminNotificationDefaults.test.tsx). +vi.mock('../../../../src/mobile/screens/admin/MAdminNotificationDefaults', () => ({ default: () =>
})); + // The per-event matrix loads its own data and has its own spec — stub it so the // assertions here only see the section's own cards. vi.mock('../../../../src/mobile/screens/admin/MAdminNotifyMatrix', () => ({ diff --git a/client/tests/unit/mobile/admin/MAdminSheets.test.tsx b/client/tests/unit/mobile/admin/MAdminSheets.test.tsx index 3cdfe716e..4d52385ad 100644 --- a/client/tests/unit/mobile/admin/MAdminSheets.test.tsx +++ b/client/tests/unit/mobile/admin/MAdminSheets.test.tsx @@ -1,4 +1,4 @@ -// FE-MOB-ASHEET-001 to FE-MOB-ASHEET-026 +// FE-MOB-ASHEET-001 to FE-MOB-ASHEET-028 import React from 'react'; import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import userEvent from '@testing-library/user-event'; @@ -217,6 +217,30 @@ describe('MAdminSheets', () => { expect(hitId).toBe('2'); }); + it('FE-MOB-ASHEET-027: unlinking single sign-on confirms first, then forgets that user's SSO identity', async () => { + const user = userEvent.setup(); + let hitId = ''; + server.use( + http.delete('/api/admin/users/:id/sso', ({ params }) => { + hitId = String(params.id); + return HttpResponse.json({ ok: true }); + }), + ); + const admin = renderSheets({ editingUser: ALICE, oidcConfigured: true }); + + await user.click(screen.getByRole('button', { name: 'Remove SSO link' })); + expect(screen.getByRole('dialog', { name: 'Remove SSO link' })).toBeInTheDocument(); + await user.click(screen.getAllByRole('button', { name: 'Remove SSO link' })[1]); + + await waitFor(() => expect(admin.toast.success).toHaveBeenCalled()); + expect(hitId).toBe('2'); + }); + + it('FE-MOB-ASHEET-028: without single sign-on set up there is nothing to unlink', () => { + renderSheets({ editingUser: ALICE, oidcConfigured: false }); + expect(screen.queryByRole('button', { name: 'Remove SSO link' })).not.toBeInTheDocument(); + }); + it('FE-MOB-ASHEET-012: a failing passkey reset toasts the error and keeps the sheet open', async () => { const user = userEvent.setup(); server.use( diff --git a/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx b/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx index 881ac5f6e..caa29db41 100644 --- a/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx +++ b/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx @@ -1,7 +1,7 @@ // FE-MOB-SET-001 onwards import { describe, it, expect, vi, beforeEach } from 'vitest'; import userEvent from '@testing-library/user-event'; -import { render, screen } from '../../../helpers/render'; +import { render, screen, within } from '../../../helpers/render'; import { resetAllStores, seedStore } from '../../../helpers/store'; import { buildSettings } from '../../../helpers/factories'; import { useSettingsStore } from '../../../../src/store/settingsStore'; @@ -53,6 +53,21 @@ describe('MSettingsGeneral', () => { expect(updateSetting).toHaveBeenCalledWith('language', 'de'); }); + it('FE-MOB-SET-003b: place names follow the app until another language is picked for them', async () => { + const user = userEvent.setup(); + const updateSetting = vi.fn().mockResolvedValue(undefined); + seedStore(useSettingsStore, { + settings: buildSettings({ language: 'en' }), + updateSetting, + }); + render(); + + await user.click(screen.getByRole('button', { name: 'Same as the app' })); + const sheet = await screen.findByRole('dialog', { name: 'Place names' }); + await user.click(within(sheet).getByRole('button', { name: 'Deutsch' })); + expect(updateSetting).toHaveBeenCalledWith('place_language', 'de'); + }); + it('FE-MOB-SET-004: a chosen display currency is shown with its symbol', () => { seedStore(useSettingsStore, { settings: buildSettings({ language: 'en', default_currency: 'EUR' }) }); render(); diff --git a/client/tests/unit/mobile/settings/MWandererConnectionSection.test.tsx b/client/tests/unit/mobile/settings/MWandererConnectionSection.test.tsx new file mode 100644 index 000000000..7a91d83aa --- /dev/null +++ b/client/tests/unit/mobile/settings/MWandererConnectionSection.test.tsx @@ -0,0 +1,102 @@ +// FE-MOB-WAND-001 to FE-MOB-WAND-004 +import userEvent from '@testing-library/user-event'; +import type { WandererConnection } from '@trek/shared'; +import { http, HttpResponse } from 'msw'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import MWandererConnectionSection from '../../../../src/mobile/screens/settings/MWandererConnectionSection'; +import { server } from '../../../helpers/msw/server'; +import { render, screen, waitFor } from '../../../helpers/render'; +import { resetAllStores } from '../../../helpers/store'; + +const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() })); +vi.mock('../../../../src/components/shared/Toast', async (importOriginal) => ({ + ...(await importOriginal()), + useToast: () => toast, +})); + +const disconnected: WandererConnection = { + url: '', + tokenMasked: '', + allowInsecureTls: false, + connected: false, + lastCheckedAt: null, + lastCheckOk: null, + lastCheckError: null, +}; +const connected: WandererConnection = { + ...disconnected, + url: 'https://wanderer.test', + tokenMasked: '••••••••', + connected: true, +}; + +function settingsRoute(state: { current: WandererConnection }) { + return http.get('/api/integrations/wanderer/settings', () => HttpResponse.json(state.current)); +} + +beforeEach(() => { + resetAllStores(); + vi.clearAllMocks(); +}); + +describe('MWandererConnectionSection', () => { + it('FE-MOB-WAND-001: saves an address and a token and shows the connection', async () => { + const state = { current: disconnected }; + const saved: unknown[] = []; + server.use( + settingsRoute(state), + http.put('/api/integrations/wanderer/settings', async ({ request }) => { + saved.push(await request.json()); + state.current = connected; + return HttpResponse.json({ success: true }); + }) + ); + render(); + + expect(await screen.findByText('Not connected')).toBeInTheDocument(); + await userEvent.type(screen.getByLabelText('Instance URL'), 'https://wanderer.test'); + await userEvent.type(screen.getByLabelText('API token'), 'wanderer_key_abc'); + await userEvent.click(screen.getByRole('button', { name: 'Save' })); + + await waitFor(() => + expect(saved).toEqual([{ url: 'https://wanderer.test', token: 'wanderer_key_abc', allowInsecureTls: false }]) + ); + expect(await screen.findByText('Connected')).toBeInTheDocument(); + }); + + it('FE-MOB-WAND-002: a token that is no wanderer API token is called out and not sent', async () => { + server.use(settingsRoute({ current: disconnected })); + render(); + await userEvent.type(await screen.findByLabelText('Instance URL'), 'https://wanderer.test'); + await userEvent.type(screen.getByLabelText('API token'), 'my-password'); + + expect(screen.getByLabelText('API token')).toHaveAttribute('aria-invalid', 'true'); + expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled(); + }); + + it('FE-MOB-WAND-003: a test reports its result in the card', async () => { + server.use( + settingsRoute({ current: connected }), + http.post('/api/integrations/wanderer/test', () => HttpResponse.json({ ok: true, trailCount: 5 })) + ); + render(); + await screen.findByText('Connected'); + await userEvent.click(screen.getByRole('button', { name: /Test connection|Test/ })); + expect(await screen.findByRole('status')).toBeInTheDocument(); + }); + + it('FE-MOB-WAND-004: a connected install can be disconnected', async () => { + let deleted = false; + server.use( + settingsRoute({ current: connected }), + http.delete('/api/integrations/wanderer/settings', () => { + deleted = true; + return HttpResponse.json({ success: true }); + }) + ); + render(); + await screen.findByText('Connected'); + await userEvent.click(screen.getByRole('button', { name: /Disconnect/ })); + await waitFor(() => expect(deleted).toBe(true)); + }); +});