|
| 1 | +import { describe, expect, it } from "vitest" |
| 2 | +import { themes, themeCategories } from "../themes" |
| 3 | + |
| 4 | +const STYLE_KEYS = [ |
| 5 | + "container", |
| 6 | + "title", |
| 7 | + "subtitle", |
| 8 | + "h1", |
| 9 | + "h2", |
| 10 | + "h3", |
| 11 | + "paragraph", |
| 12 | + "blockquote", |
| 13 | + "code", |
| 14 | + "codeBlock", |
| 15 | + "pre", |
| 16 | + "ul", |
| 17 | + "ol", |
| 18 | + "li", |
| 19 | + "strong", |
| 20 | + "em", |
| 21 | + "a", |
| 22 | + "img", |
| 23 | + "table", |
| 24 | + "th", |
| 25 | + "td", |
| 26 | + "hr", |
| 27 | +] as const |
| 28 | + |
| 29 | +describe("themes", () => { |
| 30 | + it("exports 12 themes grouped into categories", () => { |
| 31 | + expect(themes).toHaveLength(12) |
| 32 | + const totalInCategories = themeCategories.reduce( |
| 33 | + (sum, cat) => sum + cat.themes.length, |
| 34 | + 0 |
| 35 | + ) |
| 36 | + expect(totalInCategories).toBe(12) |
| 37 | + }) |
| 38 | + |
| 39 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 40 | + "%s has all required style keys and metadata", |
| 41 | + (_, theme) => { |
| 42 | + expect(theme.id).toBeTruthy() |
| 43 | + expect(theme.name).toBeTruthy() |
| 44 | + expect(theme.description).toBeTruthy() |
| 45 | + expect(theme.previewBg).toMatch(/^#/) |
| 46 | + expect(theme.category).toBeTruthy() |
| 47 | + |
| 48 | + for (const key of STYLE_KEYS) { |
| 49 | + expect(theme.styles[key]).toBeTruthy() |
| 50 | + } |
| 51 | + } |
| 52 | + ) |
| 53 | + |
| 54 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 55 | + "%s container has safe base styles", |
| 56 | + (_, theme) => { |
| 57 | + expect(theme.styles.container).toContain("max-width") |
| 58 | + expect(theme.styles.container).toContain("padding") |
| 59 | + expect(theme.styles.container).toContain("font-size") |
| 60 | + expect(theme.styles.container).toContain("word-break") |
| 61 | + } |
| 62 | + ) |
| 63 | + |
| 64 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 65 | + "%s images never overflow and tables collapse borders", |
| 66 | + (_, theme) => { |
| 67 | + expect(theme.styles.img).toContain("max-width:100%") |
| 68 | + expect(theme.styles.table).toContain("border-collapse:collapse") |
| 69 | + } |
| 70 | + ) |
| 71 | + |
| 72 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 73 | + "%s headings are block-level and WeChat-safe", |
| 74 | + (_, theme) => { |
| 75 | + expect(theme.styles.h1).not.toContain("display:inline-block") |
| 76 | + expect(theme.styles.h2).not.toContain("display:inline-block") |
| 77 | + expect(theme.styles.h3).not.toContain("display:inline-block") |
| 78 | + } |
| 79 | + ) |
| 80 | + |
| 81 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 82 | + "%s strong does not use linear-gradient", |
| 83 | + (_, theme) => { |
| 84 | + expect(theme.styles.strong).not.toContain("linear-gradient") |
| 85 | + } |
| 86 | + ) |
| 87 | + |
| 88 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 89 | + "%s lists preserve visible bullets or numbers", |
| 90 | + (_, theme) => { |
| 91 | + expect(theme.styles.ul).not.toContain("list-style:none") |
| 92 | + expect(theme.styles.ol).not.toContain("list-style:none") |
| 93 | + } |
| 94 | + ) |
| 95 | + |
| 96 | + it.each(themes.map((t) => [t.id, t] as const))( |
| 97 | + "%s links are underlined for accessibility", |
| 98 | + (_, theme) => { |
| 99 | + expect(theme.styles.a).toContain("border-bottom") |
| 100 | + } |
| 101 | + ) |
| 102 | +}) |
0 commit comments