update-search-sensitivity
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 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 | }) |