Files
jiapu/tests/pending-pages.test.js
T
2026-08-03 16:49:38 +08:00

145 lines
8.9 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-invite.html',
];
const contentPendingPages = [
'profile-data-reminders.html'
];
const pendingPages = familyPendingPages.concat(contentPendingPages);
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>'), /&lt;script&gt;/);
});
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('缺少 PC 接口契约的页面不展示静态成员、邀请或奖励数据', () => {
const reminders = read('profile-data-reminders.html');
const invite = read('profile-invite.html');
const share = read('profile-share.html');
assert.match(reminders, /当前 PC 接口未提供资料缺项提醒列表/);
assert.doesNotMatch(reminders, /鹿野 Loyel|张三|缺少出生日期/);
assert.match(invite, /当前 PC 接口未提供邀请码/);
assert.match(invite, /当前 PC 接口未提供邀请链接/);
assert.doesNotMatch(invite, /data-invite-code|data-invite-link|加载中/);
assert.match(share, /当前 PC 接口未提供分享链接或二维码/);
assert.match(share, /当前 PC 接口未提供分享记录/);
assert.match(share, /当前 PC 接口未提供收益账户或余额/);
assert.match(share, /当前 PC 接口未提供提现方式、申请或记录/);
assert.doesNotMatch(share, /data-member-overview|data-invite-link|data-withdraw(?:-form|-record)|3 人访问|1 人完成注册|加载中/);
assert.doesNotMatch(share, /data-feature-status="pending"|pending-pages\.js/);
assert.match(share, /class="module-card is-unavailable" aria-disabled="true"/);
});
test('已接入的家谱业务页面保持真实功能状态', () => {
['profile-families.html', 'profile-create-family.html', 'profile-join-family.html', 'profile-join-review.html', 'profile-family-home.html', 'profile-family-admin.html', 'profile-admin-permissions.html', 'profile-feedback.html', 'profile-services.html', 'profile-content.html', 'profile-feed.html', 'profile-feed-edit.html', 'profile-feed-detail.html', 'profile-generation.html', 'profile-tree.html', 'profile-article.html', 'profile-article-edit.html', 'profile-album.html', 'profile-album-edit.html', 'profile-album-detail.html', 'profile-video.html', 'profile-video-edit.html', 'profile-gift.html', 'profile-gift-edit.html', 'profile-ceremony.html', 'profile-ceremony-detail.html', 'profile-growth.html', 'profile-growth-edit.html', 'profile-relative.html', 'profile-relative-edit.html', 'profile-memo.html', 'profile-memo-edit.html', 'profile-merit.html', 'profile-merit-edit.html', 'profile-messages.html'].forEach((page) => {
assert.doesNotMatch(read(page), /data-feature-status="pending"/, `${page} 不应标记为待开发`);
});
assert.match(read('profile-generation.html'), /src="public\/js\/generation-pages\.js"/);
assert.match(read('profile-families.html'), /src="public\/js\/genealogy-entry-pages\.js"/);
assert.match(read('profile-create-family.html'), /src="public\/js\/genealogy-entry-pages\.js"/);
assert.match(read('profile-join-family.html'), /src="public\/js\/join-pages\.js"/);
assert.match(read('profile-join-review.html'), /src="public\/js\/join-review-pages\.js"/);
assert.match(read('profile-feedback.html'), /src="public\/js\/feedback-pages\.js"/);
assert.match(read('profile-services.html'), /src="public\/js\/vip-pages\.js"/);
assert.match(read('profile-family-home.html'), /src="public\/js\/family-home-pages\.js"/);
assert.match(read('profile-tree.html'), /src="public\/js\/lineage-pages\.js"/);
assert.match(read('profile-family-admin.html'), /src="public\/js\/member-admin-pages\.js"/);
assert.doesNotMatch(read('profile-admin-permissions.html'), /src="public\/js\/pending-pages\.js"/);
assert.match(read('profile-admin-permissions.html'), /href="profile-family-admin\.html" data-genealogy-context-link/);
assert.match(read('profile-join-review.html'), /href="profile-admin-permissions\.html" data-genealogy-context-link/);
assert.match(read('profile-article.html'), /src="public\/js\/article-pages\.js"/);
assert.match(read('profile-article-edit.html'), /src="public\/js\/article-pages\.js"/);
assert.match(read('profile-album.html'), /src="public\/js\/album-pages\.js"/);
assert.match(read('profile-album-edit.html'), /src="public\/js\/album-pages\.js"/);
assert.match(read('profile-album-detail.html'), /src="public\/js\/album-pages\.js"/);
assert.match(read('profile-video.html'), /src="public\/js\/video-pages\.js"/);
assert.match(read('profile-video-edit.html'), /src="public\/js\/video-pages\.js"/);
assert.match(read('profile-gift.html'), /src="public\/js\/ceremony-pages\.js"/);
assert.match(read('profile-gift-edit.html'), /src="public\/js\/ceremony-admin-pages\.js"/);
assert.match(read('profile-ceremony.html'), /src="public\/js\/ceremony-admin-pages\.js"/);
assert.match(read('profile-ceremony-detail.html'), /src="public\/js\/ceremony-admin-pages\.js"/);
assert.match(read('profile-growth.html'), /src="public\/js\/growth-pages\.js"/);
assert.match(read('profile-growth-edit.html'), /src="public\/js\/growth-pages\.js"/);
assert.match(read('profile-relative.html'), /src="public\/js\/relative-pages\.js"/);
assert.match(read('profile-relative-edit.html'), /src="public\/js\/relative-pages\.js"/);
assert.match(read('profile-memo.html'), /src="public\/js\/memo-pages\.js"/);
assert.match(read('profile-merit.html'), /src="public\/js\/merit-pages\.js"/);
assert.match(read('profile-merit-edit.html'), /src="public\/js\/merit-pages\.js"/);
assert.match(read('profile-messages.html'), /src="public\/js\/notification-pages\.js"/);
assert.match(read('profile-memo-edit.html'), /src="public\/js\/memo-pages\.js"/);
});
test('待开发的家谱管理页明确放行已接入的字辈入口并透传上下文', () => {
const familyAdmin = read('profile-family-admin.html');
const profileCommon = read('public/js/profile-common.js');
assert.match(familyAdmin, /href="profile-generation\.html" data-feature-link="available" data-genealogy-context-link/);
assert.match(profileCommon, /function syncGenealogyContextLinks\(\)/);
assert.match(profileCommon, /params\.set\('genealogyId', genealogyId\)/);
});
test('待开发页面仅放行显式标记的可用功能入口', () => {
assert.equal(PageAvailability.shouldBlockLink(createLink({ href: 'profile-invite.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('待开发邀请页允许返回已接入的成员管理', () => {
const invite = read('profile-invite.html');
assert.match(invite, /href="profile-family-admin\.html"[^>]*data-feature-link="available"[^>]*data-genealogy-context-link/);
assert.equal(PageAvailability.shouldBlockLink(createLink({
href: 'profile-family-admin.html',
'data-feature-link': 'available'
})), false);
});
test('内容入口明确保留家族圈动态跳转', () => {
assert.match(read('profile-content.html'), /href="profile-feed\.html" data-feature-link="available"/);
assert.match(read('profile-content.html'), /href="profile-growth\.html" data-feature-link="available" data-genealogy-context-link/);
assert.match(read('profile-content.html'), /href="profile-relative\.html" data-feature-link="available" data-genealogy-context-link/);
assert.match(read('profile-content.html'), /href="profile-memo\.html" data-feature-link="available" data-genealogy-context-link/);
assert.match(read('profile-content.html'), /href="profile-merit\.html" data-feature-link="available" data-genealogy-context-link/);
});
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} 不应标记为待开发`);
});
});