Files
menav/test/category-slug-dedup.node-test.js
rbetree 48609b86de feat: 分类锚点&质量检查&依赖治理
- 分类生成唯一 slug,模板/子菜单/滚动/扩展定位统一使用 data-id
- lint 覆盖 src/scripts/test,CI 增量格式检查
- 清理冗余依赖,升级 esbuild,overrides 修复审计项
- 补充单测并更新修复清单
2026-01-04 20:39:42 +08:00

49 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const { loadHandlebarsTemplates, generateAllPagesHTML } = require('../src/generator.js');
function withRepoRoot(fn) {
const originalCwd = process.cwd();
process.chdir(path.join(__dirname, '..'));
try {
return fn();
} finally {
process.chdir(originalCwd);
}
}
test('P1-2分类 slug 应稳定且可去重', () => {
withRepoRoot(() => {
loadHandlebarsTemplates();
const config = {
site: { title: 'Test Site', description: '', author: '', favicon: '', logo_text: 'Test' },
profile: { title: 'PROFILE_TITLE', subtitle: 'PROFILE_SUBTITLE' },
social: [],
navigation: [{ id: 'home', name: '首页', icon: 'fas fa-home' }],
home: {
title: 'HOME',
subtitle: 'HOME_SUB',
template: 'page',
categories: [
{ name: '重复 分类', icon: 'fas fa-tag', sites: [] },
{ name: '重复 分类', icon: 'fas fa-tag', sites: [] },
{ name: '含 空格/特殊#字符', icon: 'fas fa-tag', sites: [] },
],
},
};
const pages = generateAllPagesHTML(config);
assert.ok(typeof pages.home === 'string' && pages.home.length > 0);
assert.ok(pages.home.includes('id="重复-分类"'), '首个重复分类应生成稳定 slug');
assert.ok(pages.home.includes('id="重复-分类-2"'), '重复分类应通过后缀去重');
assert.ok(pages.home.includes('id="含-空格-特殊-字符"'), '空格/特殊字符应被规范化为可用 slug');
assert.ok(pages.home.includes('data-id="重复-分类"'));
assert.ok(pages.home.includes('data-id="重复-分类-2"'));
});
});