5d2a1c6974
V158 给 biz_user_notification 加 subject_user_id(事件主体用户,与收件人 user_id 分家): 一行通知是给某个收件人看的,被通知的那个 uid 原先只活在文案字符串里,没有列就没法按用户成组, 也不肯用正则去解历史文案凑分组键。存量不回填(定案)⇒ 老行 subject_user_id 为 NULL,自成「未标注主体」一组。 写入侧 pushOrRefresh 第 8 参带主体,AUDIENCE_USER 时主体=收件人(故新增 7 参便捷档,68 处调用一行没改); pushToAdminsAnyOf 传 null 并注明理由:一把密钥被 N 个账号共用,不挑一个 uid 冒充。 新增 GET /api/notifications/groups 与 /api/admin/notifications/groups:Java 侧分组(复用 baseWrapper 一份筛选实现), 分页按组切,同屏返回 total=组数 与 rowCount=明细条数;unreadGroupCount 走 COUNT(DISTINCT scene, DATE(created_at), IFNULL(subject_user_id,-1)) —— IFNULL 不能省, MySQL 的 COUNT(DISTINCT a,b,c) 会跳过任一表达式为 NULL 的行,不兜就把存量那一组整个数没。 红点是新增 unreadGroupCount 而不动 unreadCount 语义:已装机老客户端读 unreadCount 画徽标, 换语义会让老客户端出现「红点 3、列表 217 条」对不上。 铃铛两级(后管+桌面各一份):聚合行点击只展开、不替用户标已读,已读必须进明细逐条点; 明细一次最多 50 条,超出显示「另有 N 条未列出」;下钻带 scene+day+subjectUserId(主体为空改下发 subjectUnlabelled 旗标走 IS NULL),少一维就会把同场景同天别主体的行混进这一组的明细——桌面端最初就漏了这一维。 死码随两级视图退场:groupNotificationsByDay/NotificationDayGroup 删掉,用例换成 formatDayLabel/notificationGroupKey/formatGroupCounts。 后管日期选择面板 z-index 抬到 3300(面板 3200)之上:Element 弹层只自 2000 起递增,不抬就被面板压住,表现为「日期点不动」。 playwright 加 E2E_PORT+strictPort:实测 5174/5176 被别的项目的 vite 占着,reuseExistingServer 让 e2e 连上别人的应用, 当时 5 条全红是端口归属问题而不是回归。 验证=后端通知面 66/66(-Dtest='Notification*' 63 + AdminNotificationControllerTest 3)BUILD SUCCESS; 后管 node --test 1819/1819、真浏览器 e2e 10/10(含遮挡与「展开只取本组」); 桌面 node --test 834/834、组件挂载 vitest 8/8;两前端 vue-tsc --noEmit rc=0;ops 值班侧 18/18。 记账三处=后管 source-pin 逐文件基线 notification-bell.test.ts 用例 6→7(该文件钉子仍 0,占比不动); 桌面 catch 棘轮 blocks 298→299(新增那支是 toggleGroup 明细失败写进面板 loadError,非静默,silent 84 一格没涨); 桌面 endpoints 台账补 /api/notifications/groups。 变异自证 7 条全 KILLED:红点按条数/组内没读完就减组数/聚合行直接标已读/明细截断不报数/下钻丢主体/ 丢 IS NULL 旗标/null 主体当值下发。其中「组内没读完就减组数」第一轮 SURVIVED——用例只钉了徽标, 而徽标在 unreadGroupCount 归零时会退回条数兜底,把这条回归盖住了;改成同时钉「N 组未读」chip 才杀掉。 已知盲区(下次补,别当已验):①桌面两级只在 happy-dom 跑过真组件,布局与层级没在真浏览器点过 (桌面日期弹层的层级修复本就在 HEAD 里,不是这批引入);②后管 e2e 夹具没有 subjectUserId=null 的行, 「存量自成一组」在后管 UI 层没被点过,只有后端 WHERE 与桌面组件各一条用例钉着。
113 lines
4.3 KiB
TypeScript
113 lines
4.3 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import {
|
|
formatNotificationTime,
|
|
formatUnreadBadge,
|
|
formatDayLabel,
|
|
formatGroupCounts,
|
|
notificationGroupKey,
|
|
hasNewNotification,
|
|
readLastNotifiedId,
|
|
writeLastNotifiedId,
|
|
} from '../src/layout/notification-bell-model.ts'
|
|
|
|
function createStorage() {
|
|
const store = new Map<string, string>()
|
|
return {
|
|
getItem: (key: string) => (store.has(key) ? (store.get(key) as string) : null),
|
|
setItem: (key: string, value: string) => {
|
|
store.set(key, String(value))
|
|
},
|
|
removeItem: (key: string) => {
|
|
store.delete(key)
|
|
},
|
|
}
|
|
}
|
|
|
|
function setupWindow() {
|
|
const localStorage = createStorage()
|
|
const globalScope = globalThis as Record<string, unknown>
|
|
const previous = globalScope.window
|
|
globalScope.window = { localStorage }
|
|
return {
|
|
localStorage,
|
|
restore: () => {
|
|
globalScope.window = previous
|
|
},
|
|
}
|
|
}
|
|
|
|
test('test_未读徽标:0 与非法值不显示、超过 99 显示 99+', () => {
|
|
assert.equal(formatUnreadBadge(0), '')
|
|
assert.equal(formatUnreadBadge(-3), '')
|
|
assert.equal(formatUnreadBadge(null), '')
|
|
assert.equal(formatUnreadBadge(undefined), '')
|
|
assert.equal(formatUnreadBadge(Number.NaN), '')
|
|
assert.equal(formatUnreadBadge(1), '1')
|
|
assert.equal(formatUnreadBadge(99), '99')
|
|
assert.equal(formatUnreadBadge(100), '99+')
|
|
})
|
|
|
|
test('test_新通知判定:latestId 需大于已提醒 id', () => {
|
|
assert.equal(hasNewNotification(0, 0), false)
|
|
assert.equal(hasNewNotification(null, 5), false)
|
|
assert.equal(hasNewNotification(5, 5), false)
|
|
assert.equal(hasNewNotification(4, 5), false)
|
|
assert.equal(hasNewNotification(6, 5), true)
|
|
assert.equal(hasNewNotification(6, 0), true)
|
|
assert.equal(hasNewNotification(6, null), true)
|
|
})
|
|
|
|
test('test_已提醒 id 按管理员读写并容错', () => {
|
|
setupWindow()
|
|
assert.equal(readLastNotifiedId(7), 0, '未写入时按 0 处理')
|
|
|
|
writeLastNotifiedId(7, 88)
|
|
assert.equal(readLastNotifiedId(7), 88)
|
|
assert.equal(readLastNotifiedId(8), 0, '不同管理员互不影响')
|
|
|
|
writeLastNotifiedId(7, 0)
|
|
assert.equal(readLastNotifiedId(7), 88, '非法 id 不覆盖已有值')
|
|
|
|
window.localStorage.setItem('admin-notification:last-notified-id:7', 'broken')
|
|
assert.equal(readLastNotifiedId(7), 0, '损坏值按 0 处理')
|
|
|
|
assert.equal(readLastNotifiedId(null), readLastNotifiedId('0'), '空 uid 归一为 0 号键')
|
|
})
|
|
|
|
test('test_时间展示:今天/昨天/更早', () => {
|
|
const now = new Date(2026, 8, 13, 15, 30)
|
|
assert.equal(formatNotificationTime(new Date(2026, 8, 13, 9, 5).toISOString(), now), '09:05')
|
|
assert.equal(formatNotificationTime(new Date(2026, 8, 12, 23, 59).toISOString(), now), '昨天 23:59')
|
|
assert.equal(formatNotificationTime(new Date(2026, 8, 1, 8, 0).toISOString(), now), '09-01 08:00')
|
|
assert.equal(formatNotificationTime(null, now), '')
|
|
assert.equal(formatNotificationTime('not-a-date', now), '')
|
|
})
|
|
|
|
test('test_日期组头文案:今天/昨天/更早/未知时间', () => {
|
|
const now = new Date(2026, 8, 13, 15, 30)
|
|
assert.equal(formatDayLabel('2026-09-13', now), '今天')
|
|
assert.equal(formatDayLabel('2026-09-12', now), '昨天')
|
|
assert.equal(formatDayLabel('2026-09-01', now), '2026年9月1日')
|
|
assert.equal(formatDayLabel('', now), '未知时间')
|
|
})
|
|
|
|
test('test_聚合组键:三维各自都能把两组分开', () => {
|
|
const base = { scene: 'task_partial', day: '2026-09-13', subjectUserId: 1160 }
|
|
assert.notEqual(notificationGroupKey({ ...base, subjectUserId: 1196 }), notificationGroupKey(base),
|
|
'同场景同天、不同主体用户必须是两组(这是定下来的粒度)')
|
|
assert.notEqual(notificationGroupKey({ ...base, scene: 'task_failed' }), notificationGroupKey(base),
|
|
'同一天不同场景必须是两组')
|
|
assert.notEqual(notificationGroupKey({ ...base, day: '2026-09-12' }), notificationGroupKey(base),
|
|
'同场景同主体、不同自然日必须是两组')
|
|
assert.equal(notificationGroupKey({ ...base, subjectUserId: null }),
|
|
notificationGroupKey({ ...base, subjectUserId: undefined }),
|
|
'null 与 undefined 都是"未标注主体",必须落进同一组')
|
|
})
|
|
|
|
test('test_组行计数文案:读完不再挂 0 未读', () => {
|
|
assert.equal(formatGroupCounts(12, 3), '12 条 · 3 未读')
|
|
assert.equal(formatGroupCounts(12, 0), '12 条')
|
|
assert.equal(formatGroupCounts(1, null), '1 条')
|
|
})
|