successful-subscription.test.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { expect } from 'chai'
  2. import { screen, within } from '@testing-library/react'
  3. import SuccessfulSubscription from '../../../../../../frontend/js/features/subscription/components/successful-subscription/successful-subscription'
  4. import { renderWithSubscriptionDashContext } from '../../helpers/render-with-subscription-dash-context'
  5. import {
  6. annualActiveSubscription,
  7. annualActiveSubscriptionEuro,
  8. annualActiveSubscriptionPro,
  9. } from '../../fixtures/subscriptions'
  10. import { ExposedSettings } from '../../../../../../types/exposed-settings'
  11. import { UserProvider } from '@/shared/context/user-context'
  12. describe('successful subscription page', function () {
  13. it('renders the invoices link', function () {
  14. const adminEmail = 'foo@example.com'
  15. renderWithSubscriptionDashContext(
  16. <UserProvider>
  17. <SuccessfulSubscription />
  18. </UserProvider>,
  19. {
  20. metaTags: [
  21. {
  22. name: 'ol-ExposedSettings',
  23. value: {
  24. adminEmail,
  25. } as ExposedSettings,
  26. },
  27. { name: 'ol-subscription', value: annualActiveSubscription },
  28. ],
  29. }
  30. )
  31. screen.getByRole('heading', { name: /thanks for subscribing/i })
  32. const alert = screen.getByRole('alert')
  33. within(alert).getByText(/to modify your subscription go to/i)
  34. const manageSubscriptionLink = within(alert).getByRole('link', {
  35. name: /manage subscription/i,
  36. })
  37. expect(manageSubscriptionLink.getAttribute('href')).to.equal(
  38. '/user/subscription'
  39. )
  40. screen.getByText(
  41. `Thank you for subscribing to the ${annualActiveSubscription.plan.name} plan.`,
  42. { exact: false }
  43. )
  44. screen.getByText(
  45. /it’s support from people like yourself that allows .* to continue to grow and improve/i
  46. )
  47. expect(screen.getByText(/get the most out of your/i).textContent).to.match(
  48. /get the most out of your subscription by checking out Overleaf’s features/i
  49. )
  50. expect(
  51. screen
  52. .getByText(/if there is anything you ever/i)
  53. .textContent?.replace(/\xA0/g, ' ')
  54. ).to.equal(
  55. `If there is anything you ever need please feel free to contact us directly at ${adminEmail}.`
  56. )
  57. const contactLink = screen.getByRole('link', {
  58. name: adminEmail,
  59. })
  60. expect(contactLink.getAttribute('href')).to.equal(`mailto:${adminEmail}`)
  61. expect(
  62. screen.getByText(/if you would like to help us improve/i).textContent
  63. ).to.match(
  64. /if you would like to help us improve .*, please take a moment to fill out this survey/i
  65. )
  66. const surveyLink = screen.getByRole('link', {
  67. name: /this survey/i,
  68. })
  69. expect(surveyLink.getAttribute('href')).to.equal(
  70. 'https://forms.gle/CdLNX9m6NLxkv1yr5'
  71. )
  72. const helpLink = screen.getByRole('link', {
  73. name: /Overleaf’s features/i,
  74. })
  75. expect(helpLink.getAttribute('href')).to.equal(
  76. '/learn/how-to/Overleaf_premium_features'
  77. )
  78. const backToYourProjectsLink = screen.getByRole('link', {
  79. name: /back to your projects/i,
  80. })
  81. expect(backToYourProjectsLink.getAttribute('href')).to.equal('/project')
  82. })
  83. describe('upgrade variant', function () {
  84. it('renders the upgrade success page when isUpgrade is true', function () {
  85. renderWithSubscriptionDashContext(
  86. <UserProvider>
  87. <SuccessfulSubscription />
  88. </UserProvider>,
  89. {
  90. metaTags: [
  91. {
  92. name: 'ol-ExposedSettings',
  93. value: {
  94. adminEmail: 'foo@example.com',
  95. } as ExposedSettings,
  96. },
  97. { name: 'ol-subscription', value: annualActiveSubscriptionPro },
  98. { name: 'ol-isUpgrade', value: true },
  99. ],
  100. }
  101. )
  102. screen.getByRole('heading', { name: /welcome to pro/i })
  103. const alert = screen.getByRole('alert')
  104. within(alert).getByText(/you.ve upgraded your subscription/i)
  105. const manageLink = within(alert).getByRole('link', {
  106. name: /manage subscription/i,
  107. })
  108. expect(manageLink.getAttribute('href')).to.equal('/user/subscription')
  109. expect(
  110. screen
  111. .getByText(/the next payment of/i)
  112. .textContent?.replace(/\xA0/g, ' ')
  113. ).to.equal(
  114. `The next payment of ${annualActiveSubscriptionPro.payment.displayPrice} will be collected on ${annualActiveSubscriptionPro.payment.nextPaymentDueAt}.`
  115. )
  116. screen.getByText(/taxes may be added, depending on your billing address/i)
  117. screen.getByText(/full access to every AI tool/i, { exact: false })
  118. const aiFeaturesLink = screen.getByRole('link', {
  119. name: /Overleaf.s AI features/i,
  120. })
  121. expect(aiFeaturesLink.getAttribute('href')).to.equal(
  122. 'https://docs.overleaf.com/integrations-and-add-ons/ai-features'
  123. )
  124. expect(aiFeaturesLink.getAttribute('target')).to.equal('_blank')
  125. expect(aiFeaturesLink.getAttribute('rel')).to.equal('noopener noreferrer')
  126. const backLink = screen.getByRole('link', {
  127. name: /back to your projects/i,
  128. })
  129. expect(backLink.getAttribute('href')).to.equal('/project')
  130. })
  131. it('renders the standard success page when isUpgrade is not set', function () {
  132. renderWithSubscriptionDashContext(
  133. <UserProvider>
  134. <SuccessfulSubscription />
  135. </UserProvider>,
  136. {
  137. metaTags: [
  138. {
  139. name: 'ol-ExposedSettings',
  140. value: {
  141. adminEmail: 'foo@example.com',
  142. } as ExposedSettings,
  143. },
  144. { name: 'ol-subscription', value: annualActiveSubscription },
  145. ],
  146. }
  147. )
  148. screen.getByRole('heading', { name: /thanks for subscribing/i })
  149. })
  150. it('hides tax disclaimer when tax is already included in the price', function () {
  151. renderWithSubscriptionDashContext(
  152. <UserProvider>
  153. <SuccessfulSubscription />
  154. </UserProvider>,
  155. {
  156. metaTags: [
  157. {
  158. name: 'ol-ExposedSettings',
  159. value: {
  160. adminEmail: 'foo@example.com',
  161. } as ExposedSettings,
  162. },
  163. { name: 'ol-subscription', value: annualActiveSubscriptionEuro },
  164. { name: 'ol-isUpgrade', value: true },
  165. ],
  166. }
  167. )
  168. expect(screen.queryByText(/taxes may be added/i)).to.be.null
  169. })
  170. })
  171. })