import { readFileSync } from 'node:fs' import { describe, expect, it } from 'vitest' const app = readFileSync('src/App.vue', 'utf8') const style = readFileSync('src/style.css', 'utf8') const css = readFileSync('src/today-sections.css', 'utf8') describe('Today independent collapsible sections', () => { it('owns and persists one three-field collapse state in App', () => { expect(app).toContain("const TODAY_SECTION_COLLAPSE_KEY = 'dodo.today-section-collapse.v1'") expect(app).toContain('readTodaySectionCollapse(window.localStorage, TODAY_SECTION_COLLAPSE_KEY)') expect(app).toContain('writeTodaySectionCollapse(window.localStorage, TODAY_SECTION_COLLAPSE_KEY, todaySectionCollapse.value)') }) it('imports the section stylesheet from the global stylesheet', () => { expect(style).toContain('@import "./today-sections.css";') }) it('renders full-row accessible toggles and labelled regions for all three sections', () => { for (const section of ['overdue', 'tasks', 'habits']) { expect(app).toContain(`id="today-${section}-heading"`) expect(app).toContain(`aria-controls="today-${section}"`) expect(app).toContain(`:aria-expanded="!todaySectionCollapse.${section}"`) if (section === 'tasks') { expect(app).toContain(":id=\"activeView==='today' ? 'today-tasks' : undefined\"") expect(app).toContain(":aria-labelledby=\"activeView==='today' ? 'today-tasks-heading' : (activeView==='tasks' || activeView==='upcoming') ? 'task-list-title' : undefined\"") } else { expect(app).toContain(`id="today-${section}"`) expect(app).toContain(`aria-labelledby="today-${section}-heading"`) } } expect(app).toContain('逾期') expect(app).toContain('今天') expect(app).toContain('习惯') expect(app).not.toMatch(/today-section-title"><(?:CalendarDays|ListTodo|Repeat2)\/>/) expect(app.match(/class="today-section-toggle(?: today-section-anchor)?"/g)).toHaveLength(3) expect(app).toContain('{{totalTasks}}') expect(app).not.toContain('{{taskTree.length}} 项') expect(app).toContain("{{ todaySectionCollapse.overdue ? '›' : '⌄' }}") expect(app).not.toContain(' { expect(app).toContain('
') expect(app).toContain('
', app.indexOf(' { expect(app).not.toContain("async function navigateTodaySection(section: 'tasks' | 'habits')") expect(app).toContain("@click=\"toggleTodaySection('tasks')\"") expect(app).toContain("@click=\"toggleTodaySection('habits')\"") }) })