subscription-dashboard.test.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { expect } from 'chai'
  2. import { screen } from '@testing-library/react'
  3. import SubscriptionDashboard from '../../../../../../frontend/js/features/subscription/components/dashboard/subscription-dashboard'
  4. import {
  5. cleanUpContext,
  6. renderWithSubscriptionDashContext,
  7. } from '../../helpers/render-with-subscription-dash-context'
  8. import { groupPlans, plans } from '../../fixtures/plans'
  9. import { annualActiveSubscription } from '../../fixtures/subscriptions'
  10. describe('<SubscriptionDashboard />', function () {
  11. afterEach(function () {
  12. cleanUpContext()
  13. })
  14. describe('With an active subscription', function () {
  15. beforeEach(function () {
  16. renderWithSubscriptionDashContext(<SubscriptionDashboard />, {
  17. metaTags: [
  18. { name: 'ol-plans', value: plans },
  19. {
  20. name: 'ol-groupPlans',
  21. value: groupPlans,
  22. },
  23. { name: 'ol-subscription', value: annualActiveSubscription },
  24. {
  25. name: 'ol-recommendedCurrency',
  26. value: 'USD',
  27. },
  28. ],
  29. })
  30. })
  31. it('renders the "Get the most from your subscription" text', function () {
  32. screen.getByText(/Get the most out of your subscription/i)
  33. })
  34. })
  35. describe('Free Plan', function () {
  36. beforeEach(function () {
  37. renderWithSubscriptionDashContext(<SubscriptionDashboard />)
  38. })
  39. it('does not render the "Get the most out of your" subscription text', function () {
  40. const text = screen.queryByText('Get the most out of your subscription', {
  41. exact: false,
  42. })
  43. expect(text).to.be.null
  44. })
  45. it('does not render the contact Support message', function () {
  46. const text = screen.queryByText(
  47. `You’re on an Overleaf Paid plan. Contact`,
  48. {
  49. exact: false,
  50. }
  51. )
  52. expect(text).to.be.null
  53. })
  54. })
  55. describe('Custom subscription', function () {
  56. it('renders the contact Support message', function () {
  57. renderWithSubscriptionDashContext(<SubscriptionDashboard />, {
  58. metaTags: [
  59. {
  60. name: 'ol-currentInstitutionsWithLicence',
  61. value: [],
  62. },
  63. {
  64. name: 'ol-hasSubscription',
  65. value: true,
  66. },
  67. ],
  68. })
  69. screen.getByText(`You’re on an Overleaf Paid plan.`, {
  70. exact: false,
  71. })
  72. screen.getByText(`Contact Support`, {
  73. exact: false,
  74. })
  75. })
  76. })
  77. it('Show a warning when coming from plans page', function () {
  78. window.history.pushState({}, '', '?hasSubscription=true')
  79. try {
  80. renderWithSubscriptionDashContext(<SubscriptionDashboard />)
  81. screen.getByText('You already have a subscription')
  82. } finally {
  83. window.history.replaceState({}, '', window.location.pathname)
  84. }
  85. })
  86. })