Files
menav/test/home-page-profile-override.node-test.js
2026-01-04 21:07:07 +08:00

71 lines
2.7 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, generateAllPagesHTML } = require('../src/generator.js');
test('首页navigation 第一项)应使用 profile 覆盖 title/subtitle 显示', () => {
const originalCwd = process.cwd();
process.chdir(path.join(__dirname, '..'));
try {
loadHandlebarsTemplates();
const config = {
site: { title: 'Test Site', description: '', author: '', favicon: '', logo_text: 'Test' },
profile: { title: 'PROFILE_TITLE', subtitle: 'PROFILE_SUBTITLE' },
social: [],
navigation: [
{ id: 'bookmarks', name: '书签', icon: 'fas fa-bookmark' },
{ id: 'home', name: '首页', icon: 'fas fa-home' },
{ id: 'projects', name: '项目', icon: 'fas fa-project-diagram' },
],
bookmarks: {
title: '书签页标题',
subtitle: '书签页副标题',
template: 'bookmarks',
categories: [],
},
home: {
title: 'HOME_PAGE_TITLE',
subtitle: 'HOME_PAGE_SUBTITLE',
template: 'page',
categories: [],
},
projects: {
title: '项目页标题',
subtitle: '项目页副标题',
template: 'projects',
categories: [],
},
};
const pages = generateAllPagesHTML(config);
assert.ok(typeof pages.bookmarks === 'string' && pages.bookmarks.length > 0);
assert.ok(pages.bookmarks.includes('PROFILE_TITLE'));
assert.ok(pages.bookmarks.includes('PROFILE_SUBTITLE'));
assert.ok(pages.bookmarks.includes('data-editable="profile-title"'));
assert.ok(pages.bookmarks.includes('data-editable="profile-subtitle"'));
assert.ok(pages.bookmarks.includes('<h3'));
assert.ok(!pages.bookmarks.includes('书签页标题'));
assert.ok(!pages.bookmarks.includes('书签页副标题'));
assert.ok(!pages.bookmarks.includes('data-editable="page-title"'));
assert.ok(typeof pages.home === 'string' && pages.home.length > 0);
assert.ok(pages.home.includes('HOME_PAGE_TITLE'));
assert.ok(pages.home.includes('HOME_PAGE_SUBTITLE'));
assert.ok(pages.home.includes('data-editable="page-title"'));
assert.ok(pages.home.includes('data-editable="page-subtitle"'));
assert.ok(pages.home.includes('<p class="subtitle"'));
assert.ok(!pages.home.includes('PROFILE_TITLE'));
assert.ok(typeof pages.projects === 'string' && pages.projects.length > 0);
assert.ok(pages.projects.includes('项目页标题'));
assert.ok(pages.projects.includes('项目页副标题'));
assert.ok(pages.projects.includes('<p class="subtitle"'));
} finally {
process.chdir(originalCwd);
}
});