-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathsidebar.test.mjs
More file actions
66 lines (55 loc) · 1.94 KB
/
sidebar.test.mjs
File metadata and controls
66 lines (55 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { buildSideBarGroups } from '../sidebar.mjs';
describe('buildSideBarGroups', () => {
it('groups entries by category and preserves insertion order', () => {
const frontmatter = [
{ label: 'FS', link: '/api/fs.html', category: 'File System' },
{ label: 'HTTP', link: '/api/http.html', category: 'Networking' },
{ label: 'Path', link: '/api/path.html', category: 'File System' },
];
const result = buildSideBarGroups(frontmatter);
assert.deepStrictEqual(result, [
{
groupName: 'File System',
items: [
{ label: 'FS', link: '/api/fs.html' },
{ label: 'Path', link: '/api/path.html' },
],
},
{
groupName: 'Networking',
items: [{ label: 'HTTP', link: '/api/http.html' }],
},
]);
});
it('puts entries without category into an Others group at the end by default', () => {
const frontmatter = [
{ label: 'Buffer', link: '/api/buffer.html', category: 'Binary' },
{ label: 'Unknown', link: '/api/unknown.html' },
{ label: 'Config', link: '/api/config.html', category: '' },
];
const result = buildSideBarGroups(frontmatter);
assert.equal(result.at(-1).groupName, 'Others');
assert.deepStrictEqual(result.at(-1).items, [
{ label: 'Unknown', link: '/api/unknown.html' },
{ label: 'Config', link: '/api/config.html' },
]);
});
it('uses a custom default group name when provided', () => {
const result = buildSideBarGroups(
[{ label: 'Unknown', link: '/api/unknown.html' }],
'General'
);
assert.deepStrictEqual(result, [
{
groupName: 'General',
items: [{ label: 'Unknown', link: '/api/unknown.html' }],
},
]);
});
it('returns an empty array when given no entries', () => {
assert.deepStrictEqual(buildSideBarGroups([]), []);
});
});