security-section.test.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import SecuritySection from '@/features/settings/components/security-section'
  2. import { expect } from 'chai'
  3. import { screen, render } from '@testing-library/react'
  4. import fetchMock from 'fetch-mock'
  5. describe('<SecuritySection />', function () {
  6. beforeEach(function () {
  7. window.metaAttributesCache = window.metaAttributesCache || new Map()
  8. })
  9. afterEach(function () {
  10. window.metaAttributesCache = new Map()
  11. fetchMock.reset()
  12. })
  13. it('shows Group SSO rows in security section', async function () {
  14. window.metaAttributesCache.set('ol-memberOfSSOEnabledGroups', [
  15. {
  16. groupId: 'abc123abc123',
  17. linked: true,
  18. },
  19. {
  20. groupId: 'fff999fff999',
  21. linked: false,
  22. },
  23. ])
  24. render(<SecuritySection />)
  25. expect(screen.getAllByText('Single Sign-On (SSO)').length).to.equal(2)
  26. const link = screen.getByRole('link', {
  27. name: /Set up SSO/i,
  28. })
  29. expect(link).to.exist
  30. expect(link.getAttribute('href')).to.equal(
  31. '/subscription/fff999fff999/sso_enrollment'
  32. )
  33. })
  34. it('does not show the security section with no groups with SSO enabled', async function () {
  35. window.metaAttributesCache.set('ol-memberOfSSOEnabledGroups', [])
  36. render(<SecuritySection />)
  37. expect(screen.queryByText('Security')).to.not.exist
  38. })
  39. })