feat: 日报新增模板市场,支持社区模板安装与使用

This commit is contained in:
Wxw-Gu
2026-09-08 11:37:38 +08:00
parent 1156362c3c
commit 976aac32c5
35 changed files with 2957 additions and 82 deletions
+49 -1
View File
@@ -105,7 +105,14 @@ describe('daily report controls', () => {
avatar: ''
}
]
}))
})),
listReportTemplates: vi.fn(async () => []),
listReportTemplateCatalog: vi.fn(async () => ({
success: true,
catalog: { schemaVersion: '1', status: 'published', templates: [] }
})),
installReportTemplateFromCatalog: vi.fn(async () => ({ success: true })),
uninstallReportTemplate: vi.fn(async () => ({ success: true }))
}
})
})
@@ -903,4 +910,45 @@ describe('daily report controls', () => {
expect(onChange).toHaveBeenCalledWith('mobile-magazine')
})
it('does not select a market template before it is installed', async () => {
const user = userEvent.setup()
const onChange = vi.fn()
Object.assign(window.api, {
listReportTemplateCatalog: vi.fn(async () => ({
success: true,
catalog: {
schemaVersion: '1',
status: 'published',
templates: [
{
id: 'community.github.example.market',
version: '1.0.0',
interfaceVersion: '1',
name: '市场测试模板',
description: '只允许先安装',
author: 'fixture',
tags: [],
license: 'MIT',
minAppVersion: null,
download: 'https://raw.githubusercontent.com/Wxw-Gu/TraceMemo/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/packages/community.github.example.market/1.0.0/template.zip',
sizeBytes: 1,
sha256: 'a'.repeat(64),
preview: 'https://raw.githubusercontent.com/Wxw-Gu/TraceMemo/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/previews/community.github.example.market.png',
status: 'published'
}
]
}
}))
})
render(<ReportTemplateSelector value="v1" onChange={onChange} />)
const marketItem = (await screen.findByText('市场测试模板')).closest('.report-template-item')
expect(marketItem).not.toBeNull()
await user.click(within(marketItem!).getByRole('button', { name: '查看版式' }))
const dialog = screen.getByRole('dialog', { name: '市场测试模板' })
expect(within(dialog).getByRole('button', { name: '请先安装' })).toBeDisabled()
expect(within(dialog).queryByRole('button', { name: '选择此模板' })).not.toBeInTheDocument()
expect(onChange).not.toHaveBeenCalled()
})
})