modal-content.test.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. import getMeta from '@/utils/meta'
  6. describe('<LeaveModalContent />', function () {
  7. beforeEach(function () {
  8. Object.assign(getMeta('ol-ExposedSettings'), { isOverleaf: true })
  9. window.metaAttributesCache.set('ol-hasPassword', true)
  10. })
  11. afterEach(function () {
  12. fetchMock.removeRoutes().clearHistory()
  13. })
  14. it('disable delete button if form is not valid', function () {
  15. render(
  16. <LeaveModalContent
  17. handleHide={() => {}}
  18. inFlight={false}
  19. setInFlight={() => {}}
  20. />
  21. )
  22. screen.getByLabelText('Email')
  23. const deleteButton = screen.getByRole('button', {
  24. name: 'Delete',
  25. })
  26. expect(deleteButton.hasAttribute('disabled')).to.be.true
  27. })
  28. it('shows no password message', function () {
  29. window.metaAttributesCache.set('ol-isSaas', true)
  30. window.metaAttributesCache.set('ol-hasPassword', false)
  31. render(
  32. <LeaveModalContent
  33. handleHide={() => {}}
  34. inFlight={false}
  35. setInFlight={() => {}}
  36. />
  37. )
  38. const link = screen.getByRole('link', {
  39. name: 'Please use the password reset form to set a password before deleting your account',
  40. })
  41. expect(link.getAttribute('href')).to.equal('/user/password/reset')
  42. })
  43. })