group-invite.test.tsx 4.2 KB

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