| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { readFileSync } from 'fs'
- import { resolve } from 'path'
- import { formatDateTime, formatDate } from '@/utils/format'
- // 契约:admin.family.createdAtDisplay
- // 家庭管理列表「创建时间」列必须显示到 时:分:秒(改用 formatDateTime:yyyy年MM月dd日 HH:mm:ss)
- // 溯源·需求:docs/superpowers/specs/2026-11-08-family-admin-list-polish.md §需求4
- // 溯源·设计:Families.vue 创建时间列改用 formatDateTime(utils/format.js L48-55 已含时分秒)
- //
- // 说明:Families.vue 存在既有 vue-jest 模板编译告警(v-else/v-if 非同级),无法直接 shallowMount。
- // 故本契约单测采用「读源码 + 校验列模板调用」+「格式函数行为」的组合断言。
- //
- // TDD-RED:当前实现仍用 formatDate(仅日期,无时分秒),本测试预期失败(红);
- // GREEN 阶段把创建时间列模板 {{ formatDate(scope.row.createdAt) }} 改为
- // {{ formatTime(scope.row.createdAt) }} 后转绿。
- const VIEWS_DIR = resolve(__dirname, '../views')
- const FAMILIES_VUE_PATH = resolve(VIEWS_DIR, 'Families.vue')
- const source = readFileSync(FAMILIES_VUE_PATH, 'utf8')
- // 从模板中抽取「创建时间」那一列的完整 <el-table-column> 块
- function extractCreatedAtColumnBlock(src) {
- const startTag = '<el-table-column prop="createdAt"'
- const start = src.indexOf(startTag)
- if (start === -1) return ''
- const end = src.indexOf('</el-table-column>', start)
- if (end === -1) return ''
- return src.slice(start, end + '</el-table-column>'.length)
- }
- const createdAtBlock = extractCreatedAtColumnBlock(source)
- describe('Families 创建时间显示契约 (admin.family.createdAtDisplay)', () => {
- it('创建时间列必须存在(设计 L48-55)', () => {
- expect(createdAtBlock).not.toBe('')
- })
- it('创建时间列应调用 formatTime(= Vue.prototype.formatDateTime,含时分秒)而非 formatDate', () => {
- expect(createdAtBlock).toMatch(/formatTime\s*\(\s*scope\.row\.createdAt\s*\)/)
- })
- it('创建时间列不应再调用仅显示日期的 formatDate', () => {
- expect(createdAtBlock).not.toMatch(/formatDate\s*\(\s*scope\.row\.createdAt\s*\)/)
- })
- it('formatDateTime 应输出 yyyy年MM月dd日 HH:mm:ss(时分秒齐全)', () => {
- expect(formatDateTime('2026-11-08T14:30:00')).toBe('2026年11月08日 14:30:00')
- })
- it('formatDate 仅输出日期(说明两者语义差异,确认契约要求的是含时分秒的 formatTime)', () => {
- expect(formatDate('2026-11-08T14:30:00')).toBe('2026年11月08日')
- })
- })
|