ATProto Social Bookmark
1import '@testing-library/jest-dom/vitest';
2import { vi } from 'vitest';
3
4// Mock Next.js router
5vi.mock('next/navigation', () => ({
6 useRouter: () => ({
7 push: vi.fn(),
8 replace: vi.fn(),
9 prefetch: vi.fn(),
10 back: vi.fn(),
11 forward: vi.fn(),
12 }),
13 usePathname: () => '/',
14 useSearchParams: () => new URLSearchParams(),
15}));
16
17// Mock next-intl
18vi.mock('next-intl', () => ({
19 useLocale: () => 'ja',
20 useMessages: () => ({
21 title: 'Rito',
22 create: { inform: { bookmark: 'ブックマークしました', success: '成功', process: '処理中' }, error: { unknownError: 'エラー' } },
23 detail: { view: '表示', more: 'もっと見る', less: '閉じる', inform: { process: '処理中', needlogin: 'ログインが必要です', nomore: 'これ以上ありません' } },
24 delete: { title: '削除', description: '削除しますか?', button: { close: '閉じる', delete: '削除' }, inform: { success: '削除しました', error: 'エラー' }, error: { error: 'エラー' } },
25 login: { title: 'ログイン', titleDescription: 'ログイン', didresolve: 'DID解決中', redirect: 'リダイレクト中', create: 'アカウント作成', button: { login: 'ログイン' }, field: { handle: { title: 'ハンドル', placeholder: 'example.bsky.social' }, agree: { title: '同意する' } }, error: { whitespace: '空白不可', notdomain: 'ドメイン形式', multibyte: 'ASCII文字のみ', invalidhandle: '無効なハンドル' } },
26 header: { termofuse: '利用規約', privacypolicy: 'プライバシー' },
27 }),
28 useTranslations: () => (key: string) => key,
29}));
30
31// Mock fetch
32global.fetch = vi.fn();
33
34// Mock window.matchMedia
35Object.defineProperty(window, 'matchMedia', {
36 writable: true,
37 value: vi.fn().mockImplementation(query => ({
38 matches: false,
39 media: query,
40 onchange: null,
41 addListener: vi.fn(),
42 removeListener: vi.fn(),
43 addEventListener: vi.fn(),
44 removeEventListener: vi.fn(),
45 dispatchEvent: vi.fn(),
46 })),
47});
48
49// Mock ResizeObserver
50global.ResizeObserver = class {
51 observe = vi.fn();
52 unobserve = vi.fn();
53 disconnect = vi.fn();
54};
55
56// Mock IntersectionObserver
57global.IntersectionObserver = class {
58 root = null;
59 rootMargin = '';
60 scrollMargin = '';
61 thresholds = [];
62 observe = vi.fn();
63 unobserve = vi.fn();
64 disconnect = vi.fn();
65 takeRecords = vi.fn();
66};