Files
fotospiel-app/resources/js/admin/mobile/components/Sheet.test.tsx
2025-12-30 16:04:30 +01:00

63 lines
2.1 KiB
TypeScript

import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
vi.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string, fallback?: string) => fallback ?? key }),
}));
vi.mock('@tamagui/core', () => ({
useTheme: () => ({
surface: { val: '#ffffff' },
color12: { val: '#111827' },
gray: { val: '#6b7280' },
gray12: { val: '#0f172a' },
borderColor: { val: '#e5e7eb' },
shadowColor: { val: 'rgba(0,0,0,0.1)' },
}),
}));
vi.mock('@tamagui/stacks', () => ({
YStack: ({ children, ...props }: { children: React.ReactNode }) => <div {...props}>{children}</div>,
XStack: ({ children, ...props }: { children: React.ReactNode }) => <div {...props}>{children}</div>,
}));
vi.mock('@tamagui/text', () => ({
SizableText: ({ children, ...props }: { children: React.ReactNode }) => <span {...props}>{children}</span>,
}));
vi.mock('@tamagui/react-native-web-lite', () => ({
Pressable: ({ children, onPress, ...props }: { children: React.ReactNode; onPress?: () => void }) => (
<button type="button" onClick={onPress} {...props}>
{children}
</button>
),
}));
vi.mock('@tamagui/sheet', () => {
const Sheet = ({ children }: { children: React.ReactNode }) => <div>{children}</div>;
Sheet.Frame = ({ children }: { children: React.ReactNode }) => <div>{children}</div>;
Sheet.Overlay = ({ children }: { children?: React.ReactNode }) => <div>{children}</div>;
Sheet.ScrollView = ({ children }: { children: React.ReactNode }) => <div>{children}</div>;
Sheet.Handle = () => <div />;
return { Sheet };
});
import { MobileSheet } from './Sheet';
describe('MobileSheet', () => {
it('renders title and closes via the close action', () => {
const onClose = vi.fn();
render(
<MobileSheet open title="Test Sheet" onClose={onClose}>
<div>Body</div>
</MobileSheet>,
);
expect(screen.getByText('Test Sheet')).toBeInTheDocument();
fireEvent.click(screen.getByText('Close'));
expect(onClose).toHaveBeenCalledTimes(1);
});
});