root.test.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sinon from 'sinon'
  2. import { screen, render } from '@testing-library/react'
  3. import * as eventTracking from '../../../../../frontend/js/infrastructure/event-tracking'
  4. import SettingsPageRoot from '../../../../../frontend/js/features/settings/components/root'
  5. describe('<SettingsPageRoot />', function () {
  6. let sendMBSpy
  7. beforeEach(function () {
  8. window.metaAttributesCache = new Map()
  9. window.metaAttributesCache.set('ol-usersEmail', 'foo@bar.com')
  10. window.metaAttributesCache.set('ol-ExposedSettings', { isOverleaf: true })
  11. window.metaAttributesCache.set('ol-hasPassword', true)
  12. window.metaAttributesCache.set('ol-ExposedSettings', {
  13. hasAffiliationsFeature: false,
  14. })
  15. window.metaAttributesCache.set('ol-user', {
  16. features: { github: true, dropbox: true, mendeley: true, zotero: true },
  17. refProviders: {
  18. mendeley: true,
  19. zotero: true,
  20. },
  21. })
  22. window.metaAttributesCache.set('ol-github', { enabled: true })
  23. window.metaAttributesCache.set('ol-dropbox', { registered: true })
  24. window.metaAttributesCache.set('ol-oauthProviders', {})
  25. sendMBSpy = sinon.spy(eventTracking, 'sendMB')
  26. })
  27. afterEach(function () {
  28. window.metaAttributesCache = new Map()
  29. sendMBSpy.restore()
  30. })
  31. it('displays page', async function () {
  32. render(<SettingsPageRoot />)
  33. screen.getByRole('button', {
  34. name: 'Delete your account',
  35. })
  36. })
  37. it('sends tracking event on load', async function () {
  38. render(<SettingsPageRoot />)
  39. sinon.assert.calledOnce(sendMBSpy)
  40. sinon.assert.calledWith(sendMBSpy, 'settings-view')
  41. })
  42. })