/** * 契约级单测(TDD)—— 能力键 task.complete.overdue-toast(2026-11-16 产品拍板) * * 溯源: * 需求:用户「马智强」反馈打卡提示不成功,根因=超期任务被 deadline 守卫拒绝(TC-C-02-E)。 * 产品拍板:过期任务允许打卡完成,但零奖励(不发 CF 值)。后端 TaskService.completeTask * 已改为超期完成返回 { pointsEarned:0, overdue:true };本契约锁定前端首页 * quickCompleteTask 对 overdue 的提示分支(避免用户看到"获得 0 CF")。 * 设计:cfc-frontend/pages/index-home/index.vue quickCompleteTask → completeTaskApi → res.data.overdue * → uni.showToast({ title: '已过期,打卡成功但不计奖励', icon: 'none' }) * * 说明:沿项目「源码静态契约」范式(对齐 __tests__/pages/tasks/taskHistory.view.test.js 静态装配), * 只读真实源码断言分支结构,不 mount 巨型 index.vue。 */ import fs from 'fs' import path from 'path' const INDEX_HOME_PATH = path.join(__dirname, '../../pages/index-home/index.vue') /** 提取 quickCompleteTask 方法体(4 空格缩进方法,到下一个方法边界 ` },` 为止) */ function quickCompleteBody(src) { const m = src.match(/quickCompleteTask\s*:\s*function\s*\([^)]*\)\s*\{([\s\S]*?)\n \},/) if (!m) throw new Error('无法在 index.vue 中定位 quickCompleteTask 方法体') return m[1] } describe('task.complete.overdue-toast:首页过期打卡提示分支', function () { let body beforeAll(function () { const src = fs.readFileSync(INDEX_HOME_PATH, 'utf8') body = quickCompleteBody(src) }) test('容纳后端 overdue 标记并提示「已过期,打卡成功但不计奖励」', function () { expect(body.indexOf('res.data.overdue') >= 0).toBe(true) expect(body.indexOf('已过期') >= 0).toBe(true) expect(body.indexOf('打卡成功但不计奖励') >= 0).toBe(true) }) test('overdue 分支成功 toast 用 icon none(提示而非成功动画,避免误导"获得奖励")', function () { const segStart = body.indexOf('res.data.overdue') expect(segStart).toBeGreaterThanOrEqual(0) const seg = body.slice(segStart, segStart + 400) expect(seg.indexOf("icon: 'none'") >= 0).toBe(true) }) test('overdue 分支前置(早于"获得 X CF"成功分支,避免被通用成功提示吞掉)', function () { const overdueIdx = body.indexOf('res.data.overdue') const earnIdx = body.indexOf('获得 ') expect(overdueIdx).toBeGreaterThanOrEqual(0) expect(earnIdx).toBeGreaterThan(overdueIdx) }) })