modal-content.test.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { expect } from 'chai'
  2. import { screen, render } from '@testing-library/react'
  3. import fetchMock from 'fetch-mock'
  4. import LeaveModalContent from '../../../../../../frontend/js/features/settings/components/leave/modal-content'
  5. describe('<LeaveModalContent />', function () {
  6. beforeEach(function () {
  7. window.metaAttributesCache = new Map()
  8. window.metaAttributesCache.set('ol-ExposedSettings', { isOverleaf: true })
  9. window.metaAttributesCache.set('ol-hasPassword', true)
  10. })
  11. afterEach(function () {
  12. window.metaAttributesCache = new Map()
  13. fetchMock.reset()
  14. })
  15. it('disable delete button if form is not valid', function () {
  16. render(
  17. <LeaveModalContent
  18. handleHide={() => {}}
  19. inFlight={false}
  20. setInFlight={() => {}}
  21. />
  22. )
  23. screen.getByLabelText('Email')
  24. const deleteButton = screen.getByRole('button', {
  25. name: 'Delete',
  26. })
  27. expect(deleteButton.hasAttribute('disabled')).to.be.true
  28. })
  29. it('shows no password message', function () {
  30. window.metaAttributesCache.set('ol-isSaas', true)
  31. window.metaAttributesCache.set('ol-hasPassword', false)
  32. render(
  33. <LeaveModalContent
  34. handleHide={() => {}}
  35. inFlight={false}
  36. setInFlight={() => {}}
  37. />
  38. )
  39. const link = screen.getByRole('link', {
  40. name: 'Please use the password reset form to set a password before deleting your account',
  41. })
  42. expect(link.getAttribute('href')).to.equal('/user/password/reset')
  43. })
  44. })