|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import React from 'react'; |
| 3 | +import { describe, expect, test, vi } from 'vitest'; |
| 4 | + |
| 5 | +import { AppWrapper } from '@/tests/utils'; |
| 6 | + |
| 7 | +// Force mobile layout so the children count is rendered |
| 8 | +vi.mock('@/stores', () => ({ |
| 9 | + useResponsiveStore: () => ({ isDesktop: false }), |
| 10 | +})); |
| 11 | + |
| 12 | +// Provide stable mocks for hooks used by the component |
| 13 | +vi.mock('../../doc-management', async () => { |
| 14 | + const actual = await vi.importActual<any>('../../doc-management'); |
| 15 | + return { |
| 16 | + ...actual, |
| 17 | + useTrans: () => ({ transRole: vi.fn((r) => String(r)) }), |
| 18 | + useIsCollaborativeEditable: () => ({ isEditable: true }), |
| 19 | + }; |
| 20 | +}); |
| 21 | + |
| 22 | +vi.mock('@/core', () => ({ |
| 23 | + useConfig: () => ({ data: {} }), |
| 24 | +})); |
| 25 | + |
| 26 | +vi.mock('@/hook', () => ({ |
| 27 | + useDate: () => ({ |
| 28 | + relativeDate: () => 'yesterday', |
| 29 | + calculateDaysLeft: () => 5, |
| 30 | + }), |
| 31 | +})); |
| 32 | + |
| 33 | +import { DocHeaderInfo } from '../components/DocHeaderInfo'; |
| 34 | + |
| 35 | +describe('DocHeaderInfo', () => { |
| 36 | + test('renders the number of sub-documents when numchild is provided (mobile layout)', () => { |
| 37 | + const doc = { |
| 38 | + numchild: 3, |
| 39 | + updated_at: new Date().toISOString(), |
| 40 | + } as any; |
| 41 | + |
| 42 | + render(<DocHeaderInfo doc={doc} />, { wrapper: AppWrapper }); |
| 43 | + |
| 44 | + expect(screen.getByText(/Contains 3 sub-documents/i)).toBeInTheDocument(); |
| 45 | + }); |
| 46 | +}); |
0 commit comments