feat(通知): 列表按 场景×自然日×主体用户 聚合成两级,红点按组数亮而明细条数同屏;后管日期面板不再被弹窗压住

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 与桌面组件各一条用例钉着。
This commit is contained in:
2026-10-13 08:34:18 +08:00
parent 1e3bcc9688
commit 5d2a1c6974
31 changed files with 1938 additions and 344 deletions
+193 -35
View File
@@ -1,38 +1,78 @@
import { expect, test, type Page } from '@playwright/test'
// 站内通知铃铛面板验收:关键字/年月日区间搜索、按天分组、分页。
// 依赖 scripts/mock-admin-server.mjs 的通知夹具(14 条:09-13 六条、09-12 四条、09-10 四条)。
// 站内通知铃铛面板验收:聚合视图(场景 × 自然日 × 事件主体用户)、展开明细、
// 关键字/年月日区间搜索、按组分页、红点按组数。
// 依赖 scripts/mock-admin-server.mjs 的通知夹具:14 行折成 10 组、2 组未读、3 行未读。
// 夹具的 id 与 createdAt 同为插入时单调(与真库一致),场景显式写在夹具里而不是从 id 推。
// 夹具会被"标记已读"改写,而 mock 服务在 reuseExistingServer 下跨轮存活 ⇒ 每条用例前重置,
// 否则第二遍跑会带着上一遍的已读态,绝对计数断言全漂。
test.beforeEach(async ({ request }) => {
await request.post('/api/admin/notifications/__reset')
})
async function clearDateFilter(page: Page) {
const picker = page.locator('.bell-panel .bell-date-picker')
await picker.hover()
await picker.locator('.el-range__close-icon').click()
await expect(page.locator('.bell-page-total')).toHaveText('共 10 组 · 明细 14 条')
}
async function openBell(page: Page) {
await page.goto('/admin-vue/')
await expect(page.locator('.admin-topbar h1')).toHaveText('用户管理')
await page.locator('.admin-notification-bell .bell-trigger').click()
await expect(page.locator('.bell-panel')).toBeVisible()
await expect(page.locator('.bell-item').first()).toBeVisible()
// 面板默认按「当天」过滤,夹具是 09-10~09-13:先清空日期才能拿到全量
await clearDateFilter(page)
await expect(page.locator('.bell-group').first()).toBeVisible()
}
test('test_notification_panel_day_group_and_pagination', async ({ page }) => {
/**
* 打开日历并等入场动画落定。
*
* 两件事必须先做对,否则读数全是假的:
* ① 弹层节点是常驻的(Element 用 v-show),未打开时它也在 DOM 里、rect 全 0,
* 所以 `toBeAttached()` 不能当「已打开」的判据;
* ② 打开瞬间 el-zoom-in-top 把弹层 scaleY 压到 0,格子坐标整体贴到面板顶部,
* 此时做命中测试会把「动画中」读成「被面板遮挡」。
*/
async function openCalendar(page: Page) {
await page.locator('.bell-panel .bell-date-picker').click()
const popper = page.locator('.bell-date-popper')
await expect(popper).toBeVisible()
await page.waitForFunction(() => {
const pop = document.querySelector('.bell-date-popper')
if (!pop) return false
const style = getComputedStyle(pop)
return style.transform === 'none' && style.opacity === '1' && pop.getBoundingClientRect().height > 0
})
return popper
}
test('test_notification_panel_groups_and_pagination', async ({ page }) => {
await openBell(page)
const panel = page.locator('.bell-panel')
const nextPage = panel.getByRole('button', { name: '下一页' })
// 每页 10 条,跨两个日期分组,页脚显示页码与总数
await expect(page.locator('.bell-item')).toHaveCount(10)
// 一页 6 组:09-13 的 4 组 + 09-12 的 2 组 ⇒ 日期头 2 个(同一天可以多组)
await expect(page.locator('.bell-group')).toHaveCount(6)
await expect(page.locator('.bell-day-head')).toHaveCount(2)
await expect(page.locator('.bell-page-info')).toHaveText('1 / 2')
await expect(page.locator('.bell-page-total')).toHaveText('共 14 条')
await expect(page.locator('.bell-day-head').first()).toHaveText(/^(今天|昨天|\d{4}年\d{1,2}月\d{1,2}日)$/)
await expect(page.locator('.bell-page-info')).toHaveText('1 / 2')
await expect(page.locator('.bell-page-total')).toHaveText('共 10 组 · 明细 14 条')
// 聚合行必须把"折叠前几条、其中几条没读"写在行上
await expect(page.locator('.bell-group-count').first()).toHaveText('1 条 · 1 未读')
const page2Request = page.waitForRequest(
(request) => request.url().includes('/api/admin/notifications?') && request.url().includes('page=2'),
(request) => request.url().includes('/api/admin/notifications/groups?') && request.url().includes('page=2'),
)
await nextPage.click()
await page2Request
await expect(page.locator('.bell-item')).toHaveCount(4)
await expect(page.locator('.bell-group')).toHaveCount(4)
await expect(page.locator('.bell-page-info')).toHaveText('2 / 2')
await expect(page.locator('.bell-day-head')).toHaveCount(1)
await expect(nextPage).toBeDisabled()
})
@@ -45,37 +85,129 @@ test('test_notification_panel_search_by_keyword', async ({ page }) => {
await page.locator('.bell-search-input').fill('余额不足')
await keywordRequest
// 关键字命中标题/内容:夹具里 5 条含「余额不足」
await expect(page.locator('.bell-item')).toHaveCount(5)
await expect(page.locator('.bell-page-total')).toHaveText('共 5 条')
// 关键字命中标题/内容:夹具里 5 条含「余额不足」,且分属 5 个不同的组
await expect(page.locator('.bell-group')).toHaveCount(5)
await expect(page.locator('.bell-page-total')).toHaveText('共 5 组 · 明细 5 条')
await expect(page.locator('.bell-search-reset')).toBeVisible()
await page.locator('.bell-search-reset').click()
await expect(page.locator('.bell-item')).toHaveCount(10)
// 重置回到面板的默认视图:清空关键字、日期恢复「当天」(当天不是清空日期)
await expect(page.locator('.bell-search-input')).toHaveValue('')
await expect(page.locator('.bell-search-reset')).toBeHidden()
await expect(page.locator('.bell-empty')).toHaveText('暂无通知')
})
/** 红点按**组数**亮:3 条未读落在 2 个组里,徽标就是 2 而不是 3。 */
test('test_notification_panel_badge_counts_groups_not_rows', async ({ page }) => {
await page.goto('/admin-vue/')
await expect(page.locator('.admin-notification-bell .bell-badge')).toHaveText('2')
})
test('test_notification_panel_expand_group_loads_that_group_only', async ({ page }) => {
await openBell(page)
const groups = page.locator('.bell-group')
await expect(groups).toHaveCount(6)
const firstDetailRequest = page.waitForRequest((request) => {
const url = new URL(request.url())
return (
url.pathname.endsWith('/api/admin/notifications') &&
url.searchParams.get('scene') === 'secret_balance' &&
url.searchParams.get('day') === '2026-09-13' &&
url.searchParams.get('subjectUserId') === '1196'
)
})
await groups.first().click()
await firstDetailRequest
await expect(page.locator('.bell-item--detail')).toHaveCount(1)
await expect(page.locator('.bell-group--open')).toHaveCount(1)
// 换一组展开:上一组的明细必须收掉,不能两组明细叠在一起
const secondDetailRequest = page.waitForRequest((request) => {
const url = new URL(request.url())
return (
url.pathname.endsWith('/api/admin/notifications') &&
url.searchParams.get('scene') === 'task_failed' &&
url.searchParams.get('subjectUserId') === '1196'
)
})
await groups.nth(1).click()
await secondDetailRequest
await expect(page.locator('.bell-item--detail')).toHaveCount(2)
await expect(page.locator('.bell-group--open')).toHaveCount(1)
// 再点一次收起
await groups.nth(1).click()
await expect(page.locator('.bell-item--detail')).toHaveCount(0)
})
test('test_notification_panel_date_popper_not_covered_by_panel', async ({ page }) => {
await openBell(page)
await openCalendar(page)
// 日历与通知面板同为挂在 body 上的浮层:逐格做命中测试,最上层必须还是日历自己。
// 通知面板 z-index 3200 高于 Element 默认弹层段(自 2000 递增)时,日历整块被压在
// 面板底下,用户看到的就是「日期点不动」——这里必须判红而不是靠肉眼发现。
const covered = await page.evaluate(() => {
const pop = document.querySelector('.bell-date-popper') as HTMLElement
const panel = document.querySelector('.bell-panel') as HTMLElement
const blocked: string[] = []
for (const cell of Array.from(pop.querySelectorAll<HTMLTableCellElement>('td.available'))) {
const rect = cell.getBoundingClientRect()
if (rect.bottom > window.innerHeight || rect.right > window.innerWidth) continue
const hit = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)
if (!hit || !pop.contains(hit)) blocked.push(String(hit?.className ?? hit?.tagName ?? 'null'))
}
return { blocked, popperZ: getComputedStyle(pop).zIndex, panelZ: getComputedStyle(panel).zIndex }
})
expect(covered.blocked, `日历被通知面板遮挡(popper=${covered.popperZ},panel=${covered.panelZ})`).toEqual([])
})
/** 把左栏翻到 2026 年 9 月,返回按日取格的点击器(夹具:09-10 四条、09-12 四条、09-13 六条)。 */
async function openRangeOnSeptember(page: Page) {
const popper = await openCalendar(page)
await popper.locator('.el-picker-panel__icon-btn.arrow-left').click()
const leftPanel = popper.locator('.el-date-range-picker__content').first()
const day = (text: string) =>
leftPanel.locator('td.available .el-date-table-cell__text', { hasText: new RegExp(`^${text}$`) })
await expect(day('10')).toBeVisible()
return day
}
test('test_notification_panel_search_by_day_range', async ({ page }) => {
await openBell(page)
const day = await openRangeOnSeptember(page)
// 09-10 四条折成 3 组(两个用户 × 两个场景组合)
const rangeRequest = page.waitForRequest(
(request) =>
request.url().includes('startDate=2026-09-12') && request.url().includes('endDate=2026-09-12'),
request.url().includes('startDate=2026-09-10') && request.url().includes('endDate=2026-09-12'),
)
await page.locator('.bell-date-input').first().fill('2026-09-12')
await page.locator('.bell-date-input').nth(1).fill('2026-09-12')
await day('10').click()
await day('12').click()
await rangeRequest
await expect(page.locator('.bell-item')).toHaveCount(4)
await expect(page.locator('.bell-day-head')).toHaveCount(1)
await expect(page.locator('.bell-page-total')).toHaveText('共 4 条')
await expect(page.locator('.bell-page-total')).toHaveText('共 6 组 · 明细 8 条')
await expect(page.locator('.bell-day-head')).toHaveCount(2)
await expect(page.locator('.bell-empty')).toHaveCount(0)
// 选完区间后面板必须还开着:日历挂在 body 上,不能被「点击外部关闭」当成面板外
await expect(page.locator('.bell-panel')).toBeVisible()
})
// 起止倒挂自动交换:09-13 起 / 09-10 止 → 实际按 09-10 ~ 09-13 查询(全量 14 条)
await page.locator('.bell-date-input').first().fill('2026-09-13')
await page.locator('.bell-date-input').nth(1).fill('2026-09-10')
await expect(page.locator('.bell-page-total')).toHaveText('共 14 条')
await expect(page.locator('.bell-item')).toHaveCount(10)
test('test_notification_panel_day_range_picked_backwards', async ({ page }) => {
await openBell(page)
const day = await openRangeOnSeptember(page)
// 先点 13 再点 10:控件自己保证起 ≤ 止,落到 09-10 ~ 09-13(全量 14 条 / 10 组)
const swappedRequest = page.waitForRequest(
(request) =>
request.url().includes('startDate=2026-09-10') && request.url().includes('endDate=2026-09-13'),
)
await day('13').click()
await day('10').click()
await swappedRequest
await expect(page.locator('.bell-page-total')).toHaveText('共 10 组 · 明细 14 条')
})
test('test_notification_panel_not_covered_by_page_content', async ({ page }) => {
@@ -102,21 +234,47 @@ test('test_notification_panel_not_covered_by_page_content', async ({ page }) =>
test('test_notification_panel_reference_screenshot', async ({ page }) => {
await openBell(page)
// 同日多条不得重叠:逐条校验纵向排布严格递增(截图伪影与真实布局问题的分界)
const tops = await page
.locator('.bell-item')
.locator('.bell-group')
.evaluateAll((els) => els.map((el) => el.getBoundingClientRect().top))
for (let i = 1; i < tops.length; i += 1) {
expect(tops[i], `第 ${i + 1} 条应排在第 ${i} 条下方`).toBeGreaterThan(tops[i - 1])
expect(tops[i], `第 ${i + 1} 组应排在第 ${i} 组下方`).toBeGreaterThan(tops[i - 1])
}
await page.screenshot({ path: 'test-results/notification-panel-admin-page.jpg', animations: 'disabled' })
await page.locator('.bell-panel').screenshot({ path: 'test-results/notification-panel-admin.jpg', animations: 'disabled' })
await page.locator('.bell-search-input').fill('余额不足')
await expect(page.locator('.bell-item')).toHaveCount(5)
await page.locator('.bell-panel').screenshot({
path: 'test-results/notification-panel-admin-search.jpg',
path: 'test-results/notification-panel-admin-groups.jpg',
animations: 'disabled',
})
await page.locator('.bell-group').first().click()
await expect(page.locator('.bell-item--detail')).toHaveCount(1)
await page.locator('.bell-panel').screenshot({
path: 'test-results/notification-panel-admin-expanded.jpg',
animations: 'disabled',
})
})
/**
* 已读只能进明细逐条点(口径见设计):组内未读清零,红点才掉一格。
*/
test('test_notification_panel_mark_read_from_detail_drops_group_last', async ({ page }) => {
await openBell(page)
const group = page.locator('.bell-group').nth(1)
await expect(group.locator('.bell-group-count')).toHaveText('2 条 · 2 未读')
await group.click()
await expect(page.locator('.bell-item--detail')).toHaveCount(2)
// 每次点的都必须是「还红着」的那条:已读行点了不做事(onItemClick 直接 return),
// 拿 .first() 连点两次会第二次点到刚读过的那条,看着像"没扣数"。
const unread = page.locator('.bell-item--detail.bell-item--unread')
await unread.first().click()
await expect(unread).toHaveCount(1)
await expect(group.locator('.bell-group-count')).toHaveText('2 条 · 1 未读')
// 还剩一条未读 ⇒ 这一组仍计为一个未读组,红点不动
await expect(page.locator('.admin-notification-bell .bell-badge')).toHaveText('2')
await unread.first().click()
await expect(unread).toHaveCount(0)
await expect(group.locator('.bell-group-count')).toHaveText('2 条')
await expect(page.locator('.admin-notification-bell .bell-badge')).toHaveText('1')
})