'use strict'; 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('profile comments follow the author-page row and moderation contract', () => { const panel = read('templates/parts/user-home/panel-comments.php'); const item = read('templates/parts/content-profile-comment-item.php'); const dashboard = read('inc/helpers/aksrt-user-dashboard.php'); const userCenter = read('inc/helpers/user-center-renderers/profile-comments.php'); const styles = read('assets/css/routes/profile/lists.css'); assert.match(panel, /\$comment_status\s*=\s*\$is_own_profile\s*\?\s*'all'\s*:\s*'approve'/); assert.match(panel, /'type'\s*=>\s*'comment'/); assert.match(panel, /'post_type'\s*=>\s*\['post'\]/); assert.match(panel, /'count'\s*=>\s*true/); assert.match(panel, /data-uh-comments-next=/); assert.match(panel, /<\?php else : \?>\s*<\?php aksrt_render_profile_empty\(/); assert.doesNotMatch(panel, /aksrt_render_user_home_pagination/); assert.match(dashboard, /'type'\s*=>\s*'comment'[\s\S]*?'post_type'\s*=>\s*\['post'\]/); assert.match(userCenter, /'type'\s*=>\s*'comment'[\s\S]*?'post_type'\s*=>\s*\['post'\]/); assert.match(item, /profile-comment-item__time/); assert.match(item, /profile-comment-item__content text-ellipsis-5/); assert.match(item, /comment_approved\s*===\s*'0'[\s\S]*?待审核/); assert.match(item, /get_comment\(\(int\) \$comment->comment_parent\)/); assert.match(item, /preg_replace_callback\([\s\S]*?target=_blank[\s\S]*?rel="noopener noreferrer"/); assert.match(item, /评论于:/); assert.match(item, /esc_url\(\$comment_link\)/); assert.match(item, /esc_url\(\$post_link\)/); assert.match(styles, /\.profile-comment-item__time\s*\{[^}]*flex:\s*0 0 20%;[^}]*margin-right:\s*20px;[^}]*text-align:\s*right;/s); assert.match(styles, /\.profile-comment-item__body\s*\{[^}]*width:\s*calc\(80% - 25px\)/s); assert.match(styles, /@media \(min-width: 992px\)\s*\{\s*\.profile-comment-list\s*\{[^}]*display:\s*grid;[^}]*grid-template-columns:\s*repeat\(2,\s*minmax\(0,\s*1fr\)\);[^}]*\}[^}]*\.profile-comment-item\s*\{[^}]*margin:\s*8px;/s); assert.match(styles, /\.profile-comment-item__content\s*\{[^}]*-webkit-line-clamp:\s*5;/s); assert.match(styles, /@media \(max-width: 640px\)[\s\S]*?\.profile-comment-item\s*\{\s*padding:\s*10px 0;/); assert.doesNotMatch(styles, /profile-comment-item__(?:quote|meta)/); }); test('public comment load-more appends REST fragments and retains retry on errors', () => { const runtime = read('assets/js/author.js'); const rest = read('src/User/Home.php'); assert.match(runtime, /function appendCommentPage\(panel, html\)/); assert.match(runtime, /currentList\.appendChild\(item\)/); assert.match(runtime, /incomingMore && currentList/); assert.match(runtime, /data-uh-comments-next/); assert.match(runtime, /trigger\.disabled = true/); assert.match(runtime, /trigger\.disabled = false/); assert.match(runtime, /trigger\.textContent = '加载更多'/); assert.match(runtime, /panel\.innerHTML = payload\.data\.html/); assert.ok(rest.includes("'/user-home/panel/(?P\\d+)/(?P[a-z0-9_-]+)'")); });