group-invite.test.tsx 4.1 KB

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