SubMenu.utils.test.ts90 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { convertSectionsToProductMenu } from './SubMenu.utils' |
| 4 | |
| 5 | describe('convertSectionsToProductMenu', () => { |
| 6 | it('converts sections with heading and links to ProductMenuGroup format', () => { |
| 7 | const sections = [ |
| 8 | { |
| 9 | key: 'configuration', |
| 10 | heading: 'Configuration', |
| 11 | links: [ |
| 12 | { key: 'general', label: 'General', href: '/org/foo/general' }, |
| 13 | { key: 'security', label: 'Security', href: '/org/foo/security' }, |
| 14 | ], |
| 15 | }, |
| 16 | ] |
| 17 | |
| 18 | const result = convertSectionsToProductMenu(sections) |
| 19 | |
| 20 | expect(result).toEqual([ |
| 21 | { |
| 22 | key: 'configuration', |
| 23 | title: 'Configuration', |
| 24 | items: [ |
| 25 | { key: 'general', name: 'General', url: '/org/foo/general' }, |
| 26 | { key: 'security', name: 'Security', url: '/org/foo/security' }, |
| 27 | ], |
| 28 | }, |
| 29 | ]) |
| 30 | }) |
| 31 | |
| 32 | it('uses # for undefined href', () => { |
| 33 | const sections = [ |
| 34 | { |
| 35 | key: 'config', |
| 36 | links: [{ key: 'item', label: 'Item' }], |
| 37 | }, |
| 38 | ] |
| 39 | |
| 40 | const result = convertSectionsToProductMenu(sections) |
| 41 | |
| 42 | expect(result[0].items[0].url).toBe('#') |
| 43 | }) |
| 44 | |
| 45 | it('handles empty sections array', () => { |
| 46 | const result = convertSectionsToProductMenu([]) |
| 47 | expect(result).toEqual([]) |
| 48 | }) |
| 49 | |
| 50 | it('handles section with empty links', () => { |
| 51 | const sections = [ |
| 52 | { |
| 53 | key: 'empty', |
| 54 | heading: 'Empty', |
| 55 | links: [], |
| 56 | }, |
| 57 | ] |
| 58 | |
| 59 | const result = convertSectionsToProductMenu(sections) |
| 60 | |
| 61 | expect(result).toEqual([{ key: 'empty', title: 'Empty', items: [] }]) |
| 62 | }) |
| 63 | |
| 64 | it('handles section without heading', () => { |
| 65 | const sections = [ |
| 66 | { |
| 67 | key: 'no-heading', |
| 68 | links: [{ key: 'a', label: 'A', href: '/a' }], |
| 69 | }, |
| 70 | ] |
| 71 | |
| 72 | const result = convertSectionsToProductMenu(sections) |
| 73 | |
| 74 | expect(result[0].title).toBeUndefined() |
| 75 | expect(result[0].items).toHaveLength(1) |
| 76 | }) |
| 77 | |
| 78 | it('converts multiple sections', () => { |
| 79 | const sections = [ |
| 80 | { key: 'a', heading: 'A', links: [{ key: 'a1', label: 'A1', href: '/a1' }] }, |
| 81 | { key: 'b', heading: 'B', links: [{ key: 'b1', label: 'B1', href: '/b1' }] }, |
| 82 | ] |
| 83 | |
| 84 | const result = convertSectionsToProductMenu(sections) |
| 85 | |
| 86 | expect(result).toHaveLength(2) |
| 87 | expect(result[0].key).toBe('a') |
| 88 | expect(result[1].key).toBe('b') |
| 89 | }) |
| 90 | }) |