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

44 lines
1.4 KiB
JavaScript
Raw 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, generateHTML } = 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子菜单锚点应使用分类 slughref + data-category-id', () => {
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: [] },
],
},
};
const html = generateHTML(config);
assert.ok(html.includes('class="submenu-item"'), '应输出子菜单项');
assert.ok(html.includes('href="#重复-分类"'), '子菜单 href 应指向 slug');
assert.ok(html.includes('data-category-id="重复-分类"'), '子菜单应携带 data-category-id');
});
});