root.test.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { expect } from 'chai'
  2. import sinon from 'sinon'
  3. import { screen, render, waitFor } from '@testing-library/react'
  4. import * as eventTracking from '../../../../../frontend/js/infrastructure/event-tracking'
  5. import SettingsPageRoot from '../../../../../frontend/js/features/settings/components/root'
  6. describe('<SettingsPageRoot />', function () {
  7. let sendMBSpy: sinon.SinonSpy
  8. beforeEach(function () {
  9. window.metaAttributesCache = new Map()
  10. window.metaAttributesCache.set('ol-usersEmail', 'foo@bar.com')
  11. window.metaAttributesCache.set('ol-ExposedSettings', { isOverleaf: true })
  12. window.metaAttributesCache.set('ol-hasPassword', true)
  13. window.metaAttributesCache.set('ol-ExposedSettings', {
  14. hasAffiliationsFeature: true,
  15. isOverleaf: true,
  16. })
  17. window.metaAttributesCache.set('ol-user', {
  18. features: { github: true, dropbox: true, mendeley: true, zotero: true },
  19. refProviders: {
  20. mendeley: true,
  21. zotero: true,
  22. },
  23. })
  24. window.metaAttributesCache.set('ol-github', { enabled: true })
  25. window.metaAttributesCache.set('ol-dropbox', { registered: true })
  26. window.metaAttributesCache.set('ol-oauthProviders', {})
  27. sendMBSpy = sinon.spy(eventTracking, 'sendMB')
  28. })
  29. afterEach(function () {
  30. window.metaAttributesCache = new Map()
  31. sendMBSpy.restore()
  32. })
  33. it('displays page for Overleaf', async function () {
  34. render(<SettingsPageRoot />)
  35. await waitFor(() => {
  36. screen.getByText('Account Settings')
  37. })
  38. screen.getByText('Emails and Affiliations')
  39. screen.getByText('Update Account Info')
  40. screen.getByText('Change Password')
  41. screen.getByText('Integrations')
  42. screen.getByText('Overleaf Beta Program')
  43. screen.getByText('Sessions')
  44. screen.getByText('Newsletter')
  45. screen.getByRole('button', {
  46. name: 'Delete your account',
  47. })
  48. })
  49. it('displays page for non-Overleaf', async function () {
  50. window.metaAttributesCache.set('ol-ExposedSettings', {
  51. hasAffiliationsFeature: false,
  52. isOverleaf: false,
  53. })
  54. render(<SettingsPageRoot />)
  55. await waitFor(() => {
  56. screen.getByText('Account Settings')
  57. })
  58. expect(screen.queryByText('Emails and Affiliations')).to.not.exist
  59. screen.getByText('Update Account Info')
  60. screen.getByText('Change Password')
  61. screen.getByText('Integrations')
  62. expect(screen.queryByText('Overleaf Beta Program')).to.not.exist
  63. screen.getByText('Sessions')
  64. expect(screen.queryByText('Newsletter')).to.not.exist
  65. expect(
  66. screen.queryByRole('button', {
  67. name: 'Delete your account',
  68. })
  69. ).to.not.exist
  70. })
  71. it('sends tracking event on load', async function () {
  72. render(<SettingsPageRoot />)
  73. sinon.assert.calledOnce(sendMBSpy)
  74. sinon.assert.calledWith(sendMBSpy, 'settings-view')
  75. })
  76. })