OrganizationSettingsLayout.test.ts105 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { |
| 4 | generateOrganizationSettingsMenuItems, |
| 5 | generateOrganizationSettingsSections, |
| 6 | normalizeOrganizationSettingsPath, |
| 7 | } from './OrganizationSettingsLayout' |
| 8 | |
| 9 | describe('generateOrganizationSettingsMenuItems', () => { |
| 10 | it('includes webhooks entry for organization settings nav', () => { |
| 11 | const items = generateOrganizationSettingsMenuItems({ |
| 12 | slug: 'my-org', |
| 13 | showSecuritySettings: true, |
| 14 | showSsoSettings: true, |
| 15 | showLegalDocuments: true, |
| 16 | }) |
| 17 | |
| 18 | expect(items.some((item) => item.label === 'Webhooks')).toBe(true) |
| 19 | expect(items.some((item) => item.href === '/org/my-org/webhooks')).toBe(true) |
| 20 | }) |
| 21 | }) |
| 22 | |
| 23 | describe('OrganizationSettingsLayout helpers', () => { |
| 24 | it('returns expected organization settings sections and links', () => { |
| 25 | const sections = generateOrganizationSettingsSections({ |
| 26 | slug: 'my-org', |
| 27 | currentPath: '/org/my-org/general', |
| 28 | showSecuritySettings: true, |
| 29 | showSsoSettings: true, |
| 30 | showLegalDocuments: true, |
| 31 | }) |
| 32 | |
| 33 | expect(sections.map((section) => section.heading)).toEqual([ |
| 34 | 'Configuration', |
| 35 | 'Connections', |
| 36 | 'Compliance', |
| 37 | ]) |
| 38 | expect(sections.flatMap((section) => section.links.map((item) => item.label))).toEqual([ |
| 39 | 'General', |
| 40 | 'Security', |
| 41 | 'SSO', |
| 42 | 'OAuth Apps', |
| 43 | 'Webhooks', |
| 44 | 'Audit Logs', |
| 45 | 'Legal Documents', |
| 46 | ]) |
| 47 | expect( |
| 48 | sections.flatMap((section) => section.links).find((item) => item.label === 'General') |
| 49 | ?.isActive |
| 50 | ).toBe(true) |
| 51 | }) |
| 52 | |
| 53 | it('hides feature-flagged items when flags are disabled', () => { |
| 54 | const sections = generateOrganizationSettingsSections({ |
| 55 | slug: 'my-org', |
| 56 | currentPath: '/org/my-org/general', |
| 57 | showSecuritySettings: false, |
| 58 | showSsoSettings: false, |
| 59 | showLegalDocuments: false, |
| 60 | }) |
| 61 | |
| 62 | expect(sections.map((section) => section.heading)).toEqual([ |
| 63 | 'Configuration', |
| 64 | 'Connections', |
| 65 | 'Compliance', |
| 66 | ]) |
| 67 | expect(sections.flatMap((section) => section.links.map((item) => item.label))).toEqual([ |
| 68 | 'General', |
| 69 | 'OAuth Apps', |
| 70 | 'Webhooks', |
| 71 | 'Audit Logs', |
| 72 | ]) |
| 73 | }) |
| 74 | |
| 75 | it('normalizes hash paths for active state checks', () => { |
| 76 | const currentPath = normalizeOrganizationSettingsPath('/org/my-org/security#sso') |
| 77 | const sections = generateOrganizationSettingsSections({ |
| 78 | slug: 'my-org', |
| 79 | currentPath, |
| 80 | showSecuritySettings: true, |
| 81 | showSsoSettings: true, |
| 82 | showLegalDocuments: true, |
| 83 | }) |
| 84 | |
| 85 | expect( |
| 86 | sections.flatMap((section) => section.links).find((item) => item.label === 'Security') |
| 87 | ?.isActive |
| 88 | ).toBe(true) |
| 89 | }) |
| 90 | |
| 91 | it('keeps webhooks nav item active for nested endpoint routes', () => { |
| 92 | const sections = generateOrganizationSettingsSections({ |
| 93 | slug: 'my-org', |
| 94 | currentPath: '/org/my-org/webhooks/org-endpoint-1', |
| 95 | showSecuritySettings: true, |
| 96 | showSsoSettings: true, |
| 97 | showLegalDocuments: true, |
| 98 | }) |
| 99 | |
| 100 | expect( |
| 101 | sections.flatMap((section) => section.links).find((item) => item.label === 'Webhooks') |
| 102 | ?.isActive |
| 103 | ).toBe(true) |
| 104 | }) |
| 105 | }) |