1 import {flattenHeadings} from '../use-search'
2
3 describe('flattenHeadings', () => {
4 test('returns empty array for null/undefined input', () => {
5 expect(flattenHeadings(null)).toEqual([])
6 expect(flattenHeadings(undefined)).toEqual([])
7 })
8
9 test('returns empty array for empty items', () => {
10 expect(flattenHeadings([])).toEqual([])
11 })
12
13 test('flattens single level of headings', () => {
14 const items = [{title: 'Description'}, {title: 'Configuration'}]
15 expect(flattenHeadings(items)).toEqual(['Description', 'Configuration'])
16 })
17
18 test('flattens nested headings', () => {
19 const items = [
20 {
21 title: 'Description',
22 items: [{title: 'before'}, {title: 'min-release-age'}],
23 },
24 ]
25 expect(flattenHeadings(items)).toEqual(['Description', 'before', 'min-release-age'])
26 })
27
28 test('flattens deeply nested headings', () => {
29 const items = [
30 {
31 title: 'Top',
32 items: [
33 {
34 title: 'Mid',
35 items: [{title: 'Deep'}],
36 },
37 ],
38 },
39 ]
40 expect(flattenHeadings(items)).toEqual(['Top', 'Mid', 'Deep'])
41 })
42
43 test('skips items without a title', () => {
44 const items = [{items: [{title: 'child'}]}, {title: 'sibling'}]
45 expect(flattenHeadings(items)).toEqual(['child', 'sibling'])
46 })
47 })