- 分类生成唯一 slug,模板/子菜单/滚动/扩展定位统一使用 data-id - lint 覆盖 src/scripts/test,CI 增量格式检查 - 清理冗余依赖,升级 esbuild,overrides 修复审计项 - 补充单测并更新修复清单
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
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:子菜单锚点应使用分类 slug(href + 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');
|
||
});
|
||
});
|