subscription-dashboard.test.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. renderWithSubscriptionDashContext(<SubscriptionDashboard />, {
  79. metaTags: [
  80. {
  81. name: 'ol-fromPlansPage',
  82. value: true,
  83. },
  84. ],
  85. })
  86. screen.getByText('You already have a subscription')
  87. })
  88. })