Files
jiapu/tests/pending-pages.test.js
T
fizzleaf fb1743aa2a feat(api): 完善家谱系统API客户端契约
- 实现家谱管理相关方法,包括创建、详情、概览、我的家谱和选项查询
- 添加家谱加入申请功能,支持申请、审核、取消和待审核列表操作
- 集成通知详情获取方法和通知ID安全验证机制
- 完善功德记录、谱文、相册、视频、祭祀活动的完整CRUD操作契约
- 实现家谱成员管理功能,包含成员列表、更新、移除和转让所有者操作
- 优化路径ID验证逻辑,拒绝不安全的数值ID并提供明确错误提示
- 更新测试用例以验证所有新增API方法的路径和请求体白名单机制
2026-07-29 16:57:27 +08:00

118 lines
6.6 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-join-family.html',
'profile-join-review.html',
'profile-invite.html',
];
const contentPendingPages = [
'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>'), /&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('已接入的家谱业务页面保持真实功能状态', () => {
['profile-families.html', 'profile-create-family.html', 'profile-family-admin.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-tree.html'), /src="public\/js\/lineage-pages\.js"/);
assert.match(read('profile-family-admin.html'), /src="public\/js\/member-admin-pages\.js"/);
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-feedback.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"/);
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} 不应标记为待开发`);
});
});