OrganizationSettingsLayout.test.ts 3.1 KB

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