|
| 1 | +import { describe, test, expect } from 'vitest' |
| 2 | +import { getSidebar } from 'client/theme-default/support/sidebar' |
| 3 | + |
| 4 | +describe('client/theme-default/support/sidebar', () => { |
| 5 | + const root = [ |
| 6 | + { |
| 7 | + text: 'A', |
| 8 | + collapsible: true, |
| 9 | + items: [ |
| 10 | + { |
| 11 | + text: 'A', |
| 12 | + link: '' |
| 13 | + } |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + text: 'B', |
| 18 | + items: [ |
| 19 | + { |
| 20 | + text: 'B', |
| 21 | + link: '' |
| 22 | + } |
| 23 | + ] |
| 24 | + } |
| 25 | + ] |
| 26 | + const another = [ |
| 27 | + { |
| 28 | + text: 'C', |
| 29 | + items: [ |
| 30 | + { |
| 31 | + text: 'C', |
| 32 | + link: '' |
| 33 | + } |
| 34 | + ] |
| 35 | + } |
| 36 | + ] |
| 37 | + describe('normal sidebar sort', () => { |
| 38 | + const normalSidebar = { |
| 39 | + '/': root, |
| 40 | + '/multi-sidebar/': another |
| 41 | + } |
| 42 | + test('gets / sidebar', () => { |
| 43 | + expect(getSidebar(normalSidebar, '/')).toBe(root) |
| 44 | + }) |
| 45 | + test('gets /multi-sidebar/ sidebar', () => { |
| 46 | + expect(getSidebar(normalSidebar, '/multi-sidebar/')).toBe(another) |
| 47 | + }) |
| 48 | + test('gets / sidebar again', () => { |
| 49 | + expect(getSidebar(normalSidebar, '/some-entry.html')).toBe(root) |
| 50 | + }) |
| 51 | + }) |
| 52 | + describe('reversed sidebar sort', () => { |
| 53 | + const reversedSidebar = { |
| 54 | + '/multi-sidebar/': another, |
| 55 | + '/': root |
| 56 | + } |
| 57 | + test('gets / sidebar', () => { |
| 58 | + expect(getSidebar(reversedSidebar, '/')).toBe(root) |
| 59 | + }) |
| 60 | + test('gets /multi-sidebar/ sidebar', () => { |
| 61 | + expect(getSidebar(reversedSidebar, '/multi-sidebar/')).toBe(another) |
| 62 | + }) |
| 63 | + test('gets / sidebar again', () => { |
| 64 | + expect(getSidebar(reversedSidebar, '/some-entry.html')).toBe(root) |
| 65 | + }) |
| 66 | + }) |
| 67 | + describe('nested sidebar sort', () => { |
| 68 | + const nested = [ |
| 69 | + { |
| 70 | + text: 'D', |
| 71 | + items: [ |
| 72 | + { |
| 73 | + text: 'D', |
| 74 | + link: '' |
| 75 | + } |
| 76 | + ] |
| 77 | + } |
| 78 | + ] |
| 79 | + const nestedSidebar = { |
| 80 | + '/': root, |
| 81 | + '/multi-sidebar/': another, |
| 82 | + '/multi-sidebar/nested/': nested |
| 83 | + } |
| 84 | + test('gets / sidebar', () => { |
| 85 | + expect(getSidebar(nestedSidebar, '/')).toBe(root) |
| 86 | + }) |
| 87 | + test('gets /multi-sidebar/ sidebar', () => { |
| 88 | + expect(getSidebar(nestedSidebar, '/multi-sidebar/')).toBe(another) |
| 89 | + }) |
| 90 | + test('gets /multi-sidebar/nested/ sidebar', () => { |
| 91 | + expect(getSidebar(nestedSidebar, '/multi-sidebar/nested/')).toBe(nested) |
| 92 | + }) |
| 93 | + test('gets / sidebar again', () => { |
| 94 | + expect(getSidebar(nestedSidebar, '/some-entry.html')).toBe(root) |
| 95 | + }) |
| 96 | + }) |
| 97 | +}) |
0 commit comments