41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
|
|
// Task 3 用例 1:theme.manifest 满足 contracts 冻结守卫 isThemeManifest,
|
|||
|
|
// 且 pilot 主题的关键字面量(key/version/renderContractVersion/内容类型/必填配置/七模板)钉死。
|
|||
|
|
import { describe, expect, it } from 'vitest'
|
|||
|
|
import { isThemeManifest } from '@sf/contracts'
|
|||
|
|
import themeManifest from '../theme.manifest.js'
|
|||
|
|
|
|||
|
|
describe('theme.manifest(contracts 冻结面)', () => {
|
|||
|
|
it('isThemeManifest 守卫通过', () => {
|
|||
|
|
expect(isThemeManifest(themeManifest)).toBe(true)
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
it('关键字段:key/version/renderContractVersion/supportedContentTypes/requiredSiteConfig', () => {
|
|||
|
|
expect(themeManifest.key).toBe('pilot-minimal')
|
|||
|
|
expect(themeManifest.version).toBe('0.1.0')
|
|||
|
|
expect(themeManifest.renderContractVersion).toBe('1')
|
|||
|
|
expect(themeManifest.supportedContentTypes).toStrictEqual(['news_article', 'product', 'basic_page'])
|
|||
|
|
expect(themeManifest.requiredSiteConfig).toStrictEqual(['name', 'origin', 'locale'])
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
it('templates 恰七条目:home/page/product-list/product-detail/news-list/news-detail/not-found(key 唯一、appliesTo 非空)', () => {
|
|||
|
|
expect(themeManifest.templates.map((t) => t.key)).toStrictEqual([
|
|||
|
|
'home',
|
|||
|
|
'page',
|
|||
|
|
'product-list',
|
|||
|
|
'product-detail',
|
|||
|
|
'news-list',
|
|||
|
|
'news-detail',
|
|||
|
|
'not-found',
|
|||
|
|
])
|
|||
|
|
expect(new Set(themeManifest.templates.map((t) => t.key)).size).toBe(7)
|
|||
|
|
for (const t of themeManifest.templates) {
|
|||
|
|
expect(typeof t.appliesTo).toBe('string')
|
|||
|
|
expect(t.appliesTo).not.toBe('')
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
it('守卫面的反例仍然成立(守卫不是恒真)', () => {
|
|||
|
|
expect(isThemeManifest({ key: 'x', version: 'not-semver', renderContractVersion: '1' })).toBe(false)
|
|||
|
|
})
|
|||
|
|
})
|