|
1 | | -import { GET } from '../../../../[version]/[section]/[page]/[tab]' |
| 1 | +import { GET } from '../../../../../../../pages/api/[version]/[section]/[page]/[tab]' |
2 | 2 |
|
3 | 3 | /** |
4 | 4 | * Mock content collections with entries that have body content |
5 | 5 | * to test markdown/MDX content retrieval |
6 | 6 | */ |
7 | | -jest.mock('../../../../../../content', () => { |
8 | | - const { mockContentCollections } = jest.requireActual('../../../../testHelpers.ts') |
9 | | - return { content: mockContentCollections.v6 } |
10 | | -}) |
| 7 | +jest.mock('../../../../../../../content', () => ({ |
| 8 | + content: [ |
| 9 | + { name: 'react-component-docs', base: '/mock/path/react', pattern: '**/*.md', version: 'v6' }, |
| 10 | + { name: 'core-docs', base: '/mock/path/core', pattern: '**/*.md', version: 'v6' } |
| 11 | + ] |
| 12 | +})) |
11 | 13 |
|
12 | 14 | /** |
13 | 15 | * Mock getCollection to return entries with body (markdown content) |
14 | 16 | * simulating real documentation pages with content |
15 | 17 | */ |
16 | | -jest.mock('astro:content', () => { |
17 | | - const { mockEntriesWithBody, createGetCollectionMock } = jest.requireActual( |
18 | | - '../../../../testHelpers.ts', |
19 | | - ) |
20 | | - return { |
21 | | - getCollection: createGetCollectionMock({ |
22 | | - 'react-component-docs': mockEntriesWithBody['react-component-docs'], |
23 | | - 'core-docs': mockEntriesWithBody['core-docs'], |
24 | | - }), |
25 | | - } |
26 | | -}) |
| 18 | +jest.mock('astro:content', () => ({ |
| 19 | + getCollection: jest.fn((collectionName: string) => { |
| 20 | + const mockData: Record<string, any[]> = { |
| 21 | + 'react-component-docs': [ |
| 22 | + { |
| 23 | + id: 'components/alert/react', |
| 24 | + slug: 'components/alert/react', |
| 25 | + body: '# Alert Component\n\nReact Alert documentation content', |
| 26 | + data: { id: 'Alert', title: 'Alert', section: 'components', tab: 'react' }, |
| 27 | + collection: 'react-component-docs' |
| 28 | + }, |
| 29 | + { |
| 30 | + id: 'components/alert/html', |
| 31 | + slug: 'components/alert/html', |
| 32 | + body: '# Alert HTML\n\nHTML Alert documentation content', |
| 33 | + data: { id: 'Alert', title: 'Alert', section: 'components', tab: 'html' }, |
| 34 | + collection: 'react-component-docs' |
| 35 | + }, |
| 36 | + { |
| 37 | + id: 'components/alert/react-demos', |
| 38 | + slug: 'components/alert/react-demos', |
| 39 | + body: '# Alert Demos\n\nReact demos content', |
| 40 | + data: { id: 'Alert', title: 'Alert Demos', section: 'components', tab: 'react-demos' }, |
| 41 | + collection: 'react-component-docs' |
| 42 | + } |
| 43 | + ], |
| 44 | + 'core-docs': [] |
| 45 | + } |
| 46 | + return Promise.resolve(mockData[collectionName] || []) |
| 47 | + }) |
| 48 | +})) |
27 | 49 |
|
28 | 50 | /** |
29 | 51 | * Mock utilities for tab identification and transformation |
30 | 52 | */ |
31 | | -jest.mock('../../../../../../utils', () => { |
32 | | - const { mockUtils } = jest.requireActual('../../../../testHelpers.ts') |
33 | | - return mockUtils |
34 | | -}) |
| 53 | +jest.mock('../../../../../../../utils', () => ({ |
| 54 | + kebabCase: jest.fn((id: string) => { |
| 55 | + if (!id) return '' |
| 56 | + return id |
| 57 | + .replace(/PatternFly/g, 'Patternfly') |
| 58 | + .replace(/([a-z])([A-Z])/g, '$1-$2') |
| 59 | + .replace(/[\s_]+/g, '-') |
| 60 | + .toLowerCase() |
| 61 | + }), |
| 62 | + getDefaultTab: jest.fn((filePath?: string) => { |
| 63 | + if (!filePath) return 'react' |
| 64 | + if (filePath.includes('react')) return 'react' |
| 65 | + if (filePath.includes('html')) return 'html' |
| 66 | + return 'react' |
| 67 | + }), |
| 68 | + addDemosOrDeprecated: jest.fn((tabName: string, filePath?: string) => { |
| 69 | + if (!filePath || !tabName) return '' |
| 70 | + let result = tabName |
| 71 | + if (filePath.includes('demos') && !tabName.includes('-demos')) result += '-demos' |
| 72 | + if (filePath.includes('deprecated') && !tabName.includes('-deprecated')) result += '-deprecated' |
| 73 | + return result |
| 74 | + }) |
| 75 | +})) |
35 | 76 |
|
36 | 77 | /** |
37 | 78 | * Mock API index to validate paths |
38 | 79 | */ |
39 | | -jest.mock('../../../../../../utils/apiIndex/get', () => ({ |
| 80 | +jest.mock('../../../../../../../utils/apiIndex/get', () => ({ |
40 | 81 | getApiIndex: jest.fn().mockResolvedValue({ |
41 | 82 | versions: ['v6'], |
42 | 83 | sections: { |
|
0 commit comments