99 lines
3.3 KiB
JavaScript
99 lines
3.3 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const PageAvailability = require('../public/js/pending-pages.js');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const familyPendingPages = [
|
|
'profile-families.html',
|
|
'profile-create-family.html',
|
|
'profile-join-family.html',
|
|
'profile-join-review.html',
|
|
'profile-family-admin.html',
|
|
'profile-invite.html',
|
|
'profile-tree.html',
|
|
'profile-generation.html'
|
|
];
|
|
|
|
const contentPendingPages = [
|
|
'profile-content.html',
|
|
'profile-article.html',
|
|
'profile-article-edit.html',
|
|
'profile-album.html',
|
|
'profile-video.html',
|
|
'profile-gift.html',
|
|
'profile-gift-edit.html',
|
|
'profile-growth.html',
|
|
'profile-growth-edit.html',
|
|
'profile-memo.html',
|
|
'profile-memo-edit.html',
|
|
'profile-merit.html',
|
|
'profile-merit-edit.html',
|
|
'profile-messages.html',
|
|
'profile-feedback.html',
|
|
'profile-admin-permissions.html',
|
|
'profile-data-reminders.html'
|
|
];
|
|
|
|
const residualPendingPages = [
|
|
'profile-family-home.html',
|
|
'profile-share.html',
|
|
'profile-services.html'
|
|
];
|
|
|
|
const pendingPages = familyPendingPages.concat(contentPendingPages, residualPendingPages);
|
|
|
|
function read(relativePath) {
|
|
return fs.readFileSync(path.join(root, relativePath), 'utf8');
|
|
}
|
|
|
|
function createLink(attributes) {
|
|
return {
|
|
getAttribute(name) {
|
|
return Object.prototype.hasOwnProperty.call(attributes, name) ? attributes[name] : null;
|
|
}
|
|
};
|
|
}
|
|
|
|
test('待开发页面生成明确且转义后的状态提示', () => {
|
|
assert.match(PageAvailability.buildBanner('家谱基础服务正在开发中'), /家谱基础服务正在开发中/);
|
|
assert.match(PageAvailability.buildBanner('<script>'), /<script>/);
|
|
});
|
|
|
|
test('待开发页面显式加载状态脚本', () => {
|
|
pendingPages.forEach((page) => {
|
|
const source = read(page);
|
|
|
|
assert.match(source, /data-feature-status="pending"/, `${page} 缺少待开发状态标记`);
|
|
assert.match(source, /src="public\/js\/pending-pages\.js"/, `${page} 未加载状态脚本`);
|
|
});
|
|
});
|
|
|
|
test('家族圈动态页面保持真实功能状态', () => {
|
|
['profile-feed.html', 'profile-feed-edit.html'].forEach((page) => {
|
|
assert.doesNotMatch(read(page), /data-feature-status="pending"/, `${page} 不应标记为待开发`);
|
|
});
|
|
});
|
|
|
|
test('待开发页面仅放行显式标记的可用功能入口', () => {
|
|
assert.equal(PageAvailability.shouldBlockLink(createLink({ href: 'profile-article.html' })), true);
|
|
assert.equal(PageAvailability.shouldBlockLink(createLink({ href: 'profile-feed.html', 'data-feature-link': 'available' })), false);
|
|
assert.equal(PageAvailability.shouldBlockLink(createLink({ href: '#section' })), false);
|
|
});
|
|
|
|
test('内容入口明确保留家族圈动态跳转', () => {
|
|
assert.match(read('profile-content.html'), /href="profile-feed\.html" data-feature-link="available"/);
|
|
});
|
|
|
|
test('家谱主页明确保留家族圈动态跳转', () => {
|
|
assert.match(read('profile-family-home.html'), /href="profile-feed\.html" data-feature-link="available"/);
|
|
});
|
|
|
|
test('账号闭环页面保持真实功能状态', () => {
|
|
['profile.html', 'profile-data.html', 'profile-security.html'].forEach((page) => {
|
|
assert.doesNotMatch(read(page), /data-feature-status="pending"/, `${page} 不应标记为待开发`);
|
|
});
|
|
});
|