group-invite.test.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { render, screen } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import GroupInvite from '../../../../../../frontend/js/features/subscription/components/group-invite/group-invite'
  4. describe('group invite', function () {
  5. const inviterName = 'example@overleaf.com'
  6. beforeEach(function () {
  7. window.metaAttributesCache = new Map()
  8. window.metaAttributesCache.set('ol-inviterName', inviterName)
  9. })
  10. afterEach(function () {
  11. window.metaAttributesCache = new Map()
  12. })
  13. it('renders header', async function () {
  14. render(<GroupInvite />)
  15. await screen.findByText(inviterName)
  16. screen.getByText(`has invited you to join a group subscription on Overleaf`)
  17. expect(screen.queryByText('Email link expired, please request a new one.'))
  18. .to.be.null
  19. })
  20. describe('when user has personal subscription', function () {
  21. beforeEach(function () {
  22. window.metaAttributesCache.set(
  23. 'ol-hasIndividualRecurlySubscription',
  24. true
  25. )
  26. })
  27. it('renders cancel personal subscription view', async function () {
  28. render(<GroupInvite />)
  29. await screen.findByText(
  30. 'You already have an individual subscription, would you like us to cancel this first before joining the group licence?'
  31. )
  32. })
  33. describe('and in a managed group', function () {
  34. // note: this should not be possible but managed user view takes priority over all
  35. beforeEach(function () {
  36. window.metaAttributesCache.set(
  37. 'ol-currentManagedUserAdminEmail',
  38. 'example@overleaf.com'
  39. )
  40. window.metaAttributesCache.set('ol-cannot-join-subscription', true)
  41. })
  42. it('renders managed user cannot join view', async function () {
  43. render(<GroupInvite />)
  44. await screen.findByText('You can’t join this group subscription')
  45. screen.getByText(
  46. 'Your Overleaf account is managed by your current group admin (example@overleaf.com). This means you can’t join additional group subscriptions',
  47. { exact: false }
  48. )
  49. screen.getByRole('link', { name: 'Read more about Managed Users.' })
  50. })
  51. })
  52. })
  53. describe('when user does not have a personal subscription', function () {
  54. beforeEach(function () {
  55. window.metaAttributesCache.set(
  56. 'ol-hasIndividualRecurlySubscription',
  57. false
  58. )
  59. window.metaAttributesCache.set('ol-inviteToken', 'token123')
  60. })
  61. it('does not render cancel personal subscription view', async function () {
  62. render(<GroupInvite />)
  63. await screen.findByText(
  64. 'Please click the button below to join the group subscription and enjoy the benefits of an upgraded Overleaf account'
  65. )
  66. })
  67. })
  68. describe('when the user is already a managed user in another group', function () {
  69. beforeEach(function () {
  70. window.metaAttributesCache.set(
  71. 'ol-currentManagedUserAdminEmail',
  72. 'example@overleaf.com'
  73. )
  74. window.metaAttributesCache.set('ol-cannot-join-subscription', true)
  75. })
  76. it('renders managed user cannot join view', async function () {
  77. render(<GroupInvite />)
  78. await screen.findByText(inviterName)
  79. screen.getByText(
  80. `has invited you to join a group subscription on Overleaf`
  81. )
  82. screen.getByText('You can’t join this group subscription')
  83. screen.getByText(
  84. 'Your Overleaf account is managed by your current group admin (example@overleaf.com). This means you can’t join additional group subscriptions',
  85. { exact: false }
  86. )
  87. screen.getByRole('link', { name: 'Read more about Managed Users.' })
  88. })
  89. })
  90. describe('expired', function () {
  91. beforeEach(function () {
  92. window.metaAttributesCache.set('ol-expired', true)
  93. })
  94. it('shows error notification when expired', async function () {
  95. render(<GroupInvite />)
  96. await screen.findByText('Email link expired, please request a new one.')
  97. })
  98. })
  99. describe('join view', function () {
  100. beforeEach(function () {
  101. window.metaAttributesCache.set('ol-inviteToken', 'token123')
  102. })
  103. it('shows view to join group', async function () {
  104. render(<GroupInvite />)
  105. await screen.findByText(
  106. 'Please click the button below to join the group subscription and enjoy the benefits of an upgraded Overleaf account'
  107. )
  108. })
  109. })
  110. })