Refine admin PWA layout and tamagui usage
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-15 22:24:10 +01:00
parent 11018f273d
commit 292c8f0b26
37 changed files with 51503 additions and 21989 deletions

View File

@@ -65,6 +65,11 @@ vi.mock('../theme', () => ({
backdrop: '#0f172a',
dangerBg: '#fee2e2',
dangerText: '#b91c1c',
glassSurface: 'rgba(255,255,255,0.8)',
glassSurfaceStrong: 'rgba(255,255,255,0.9)',
glassBorder: 'rgba(226,232,240,0.7)',
glassShadow: 'rgba(15,23,42,0.14)',
appBackground: 'linear-gradient(180deg, #f7fafc, #eef3f7)',
}),
}));

View File

@@ -0,0 +1,235 @@
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
const fixtures = vi.hoisted(() => ({
event: {
id: 1,
name: 'Demo Wedding',
slug: 'demo-event',
event_date: '2026-02-19',
status: 'published' as const,
settings: { location: 'Berlin' },
tasks_count: 4,
photo_count: 12,
active_invites_count: 3,
total_invites_count: 5,
},
activePackage: {
id: 1,
package_id: 1,
package_name: 'Standard',
package_type: 'standard',
included_package_slug: null,
active: true,
used_events: 2,
remaining_events: 3,
price: null,
currency: null,
purchased_at: null,
expires_at: null,
package_limits: null,
branding_allowed: true,
watermark_allowed: true,
features: [],
},
}));
const navigateMock = vi.fn();
vi.mock('react-router-dom', () => ({
useNavigate: () => navigateMock,
useLocation: () => ({ search: '', pathname: '/event-admin/mobile/dashboard' }),
useParams: () => ({ slug: fixtures.event.slug }),
}));
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, fallback?: string | Record<string, unknown>, options?: Record<string, unknown>) => {
let text = key;
let resolvedOptions = options;
if (typeof fallback === 'string') {
text = fallback;
} else if (fallback && typeof fallback === 'object') {
resolvedOptions = fallback;
if (typeof fallback.defaultValue === 'string') {
text = fallback.defaultValue;
}
}
if (!resolvedOptions || typeof text !== 'string') {
return text;
}
return text.replace(/\{\{(\w+)\}\}/g, (_, token) => String(resolvedOptions?.[token] ?? ''));
},
i18n: {
language: 'de',
},
}),
initReactI18next: {
type: '3rdParty',
init: () => undefined,
},
}));
vi.mock('@tanstack/react-query', () => ({
useQuery: ({ queryKey }: { queryKey: unknown }) => {
const keyParts = Array.isArray(queryKey) ? queryKey : [queryKey];
const key = keyParts.map(String).join(':');
if (key.includes('packages-overview')) {
return { data: { packages: [], activePackage: fixtures.activePackage }, isLoading: false, isError: false };
}
if (key.includes('onboarding') && key.includes('status')) {
return { data: { steps: { summary_seen_package_id: fixtures.activePackage.id } }, isLoading: false };
}
if (key.includes('dashboard') && key.includes('events')) {
return { data: [fixtures.event], isLoading: false };
}
if (key.includes('dashboard') && key.includes('stats')) {
return { data: null, isLoading: false };
}
return { data: null, isLoading: false, isError: false };
},
}));
vi.mock('../../context/EventContext', () => ({
useEventContext: () => ({
events: [fixtures.event],
activeEvent: fixtures.event,
hasEvents: true,
hasMultipleEvents: false,
isLoading: false,
selectEvent: vi.fn(),
}),
}));
vi.mock('../../auth/context', () => ({
useAuth: () => ({ status: 'unauthenticated' }),
}));
vi.mock('../hooks/useInstallPrompt', () => ({
useInstallPrompt: () => ({ isInstalled: true, canInstall: false, isIos: false, promptInstall: vi.fn() }),
}));
vi.mock('../hooks/useAdminPushSubscription', () => ({
useAdminPushSubscription: () => ({ supported: true, subscribed: true, permission: 'granted', loading: false, enable: vi.fn() }),
}));
vi.mock('../hooks/useDevicePermissions', () => ({
useDevicePermissions: () => ({ storage: 'unavailable', loading: false, requestPersistentStorage: vi.fn() }),
}));
vi.mock('../lib/mobileTour', () => ({
getTourSeen: () => true,
resolveTourStepKeys: () => [],
setTourSeen: vi.fn(),
}));
vi.mock('../components/MobileShell', () => ({
MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('../components/Sheet', () => ({
MobileSheet: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('../components/Primitives', () => ({
MobileCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
CTAButton: ({ label }: { label: string }) => <button type="button">{label}</button>,
KpiTile: ({ label, value }: { label: string; value: string | number }) => (
<div>
<span>{label}</span>
<span>{value}</span>
</div>
),
ActionTile: ({ label }: { label: string }) => <div>{label}</div>,
PillBadge: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
SkeletonCard: () => <div>Loading...</div>,
}));
vi.mock('@tamagui/card', () => ({
Card: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('@tamagui/progress', () => ({
Progress: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
Indicator: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
}),
}));
vi.mock('@tamagui/group', () => ({
XGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
Item: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}),
YGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
Item: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}),
}));
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 }: { children: React.ReactNode; onPress?: () => void }) => (
<button type="button" onClick={onPress}>
{children}
</button>
),
}));
vi.mock('../theme', () => ({
ADMIN_ACTION_COLORS: {
settings: '#10b981',
tasks: '#f59e0b',
qr: '#6366f1',
images: '#ec4899',
liveShow: '#f97316',
liveShowSettings: '#38bdf8',
guests: '#22c55e',
guestMessages: '#f97316',
branding: '#0ea5e9',
photobooth: '#f43f5e',
recap: '#94a3b8',
analytics: '#22c55e',
},
ADMIN_MOTION: {
tileStaggerMs: 0,
},
useAdminTheme: () => ({
textStrong: '#0f172a',
muted: '#64748b',
border: '#e2e8f0',
surface: '#ffffff',
accentSoft: '#eef2ff',
primary: '#ff5a5f',
surfaceMuted: '#f8fafc',
shadow: 'rgba(15,23,42,0.12)',
}),
}));
vi.mock('../../lib/events', () => ({
resolveEventDisplayName: () => fixtures.event.name,
resolveEngagementMode: () => 'full',
isBrandingAllowed: () => true,
formatEventDate: () => '19. Feb. 2026',
}));
vi.mock('../eventDate', () => ({
isPastEvent: () => false,
}));
import MobileDashboardPage from '../DashboardPage';
describe('MobileDashboardPage', () => {
it('shows package usage progress when a limit is available', () => {
render(<MobileDashboardPage />);
expect(screen.getByText('2 of 5 events used')).toBeInTheDocument();
expect(screen.getByText('3 remaining')).toBeInTheDocument();
});
});

View File

@@ -79,6 +79,11 @@ vi.mock('../theme', () => ({
border: '#e5e7eb',
surface: '#ffffff',
primary: '#ff5a5f',
glassSurface: 'rgba(255,255,255,0.8)',
glassSurfaceStrong: 'rgba(255,255,255,0.9)',
glassBorder: 'rgba(229,231,235,0.7)',
glassShadow: 'rgba(15,23,42,0.14)',
appBackground: 'linear-gradient(180deg, #f7fafc, #eef3f7)',
}),
}));

View File

@@ -0,0 +1,217 @@
import React from 'react';
import { describe, expect, it, vi } 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-19',
event_type_id: null,
event_type: null,
status: 'published',
settings: {},
},
assignedTasks: [
{ id: 1, title: 'Task A', description: 'Desc', emotion: null, event_type_id: null },
{ id: 2, title: 'Task B', description: '', emotion: null, event_type_id: null },
],
libraryTasks: [
{ id: 3, title: 'Task C', description: '', emotion: null, event_type_id: null },
],
collections: [{ id: 1, name: 'Starter Pack', description: '' }],
emotions: [{ id: 1, name: 'Joy', color: '#ff6b6b' }],
}));
const navigateMock = vi.fn();
const backMock = vi.fn();
vi.mock('react-router-dom', () => ({
useNavigate: () => navigateMock,
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;
},
}),
}));
vi.mock('../hooks/useBackNavigation', () => ({
useBackNavigation: () => backMock,
}));
vi.mock('../../context/EventContext', () => ({
useEventContext: () => ({
activeEvent: fixtures.event,
selectEvent: vi.fn(),
}),
}));
vi.mock('../../api', () => ({
getEvent: vi.fn().mockResolvedValue(fixtures.event),
getEvents: vi.fn().mockResolvedValue([fixtures.event]),
getEventTasks: vi.fn().mockResolvedValue({ data: fixtures.assignedTasks }),
getTasks: vi.fn().mockResolvedValue({ data: fixtures.libraryTasks }),
getTaskCollections: vi.fn().mockResolvedValue({ data: fixtures.collections }),
getEmotions: vi.fn().mockResolvedValue(fixtures.emotions),
assignTasksToEvent: vi.fn(),
updateTask: vi.fn(),
importTaskCollection: vi.fn(),
createTask: vi.fn(),
detachTasksFromEvent: vi.fn(),
createEmotion: vi.fn(),
updateEmotion: vi.fn(),
deleteEmotion: vi.fn(),
}));
vi.mock('react-hot-toast', () => ({
default: {
error: vi.fn(),
success: vi.fn(),
},
}));
vi.mock('@tamagui/card', () => ({
Card: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('@tamagui/scroll-view', () => ({
ScrollView: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('@tamagui/group', () => ({
YGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
Item: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}),
}));
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/list-item', () => ({
ListItem: ({ title, subTitle, iconAfter }: { title?: React.ReactNode; subTitle?: React.ReactNode; iconAfter?: React.ReactNode }) => (
<div>
{title}
{subTitle}
{iconAfter}
</div>
),
}));
vi.mock('@tamagui/react-native-web-lite', () => ({
Pressable: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => (
<button type="button" onClick={onPress}>
{children}
</button>
),
}));
vi.mock('@tamagui/button', () => ({
Button: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => (
<button type="button" onClick={onPress}>
{children}
</button>
),
}));
vi.mock('@tamagui/radio-group', () => ({
RadioGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
Item: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Indicator: () => <div />,
}),
}));
vi.mock('@tamagui/alert-dialog', () => ({
AlertDialog: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
Portal: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Overlay: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
Content: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Title: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Description: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Cancel: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Action: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}),
}));
vi.mock('../components/MobileShell', () => ({
MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
HeaderActionButton: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('../components/Primitives', () => ({
MobileCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
CTAButton: ({ label, onPress }: { label: string; onPress?: () => void }) => (
<button type="button" onClick={onPress}>
{label}
</button>
),
SkeletonCard: () => <div>Loading...</div>,
FloatingActionButton: ({ label }: { label: string }) => <div>{label}</div>,
}));
vi.mock('../components/FormControls', () => ({
MobileField: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
MobileInput: (props: React.InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
MobileSelect: ({ children }: { children: React.ReactNode }) => <select>{children}</select>,
MobileTextArea: (props: React.TextareaHTMLAttributes<HTMLTextAreaElement>) => <textarea {...props} />,
}));
vi.mock('../components/Sheet', () => ({
MobileSheet: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('../components/Tag', () => ({
Tag: ({ label }: { label: string }) => <span>{label}</span>,
}));
vi.mock('../theme', () => ({
ADMIN_ACTION_COLORS: {
settings: '#0ea5e9',
tasks: '#f59e0b',
qr: '#6366f1',
branding: '#22c55e',
},
useAdminTheme: () => ({
textStrong: '#111827',
muted: '#6b7280',
subtle: '#94a3b8',
border: '#e5e7eb',
primary: '#ff5a5f',
danger: '#dc2626',
surface: '#ffffff',
surfaceMuted: '#f9fafb',
dangerBg: '#fee2e2',
dangerText: '#b91c1c',
overlay: 'rgba(15,23,42,0.5)',
shadow: 'rgba(15,23,42,0.12)',
}),
}));
import MobileEventTasksPage from '../EventTasksPage';
describe('MobileEventTasksPage', () => {
it('renders the task overview summary and quick jump chips', async () => {
render(<MobileEventTasksPage />);
expect(await screen.findByText('Task overview')).toBeInTheDocument();
expect(screen.getByText('Tasks total')).toBeInTheDocument();
expect(screen.getByText('Quick jump')).toBeInTheDocument();
expect(screen.getByText('Assigned')).toBeInTheDocument();
});
});

View File

@@ -69,6 +69,11 @@ vi.mock('../theme', () => ({
surface: '#ffffff',
primary: '#ff5a5f',
accentSoft: '#fde7ea',
glassSurface: 'rgba(255,255,255,0.8)',
glassSurfaceStrong: 'rgba(255,255,255,0.9)',
glassBorder: 'rgba(229,231,235,0.7)',
glassShadow: 'rgba(15,23,42,0.14)',
appBackground: 'linear-gradient(180deg, #f7fafc, #eef3f7)',
}),
}));

View File

@@ -110,6 +110,11 @@ vi.mock('../theme', () => ({
primary: '#ff5a5f',
danger: '#b91c1c',
accentSoft: '#ffe5ec',
glassSurface: 'rgba(255,255,255,0.8)',
glassSurfaceStrong: 'rgba(255,255,255,0.9)',
glassBorder: 'rgba(229,231,235,0.7)',
glassShadow: 'rgba(15,23,42,0.14)',
appBackground: 'linear-gradient(180deg, #f7fafc, #eef3f7)',
}),
}));