78 lines
3.7 KiB
JavaScript
78 lines
3.7 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 center exposes only the four canonical parameter-free routes', () => {
|
|
const routing = read('inc/modules/user-parts/routing.php');
|
|
const urls = read('inc/modules/user-parts/urls.php');
|
|
const registry = read('inc/modules/user-parts/template-registry.php');
|
|
|
|
assert.match(routing, /add_rewrite_rule\('\^message\/\?\$',[\s\S]*?aksrt_message_view=unread/);
|
|
assert.match(routing, /add_rewrite_rule\('\^message\/\(posts\|like\|system\)\/\?\$'/);
|
|
assert.doesNotMatch(routing, /message\/\(\[0-9]|aksrt_message_id/);
|
|
for (const route of ['/message/', '/message/posts/', '/message/like/', '/message/system/']) {
|
|
assert.ok(urls.includes(route), `${route} should be canonical`);
|
|
}
|
|
const messageUrlFunction = urls.slice(
|
|
urls.indexOf('function aksrt_get_messages_page_url'),
|
|
urls.indexOf('endif;', urls.indexOf('function aksrt_get_messages_page_url')),
|
|
);
|
|
assert.doesNotMatch(messageUrlFunction, /add_query_arg|\/messages\//);
|
|
assert.doesNotMatch(registry, /'messages'\s*=>/);
|
|
assert.match(registry, /page-messages\.php'\)\s*\{[\s\S]*?return ''/);
|
|
assert.match(routing, /get_page_template_slug[\s\S]*?page-messages\.php[\s\S]*?set_404/);
|
|
});
|
|
|
|
test('tabs, pagination, actions, and detail all replace DOM fragments', () => {
|
|
const center = read('inc/modules/message-center.php');
|
|
const script = read('assets/js/messages.js');
|
|
const template = read('templates/pages/page-messages.php');
|
|
|
|
for (const label of ['未读消息', '文章评论', '点赞喜欢', '系统通知']) {
|
|
assert.ok(center.includes(label));
|
|
}
|
|
assert.match(center, /wp_ajax_aksrt_load_message_center/);
|
|
assert.match(center, /aksrt_render_message_center_detail/);
|
|
assert.match(template, /data-message-content/);
|
|
assert.match(script, /nav\.innerHTML = result\.data\.nav/);
|
|
assert.match(script, /content\.innerHTML = result\.data\.content/);
|
|
assert.match(script, /\.js-msg-detail/);
|
|
assert.match(script, /data-message-back/);
|
|
assert.doesNotMatch(script, /searchParams|msg_type|msg_page|location\.href\s*=/);
|
|
assert.doesNotMatch(script, /pushState\([^\n]+detail/);
|
|
});
|
|
|
|
test('asset notifications are absent and interaction notification hooks are present', () => {
|
|
const notifications = read('inc/modules/user-notifications.php');
|
|
const settings = read('src/Settings/Integration.php');
|
|
const adminSettings = read('assets/admin/src/pages/content/NotificationCenterSettings.vue');
|
|
const messageAdmin = read('assets/admin/src/pages/users/UsersMessages.vue');
|
|
const combined = [notifications, settings, adminSettings, messageAdmin].join('\n');
|
|
|
|
for (const retired of [
|
|
'asset_points_increase',
|
|
'asset_points_decrease',
|
|
'asset_balance_increase',
|
|
'asset_balance_decrease',
|
|
]) {
|
|
assert.equal(combined.includes(retired), false, `${retired} should be absent`);
|
|
}
|
|
assert.doesNotMatch(notifications, /add_action\('aksrt_asset_transaction_committed'/);
|
|
for (const hook of ['aksrt_post_favorited', 'aksrt_post_liked', 'aksrt_comment_liked', 'aksrt_user_followed']) {
|
|
assert.ok(notifications.includes(`add_action('${hook}'`));
|
|
}
|
|
});
|
|
|
|
test('notification storage has no message-center legacy metadata fallback', () => {
|
|
const notifications = read('inc/modules/user-notifications.php');
|
|
const service = read('src/Messages/Message.php');
|
|
const combined = `${notifications}\n${service}`;
|
|
|
|
assert.doesNotMatch(combined, /aksrt_notifications|aksrt_unread_message_count/);
|
|
assert.doesNotMatch(combined, /legacy|兼容|降级/i);
|
|
});
|