Files
wordpress-theme-aksrt/tests/widget-system/notification-preferences-contract.test.cjs
kate522 6f815678ec feat(frontend): replicate reference header user box 1:1
顶导航点击小人弹出的用户信息浮层,从 AKSRT 定制结构改为与参考主题 zib_header_user_box() 逐行同构:头像链接包裹、钱包双瓷砖、会员条、签到、消息图标、统计徽章行全部改用参考主题遗留类,渲染交回 main.css(.sub-user-box 242px、.avatar-img 38px、.msg-news-icon、badge.top、.payvip-icon 深色渐变加 gem 水印、.vip-expdate-tag、.muted-box)。

头像改走 aksrt_get_avatar_box(用户ID, avatar-img, true, false),得到参考的 a 链接包裹 avatar-img 结构。消息图标改参考标记 msg-news-icon abs-right 加 toggle-radius msg-icon,未读徽章用 badge.top,avatar_dropdown 位置门控契约保留。管理端行在「后台管理」前插入「支付中心」,跳 admin.php?page=aksrt_pay,即参考主题「商城中心」槽位,图标 fa-credit-card。

钱包重写为参考双瓷砖:余额在前(c-blue-2 加 fa-money-bill-wave)、积分在后(c-yellow 加 fa-coins),分别按充值开关与积分总开关门控,两块皆关则不渲染,并保留 data-aksrt-wallet-value 与 data-aksrt-points-value 两个 JS 刷新钩子。会员条去掉 AKSRT 自创的 vipbg-v2 level-N 金色背景,改参考的 payvip-icon 加 badg jb-yellow vip-expdate-tag,到期文案按参考语义分为已过期、永久会员、裸日期三种。签到入口由 button 改为 a.but block c-yellow,并去掉随之失效的 compact 形参,data-signin 挂载与 wp_footer 验证码不变。统计行删掉文章徽章(本站不做帖子),图标由 SVG sprite 换 FA5+ 的 fa-comment-dots、fa-thumbs-up、fa-fire。

会员等级图标契约不动:aksrt_get_vip_icon 与 User\Level::get_badge_html 的调用与参数保持原样。

顺带清死代码:aksrt_header_user_badges_row 原本取到函数后直接返回空串,现在真正输出统计行;删掉 header-userbox.css 里整套 bespoke 规则与 vip-modal.css 的 vipbg-v2 死规则。

显式偏差:统计行链接保持扁平用户主页 URL(AKSRT 用户主页是干净 URL 加 JS tab,没有 query tab 路由);签到入口沿用积分签到总开关门控,不新增管理端可配置项。

public.css 与 public.min.css 用 tools/build-public-assets.mjs 重建:该 bundle 打包了 header-userbox.css 且作为依赖先于单模块入队,旧的 width 260px 会压过新源码、把卡片钉在 260px 而不是参考的 242px。

验证:node --test tests/**/*.test.cjs 573 项全通过;六个改动 PHP 文件 php -l 无语法错误;卡片用到的 FA5 token 逐个核对 5.15.4 全部命中。未做真实视觉效果验收。
2026-10-10 16:17:01 +08:00

101 lines
5.1 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
test('message notification settings are a canonical user/msg inline panel', () => {
const center = read('src/User/Center.php');
const helpers = read('inc/helpers/aksrt-user-center.php');
const sidebar = read('inc/helpers/user-center-renderers/sidebar-nav.php');
const routing = read('inc/modules/user-parts/routing.php');
assert.match(center, /'msg'\s*=>\s*\[[\s\S]*?'type'\s*=>\s*'panel'/);
assert.doesNotMatch(center, /'notif'\s*=>/);
assert.match(helpers, /'msg'\s*=>\s*'msg'/);
assert.match(sidebar, /aksrt_get_user_center_tab_url\('msg'\)/);
assert.match(sidebar, /'tab'\s*=>\s*'msg'/);
assert.doesNotMatch(sidebar, /'url'\s*=>\s*\(string\) \(\$messages_url/);
assert.match(routing, /'revenue', 'msg', 'settings'/);
});
test('notification icon positions map to their four render locations', () => {
const phpSchema = read('src/Admin/Schema/SchemaUsers.php');
const jsSchema = read('assets/admin/src/schema/sections/users/notifications.js');
const integration = read('src/Settings/Integration.php');
const header = read('inc/helpers/header/aksrt-header-navbar.php');
const headerStyles = read('assets/css/frontend/header-userbox.css');
const legacyMainCss = read('assets/css/main.css');
const userCenter = read('inc/helpers/aksrt-user-center.php');
const userHome = read('templates/parts/user/author-hero.php');
for (const source of [phpSchema, jsSchema]) {
assert.match(source, /message_icon_show/);
assert.match(source, /导航菜单/);
assert.match(source, /头像下拉面板/);
assert.match(source, /用户中心顶部资料卡/);
assert.match(source, /公开主页顶部资料卡/);
}
assert.match(integration, /\['nav_menu', 'avatar_dropdown', 'user_center_header', 'user_home_header'\]/);
assert.match(header, /in_array\('nav_menu', \$positions, true\)/);
assert.match(header, /in_array\('avatar_dropdown', \$positions, true\)/);
// The card message icon uses the reference msg-news-icon markup, positioned by
// the shared legacy stylesheet instead of a bespoke popover rule.
assert.match(header, /msg-news-icon abs-right/);
assert.match(header, /toggle-radius msg-icon/);
assert.match(header, /<badge class="top">/);
assert.match(legacyMainCss, /\.sub-user-box \.msg-news-icon \{[\s\S]*?top: 0\.4em;[\s\S]*?right: 0;/);
assert.doesNotMatch(headerStyles, /\.aksrt-header-userbox \.user-info > \.abs-right/);
assert.match(header, /aksrt-nav-icon aksrt-nav-notification/);
assert.match(header, /\$notification_but \. \$sign_but \. \$search_but/);
assert.match(userCenter, /in_array\('user_center_header'/);
assert.match(userHome, /in_array\('user_home_header'/);
});
test('notification preference endpoint stores only the three boolean categories', () => {
const controller = read('src/User/NotificationPreferences.php');
assert.match(controller, /META_KEY = 'aksrt_notification_preferences'/);
assert.match(controller, /CATEGORIES = \['posts', 'like', 'system'\]/);
assert.match(controller, /register_rest_route\('aksrt\/v1', '\/user\/notification-preferences'/);
assert.match(controller, /permission_callback/);
assert.match(controller, /current_user_can\('read'\)/);
assert.match(controller, /'additionalProperties'\s*=>\s*false/);
assert.match(controller, /array_diff\(array_keys\(\$value\), self::CATEGORIES\)/);
assert.doesNotMatch(controller, /message_shield|migration|legacy/i);
});
test('notification preference UI uses the global toast lifecycle', () => {
const template = read('inc/helpers/user-center-renderers/profile-msg.php');
const script = read('assets/js/routes/user-center.js');
const styles = read('assets/css/routes/user-center/settings.css');
for (const text of [
'文章评论',
'接收文章、评论、收藏等相关消息',
'点赞喜欢',
'接收点赞、关注等相关消息',
'系统消息',
'接收订单、活动、等系统消息',
]) {
assert.ok(template.includes(text));
}
assert.match(template, /role="switch"/);
assert.match(styles, /\.uc-notification-switch input\[type='checkbox'\][\s\S]*?opacity: 0 !important/);
assert.match(styles, /\.uc-notification-switch input\[type='checkbox'\]::before,[\s\S]*?\.uc-notification-switch input\[type='checkbox'\]::after[\s\S]*?content: none !important/);
assert.match(script, /aksrt-notification-preferences-toast/);
assert.match(script, /notyf\([^;]+?'load'[^;]+?toastId/);
assert.match(script, /notyf\([^;]+?'success'[^;]+?toastId/);
assert.match(script, /notyf\([^;]+?'danger'[^;]+?toastId/);
assert.doesNotMatch(script, /\b(?:window\.)?alert\s*\(/);
});
test('notification writes and stateful alerts honor the category preference', () => {
const notifications = read('inc/modules/user-notifications.php');
assert.match(notifications, /NotificationPreferences::allows\(\$user_id, 'pending_comments'\)/);
assert.match(notifications, /NotificationPreferences::allows\(\$user_id, \$type\)/);
});