64 行
3.1 KiB
TypeScript
64 行
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { createHelpFixture } from '@/test/helpFixtures'
|
|
|
|
|
|
describe ('Help file catalogue', () => {
|
|
it ('uses current_edition rather than the newest file, without YAML titles', async () => {
|
|
const { api } = createHelpFixture ()
|
|
expect ((await api.getHelpArticle ('guide'))?.languages.ja.currentEdition)
|
|
.toBe ('2026-10-02.10')
|
|
expect (await api.getHelpSearchEntries ('ja')).toEqual ([
|
|
{ identifier: 'guide', edition: '2026-10-02.10',
|
|
title: 'ホーム第十版', body: '\nタグを検索する 第十版本文' },
|
|
{ identifier: '設定 手順', edition: '2026-10-03',
|
|
title: '設定', body: '\nタグを設定する' }])
|
|
})
|
|
|
|
it ('orders published editions numerically and separates languages', async () => {
|
|
const { api } = createHelpFixture ()
|
|
expect (await api.getHelpEditions ('guide', 'ja')).toEqual ([
|
|
'2026-10-01', '2026-10-02', '2026-10-02.2', '2026-10-02.3', '2026-10-02.10'])
|
|
expect (await api.getHelpEditions ('guide', 'en')).toEqual (['2026-10-02'])
|
|
expect (await api.getHelpPublishedEditions ('guide', 'ja'))
|
|
.not.toContain ('2026-10-02.11')
|
|
})
|
|
|
|
it ('uses generated edition titles without reparsing raw sources', async () => {
|
|
const { api, raw } = createHelpFixture ()
|
|
expect (await api.getHelpEditionText ('guide', 'ja', '2026-10-01'))
|
|
.toEqual ({ title: '旧ホーム', body: '\n過去限定本文' })
|
|
raw['../../help/guide/editions/ja/2026-10-02.mdx']
|
|
.mockResolvedValue ('\uFEFF# 改題\r\n\r\n本文\r\n# 別見出し')
|
|
expect (await api.getHelpEditionText ('guide', 'ja', '2026-10-02'))
|
|
.toEqual ({ title: 'ホーム', body: '\nタグを検索する' })
|
|
expect (raw['../../help/guide/editions/ja/2026-10-02.mdx']).not.toHaveBeenCalled ()
|
|
expect ((await api.getHelpEditionSource ('guide', 'ja', '2026-10-02'))?.source)
|
|
.toBe ('\uFEFF# 改題\r\n\r\n本文\r\n# 別見出し')
|
|
})
|
|
|
|
it ('returns missing resources without substituting another edition', async () => {
|
|
const { api } = createHelpFixture ()
|
|
expect (await api.getHelpArticle ('absent')).toBeNull ()
|
|
expect (await api.getHelpEditions ('absent', 'ja')).toEqual ([])
|
|
expect (await api.getHelpEdition ('guide', 'ja', 'missing')).toBeNull ()
|
|
expect (await api.getHelpEditionText ('guide', 'fr', '2026-10-02')).toBeNull ()
|
|
})
|
|
|
|
it ('reports generated search asset failures instead of hiding articles', async () => {
|
|
const { api, loads } = createHelpFixture ()
|
|
loads.search.mockImplementationOnce (() => { throw new Error ('asset failure') })
|
|
await expect (api.getHelpSearchEntries ('ja')).rejects.toThrow ('asset failure')
|
|
})
|
|
|
|
it ('reports raw loading failures and excludes unpublished editions', async () => {
|
|
const { api, raw } = createHelpFixture ()
|
|
const loader = raw['../../help/guide/editions/ja/2026-10-02.mdx']
|
|
loader.mockRejectedValueOnce (new Error ('fixture failure'))
|
|
await expect (api.getHelpEditionSource ('guide', 'ja', '2026-10-02'))
|
|
.rejects.toThrow ('fixture failure')
|
|
expect (await api.getHelpEdition ('guide', 'ja', '2026-10-02.11')).toBeNull ()
|
|
expect (await api.getHelpEditionSource ('guide', 'ja', '2026-10-02.11')).toBeNull ()
|
|
})
|
|
})
|