|
1 | 1 | import { describe, it, expect } from 'vitest' |
2 | | -import { getCollectionByFilePath, generateIdFromFsPath } from '../../src/runtime/utils/collection' |
| 2 | +import { getCollectionByFilePath, generateIdFromFsPath, generateFsPathFromId } from '../../src/runtime/utils/collection' |
3 | 3 | import type { CollectionInfo, ResolvedCollectionSource } from '@nuxt/content' |
4 | 4 | import { collections } from '../mocks/collection' |
5 | 5 |
|
@@ -87,3 +87,40 @@ describe('generateIdFromFsPath', () => { |
87 | 87 | // expect(result).toBe('multi-source/first/content/test.md') |
88 | 88 | // }) |
89 | 89 | }) |
| 90 | + |
| 91 | +describe('generateFsPathFromId', () => { |
| 92 | + it('One file included', () => { |
| 93 | + const id = 'landing/index.md' |
| 94 | + const source = { |
| 95 | + prefix: '/', |
| 96 | + include: 'index.md', |
| 97 | + } as ResolvedCollectionSource |
| 98 | + const result = generateFsPathFromId(id, source) |
| 99 | + expect(result).toBe('index.md') |
| 100 | + }) |
| 101 | + |
| 102 | + it('Global pattern included', () => { |
| 103 | + const id = 'docs/1.getting-started/2.introduction.md' |
| 104 | + const source = { |
| 105 | + prefix: '/', |
| 106 | + include: '**', |
| 107 | + exclude: ['index.md'], |
| 108 | + } as ResolvedCollectionSource |
| 109 | + const result = generateFsPathFromId(id, source) |
| 110 | + expect(result).toBe('1.getting-started/2.introduction.md') |
| 111 | + }) |
| 112 | + |
| 113 | + it('Custom pattern with prefix', () => { |
| 114 | + const id = 'docs_en/en/1.getting-started/2.introduction.md' |
| 115 | + const source = { |
| 116 | + prefix: '/en', |
| 117 | + include: 'en/**/*', |
| 118 | + exclude: [ |
| 119 | + 'en/index.md', |
| 120 | + ], |
| 121 | + } as ResolvedCollectionSource |
| 122 | + |
| 123 | + const result = generateFsPathFromId(id, source) |
| 124 | + expect(result).toBe('en/1.getting-started/2.introduction.md') |
| 125 | + }) |
| 126 | +}) |
0 commit comments