feat(admin): finalize live show settings and related tests
This commit is contained in:
@@ -91,6 +91,7 @@ export type LiveShowLink = {
|
||||
url: string;
|
||||
qr_code_data_url: string | null;
|
||||
rotated_at: string | null;
|
||||
expires_at: string | null;
|
||||
};
|
||||
|
||||
export type TenantEvent = {
|
||||
@@ -1766,6 +1767,7 @@ function normalizeLiveShowLink(payload: JsonValue | LiveShowLink | null | undefi
|
||||
url: '',
|
||||
qr_code_data_url: null,
|
||||
rotated_at: null,
|
||||
expires_at: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1776,6 +1778,7 @@ function normalizeLiveShowLink(payload: JsonValue | LiveShowLink | null | undefi
|
||||
url: typeof record.url === 'string' ? record.url : '',
|
||||
qr_code_data_url: typeof record.qr_code_data_url === 'string' ? record.qr_code_data_url : null,
|
||||
rotated_at: typeof record.rotated_at === 'string' ? record.rotated_at : null,
|
||||
expires_at: typeof record.expires_at === 'string' ? record.expires_at : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2603,6 +2603,11 @@
|
||||
"rotateSuccess": "Live-Show-Link neu generiert.",
|
||||
"rotateFailed": "Live-Show-Link konnte nicht neu generiert werden.",
|
||||
"rotatedAt": "Zuletzt erneuert {{time}}",
|
||||
"expiresAt": "Gültig bis {{time}}",
|
||||
"expiresSoonAt": "Läuft bald ab: {{time}}",
|
||||
"expiredAt": "Abgelaufen am {{time}}",
|
||||
"expiredHint": "Generiere den Link neu, um wieder eine aktive URL und einen aktiven QR-Code zu erhalten.",
|
||||
"rotateNow": "Jetzt neu generieren",
|
||||
"noExpiry": "Dauerhaft gültig, bis von Dir erneuert.",
|
||||
"loadFailed": "Live-Show-Link konnte nicht geladen werden.",
|
||||
"copySuccess": "Link kopiert",
|
||||
|
||||
@@ -2605,6 +2605,11 @@
|
||||
"rotateSuccess": "Live Show link rotated.",
|
||||
"rotateFailed": "Live Show link could not be rotated.",
|
||||
"rotatedAt": "Last rotated {{time}}",
|
||||
"expiresAt": "Valid until {{time}}",
|
||||
"expiresSoonAt": "Expires soon: {{time}}",
|
||||
"expiredAt": "Expired at {{time}}",
|
||||
"expiredHint": "Rotate the link to generate a new active URL and QR code.",
|
||||
"rotateNow": "Rotate now",
|
||||
"noExpiry": "No expiry date (valid until you rotate it).",
|
||||
"loadFailed": "Live Show link could not be loaded.",
|
||||
"copySuccess": "Link copied",
|
||||
|
||||
@@ -146,6 +146,8 @@ export default function MobileEventLiveShowSettingsPage() {
|
||||
const back = useBackNavigation(slug ? adminPath(`/mobile/events/${slug}`) : adminPath('/mobile/events'));
|
||||
|
||||
const locale = i18n.language?.startsWith('en') ? 'en-GB' : 'de-DE';
|
||||
const linkExpiryInfo = React.useMemo(() => parseLinkExpiry(liveShowLink?.expires_at ?? null, locale), [liveShowLink?.expires_at, locale]);
|
||||
const linkExpired = linkExpiryInfo?.isExpired ?? false;
|
||||
|
||||
const loadLink = React.useCallback(async () => {
|
||||
if (!slug) return;
|
||||
@@ -316,21 +318,21 @@ export default function MobileEventLiveShowSettingsPage() {
|
||||
<XStack gap="$2" marginTop="$2" alignItems="center" flexWrap="nowrap">
|
||||
<IconAction
|
||||
label={t('liveShowSettings.link.copy', 'Copy')}
|
||||
disabled={!liveShowLink?.url}
|
||||
disabled={!liveShowLink?.url || linkExpired}
|
||||
onPress={() => liveShowLink?.url && copyToClipboard(liveShowLink.url, t)}
|
||||
>
|
||||
<Copy size={18} />
|
||||
</IconAction>
|
||||
<IconAction
|
||||
label={t('liveShowSettings.link.share', 'Share')}
|
||||
disabled={!liveShowLink?.url}
|
||||
disabled={!liveShowLink?.url || linkExpired}
|
||||
onPress={() => liveShowLink?.url && shareLink(liveShowLink.url, event, t)}
|
||||
>
|
||||
<Share2 size={18} />
|
||||
</IconAction>
|
||||
<IconAction
|
||||
label={t('liveShowSettings.link.open', 'Open')}
|
||||
disabled={!liveShowLink?.url}
|
||||
disabled={!liveShowLink?.url || linkExpired}
|
||||
onPress={() => liveShowLink?.url && openLink(liveShowLink.url)}
|
||||
>
|
||||
<ExternalLink size={18} />
|
||||
@@ -360,10 +362,28 @@ export default function MobileEventLiveShowSettingsPage() {
|
||||
</XStack>
|
||||
) : null}
|
||||
{liveShowLink ? (
|
||||
<Text fontSize="$xs" color={muted} marginTop="$1.5">
|
||||
{t('liveShowSettings.link.noExpiry', 'No expiry date set.')}
|
||||
<Text fontSize="$xs" color={linkExpired ? danger : muted} marginTop="$1.5">
|
||||
{linkExpiryInfo
|
||||
? linkExpiryInfo.isExpired
|
||||
? t('liveShowSettings.link.expiredAt', 'Expired at {{time}}', { time: linkExpiryInfo.formatted })
|
||||
: linkExpiryInfo.isSoon
|
||||
? t('liveShowSettings.link.expiresSoonAt', 'Expires soon: {{time}}', { time: linkExpiryInfo.formatted })
|
||||
: t('liveShowSettings.link.expiresAt', 'Valid until {{time}}', { time: linkExpiryInfo.formatted })
|
||||
: t('liveShowSettings.link.noExpiry', 'No expiry date set.')}
|
||||
</Text>
|
||||
) : null}
|
||||
{linkExpired ? (
|
||||
<YStack gap="$2" marginTop="$2">
|
||||
<Text fontSize="$xs" color={muted}>
|
||||
{t('liveShowSettings.link.expiredHint', 'Rotate the link to generate a new active URL and QR code.')}
|
||||
</Text>
|
||||
<CTAButton
|
||||
label={linkBusy ? t('common.processing', '...') : t('liveShowSettings.link.rotateNow', 'Rotate now')}
|
||||
onPress={() => handleRotateLink()}
|
||||
disabled={linkBusy}
|
||||
/>
|
||||
</YStack>
|
||||
) : null}
|
||||
{liveShowLink?.rotated_at ? (
|
||||
<Text fontSize="$xs" color={muted} marginTop="$1.5">
|
||||
{t('liveShowSettings.link.rotatedAt', 'Last rotated {{time}}', {
|
||||
@@ -623,6 +643,35 @@ function formatTimestamp(value: string, locale: string): string {
|
||||
return date.toLocaleString(locale, { day: '2-digit', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
function parseLinkExpiry(
|
||||
value: string | null,
|
||||
locale: string
|
||||
): {
|
||||
formatted: string;
|
||||
isExpired: boolean;
|
||||
isSoon: boolean;
|
||||
} | null {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const expiresAt = date.getTime();
|
||||
const isExpired = expiresAt < now;
|
||||
const isSoon = !isExpired && expiresAt - now <= 24 * 60 * 60 * 1000;
|
||||
|
||||
return {
|
||||
formatted: formatTimestamp(value, locale),
|
||||
isExpired,
|
||||
isSoon,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveOption<T extends string>(value: unknown, options: T[], fallback: T): T {
|
||||
if (typeof value !== 'string') return fallback;
|
||||
return options.includes(value as T) ? (value as T) : fallback;
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
import React from 'react';
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
const fixtures = vi.hoisted(() => ({
|
||||
event: {
|
||||
id: 1,
|
||||
name: 'Demo Event',
|
||||
slug: 'demo-event',
|
||||
event_date: '2026-02-12',
|
||||
event_type_id: 1,
|
||||
event_type: { id: 1, name: 'Wedding' },
|
||||
status: 'published',
|
||||
settings: {
|
||||
live_show: {
|
||||
moderation_mode: 'manual',
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('react-router-dom', () => ({
|
||||
useParams: () => ({ slug: fixtures.event.slug }),
|
||||
}));
|
||||
|
||||
vi.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, fallback?: string | Record<string, unknown>) => {
|
||||
if (typeof fallback === 'string') {
|
||||
return fallback;
|
||||
}
|
||||
if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
|
||||
return fallback.defaultValue;
|
||||
}
|
||||
return key;
|
||||
},
|
||||
i18n: { language: 'en' },
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('../../api', () => ({
|
||||
getEvent: vi.fn(),
|
||||
getLiveShowLink: vi.fn(),
|
||||
rotateLiveShowLink: vi.fn(),
|
||||
updateEvent: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../auth/tokens', () => ({
|
||||
isAuthError: () => false,
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/apiError', () => ({
|
||||
getApiErrorMessage: () => 'error',
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/events', () => ({
|
||||
resolveEventDisplayName: () => fixtures.event.name,
|
||||
}));
|
||||
|
||||
vi.mock('../hooks/useBackNavigation', () => ({
|
||||
useBackNavigation: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('../components/MobileShell', () => ({
|
||||
MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
HeaderActionButton: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => (
|
||||
<button type="button" onClick={onPress}>
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('../components/Primitives', () => ({
|
||||
MobileCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
CTAButton: ({ label, onPress, disabled }: { label: string; onPress?: () => void; disabled?: boolean }) => (
|
||||
<button type="button" onClick={onPress} disabled={disabled}>
|
||||
{label}
|
||||
</button>
|
||||
),
|
||||
SkeletonCard: () => <div>Loading...</div>,
|
||||
}));
|
||||
|
||||
vi.mock('../components/FormControls', () => ({
|
||||
MobileField: ({ label, children }: { label: string; children: React.ReactNode }) => (
|
||||
<label>
|
||||
{label}
|
||||
{children}
|
||||
</label>
|
||||
),
|
||||
MobileInput: (props: React.InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
|
||||
MobileSelect: (props: React.SelectHTMLAttributes<HTMLSelectElement>) => <select {...props} />,
|
||||
}));
|
||||
|
||||
vi.mock('../components/ContextHelpLink', () => ({
|
||||
ContextHelpLink: () => null,
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/stacks', () => ({
|
||||
YStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
XStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/text', () => ({
|
||||
SizableText: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/react-native-web-lite', () => ({
|
||||
Pressable: ({
|
||||
children,
|
||||
onPress,
|
||||
disabled,
|
||||
...rest
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
onPress?: () => void;
|
||||
disabled?: boolean;
|
||||
[key: string]: unknown;
|
||||
}) => (
|
||||
<button type="button" onClick={onPress} disabled={disabled} {...rest}>
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('tamagui', () => ({
|
||||
Slider: Object.assign(
|
||||
({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
{
|
||||
Track: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
TrackActive: () => <div />,
|
||||
Thumb: () => <div />,
|
||||
}
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('../theme', () => ({
|
||||
useAdminTheme: () => ({
|
||||
textStrong: '#111827',
|
||||
text: '#111827',
|
||||
muted: '#6b7280',
|
||||
danger: '#dc2626',
|
||||
border: '#e5e7eb',
|
||||
surface: '#ffffff',
|
||||
primary: '#ff5a5f',
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('react-hot-toast', () => ({
|
||||
default: {
|
||||
error: vi.fn(),
|
||||
success: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
import MobileEventLiveShowSettingsPage from '../EventLiveShowSettingsPage';
|
||||
import { getEvent, getLiveShowLink } from '../../api';
|
||||
|
||||
describe('MobileEventLiveShowSettingsPage', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(getEvent).mockResolvedValue(fixtures.event as any);
|
||||
});
|
||||
|
||||
it('shows a validity timestamp when link expiry is present', async () => {
|
||||
vi.mocked(getLiveShowLink).mockResolvedValue({
|
||||
token: 'token-1',
|
||||
url: 'https://example.test/show/token-1',
|
||||
qr_code_data_url: null,
|
||||
rotated_at: null,
|
||||
expires_at: '2099-01-01T12:00:00Z',
|
||||
});
|
||||
|
||||
render(<MobileEventLiveShowSettingsPage />);
|
||||
|
||||
expect(await screen.findByText('Live Show link')).toBeInTheDocument();
|
||||
expect(await screen.findByText(/Valid until/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows expired state and disables stale link actions', async () => {
|
||||
vi.mocked(getLiveShowLink).mockResolvedValue({
|
||||
token: 'token-2',
|
||||
url: 'https://example.test/show/token-2',
|
||||
qr_code_data_url: null,
|
||||
rotated_at: null,
|
||||
expires_at: '2000-01-01T00:00:00Z',
|
||||
});
|
||||
|
||||
render(<MobileEventLiveShowSettingsPage />);
|
||||
|
||||
expect(await screen.findByText(/Expired at/)).toBeInTheDocument();
|
||||
expect(screen.getByText('Rotate the link to generate a new active URL and QR code.')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Copy' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Share' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Open' })).toBeDisabled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user