返回 oh-my-ppt
style-density.test.ts
根目录 / tests / unit / styles / style-density.test.ts
1 import { readdirSync, readFileSync } from 'fs'
2 import path from 'path'
3 import { describe, expect, it } from 'vitest'
4
5 const projectRoot = process.cwd()
6 const stylesRoot = path.join(projectRoot, 'resources/styles')
7
8 const listBuiltinStyleSkillFiles = () =>
9 readdirSync(stylesRoot, { withFileTypes: true })
10 .filter((entry) => entry.isDirectory())
11 .map((entry) => path.join(stylesRoot, entry.name, 'SKILL.md'))
12 .filter((filePath) => {
13 try {
14 readFileSync(filePath, 'utf8')
15 return true
16 } catch {
17 return false
18 }
19 })
20
21 const extractLayoutSection = (markdown: string) => {
22 const match = markdown.match(/## 布局\n([\s\S]*?)(\n## |$)/)
23 return (match?.[1] || markdown).replace(/\s+/g, ' ').trim()
24 }
25
26 describe('builtin style density guidance', () => {
27 it('does not use style wording that directly encourages overloaded pages', () => {
28 const forbidden = [
29 '儿童节不怕满',
30 '全屏代码展示是常态',
31 '宁可多塞一行数据',
32 '信息密度可以很高',
33 '每个数据模块独立成卡片',
34 '信息宫格化,每个色块承载一类信息',
35 '下方结合卡片宫格',
36 '像积木一样堆叠'
37 ]
38
39 for (const filePath of listBuiltinStyleSkillFiles()) {
40 const markdown = readFileSync(filePath, 'utf8')
41 for (const phrase of forbidden) {
42 expect(markdown, `${path.relative(projectRoot, filePath)} should not contain ${phrase}`).not.toContain(
43 phrase
44 )
45 }
46 }
47 })
48
49 it('pairs card/grid/terminal/table layout cues with explicit breathing-room guidance', () => {
50 const riskyCue =
51 /(宫格|多面板|终端|代码|KPI|表格|看板|卡片式布局|色块.*分组|模块化排布|不对称布局)/
52 const densityBuffer =
53 /(留白|呼吸|低到中密度|不要.*堆|不要.*塞|不要.*密集|不要默认|避免.*堆|避免.*塞|避免.*密集|由内容|按内容|可读|克制|少量|必要信息)/
54
55 for (const filePath of listBuiltinStyleSkillFiles()) {
56 const layout = extractLayoutSection(readFileSync(filePath, 'utf8'))
57 if (!riskyCue.test(layout)) continue
58
59 expect(layout, `${path.relative(projectRoot, filePath)} has risky layout cues`).toMatch(
60 densityBuffer
61 )
62 }
63 })
64
65 it('keeps dreamy-romance sparse for data-heavy report pages', () => {
66 const dreamy = readFileSync(path.join(stylesRoot, 'dreamy-romance/SKILL.md'), 'utf8')
67
68 expect(dreamy).toContain('数据、报告或表格型内容也要保持柔和低到中密度')
69 expect(dreamy).toContain('不要把每个指标都扩成同等大小的大卡片')
70 expect(dreamy).toContain('避免同一事实同时出现在摘要卡、时间轴和说明卡里')
71 })
72 })
73
73 lines TYPESCRIPT