successful-subscription.test.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 { annualActiveSubscription } from '../../fixtures/subscriptions'
  6. describe('successful subscription page', function () {
  7. afterEach(function () {
  8. window.metaAttributesCache = new Map()
  9. })
  10. it('renders the invoices link', function () {
  11. const adminEmail = 'foo@example.com'
  12. const options = {
  13. metaTags: [
  14. {
  15. name: 'ol-ExposedSettings',
  16. value: {
  17. adminEmail,
  18. },
  19. },
  20. { name: 'ol-subscription', value: annualActiveSubscription },
  21. ],
  22. }
  23. renderWithSubscriptionDashContext(<SuccessfulSubscription />, options)
  24. screen.getByRole('heading', { name: /thanks for subscribing/i })
  25. const alert = screen.getByRole('alert')
  26. within(alert).getByText(/to modify your subscription go to/i)
  27. const manageSubscriptionLink = within(alert).getByRole('link', {
  28. name: /manage subscription/i,
  29. })
  30. expect(manageSubscriptionLink.getAttribute('href')).to.equal(
  31. '/user/subscription'
  32. )
  33. screen.getByText(
  34. `Thank you for subscribing to the ${annualActiveSubscription.plan.name} plan.`,
  35. { exact: false }
  36. )
  37. screen.getByText(
  38. /it’s support from people like yourself that allows .* to continue to grow and improve/i
  39. )
  40. expect(screen.getByText(/get the most out of your/i).textContent).to.match(
  41. /get the most out of your .* subscription by checking out the list of .*’s premium features/i
  42. )
  43. expect(
  44. screen
  45. .getByText(/if there is anything you ever/i)
  46. .textContent?.replace(/\xA0/g, ' ')
  47. ).to.equal(
  48. `If there is anything you ever need please feel free to contact us directly at ${adminEmail}.`
  49. )
  50. const contactLink = screen.getByRole('link', {
  51. name: adminEmail,
  52. })
  53. expect(contactLink.getAttribute('href')).to.equal(`mailto:${adminEmail}`)
  54. expect(
  55. screen.getByText(/if you would like to help us improve/i).textContent
  56. ).to.match(
  57. /if you would like to help us improve .*, please take a moment to fill out this survey/i
  58. )
  59. const surveyLink = screen.getByRole('link', {
  60. name: /this survey/i,
  61. })
  62. expect(surveyLink.getAttribute('href')).to.equal(
  63. 'https://forms.gle/CdLNX9m6NLxkv1yr5'
  64. )
  65. const helpLink = screen.getByRole('link', {
  66. name: /.*’s premium features/i,
  67. })
  68. expect(helpLink.getAttribute('href')).to.equal(
  69. '/learn/how-to/Overleaf_premium_features'
  70. )
  71. const backToYourProjectsLink = screen.getByRole('link', {
  72. name: /back to your projects/i,
  73. })
  74. expect(backToYourProjectsLink.getAttribute('href')).to.equal('/project')
  75. })
  76. })