subscription-dashboard.test.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 out of your" subscription text', function () {
  32. screen.getByText(
  33. 'Get the most out of your Overleaf subscription by checking out the list of',
  34. { exact: false }
  35. )
  36. })
  37. })
  38. describe('Free Plan', function () {
  39. beforeEach(function () {
  40. renderWithSubscriptionDashContext(<SubscriptionDashboard />)
  41. })
  42. it('does not render the "Get the most out of your" subscription text', function () {
  43. const text = screen.queryByText('Get the most out of your', {
  44. exact: false,
  45. })
  46. expect(text).to.be.null
  47. })
  48. it('does not render the contact support message', function () {
  49. const text = screen.queryByText(
  50. `You’re on an Overleaf Paid plan. Contact`,
  51. {
  52. exact: false,
  53. }
  54. )
  55. expect(text).to.be.null
  56. })
  57. })
  58. describe('Custom subscription', function () {
  59. it('renders the contact support message', function () {
  60. renderWithSubscriptionDashContext(<SubscriptionDashboard />, {
  61. metaTags: [
  62. {
  63. name: 'ol-currentInstitutionsWithLicence',
  64. value: [],
  65. },
  66. {
  67. name: 'ol-hasSubscription',
  68. value: true,
  69. },
  70. ],
  71. })
  72. screen.getByText(`You’re on an Overleaf Paid plan.`, {
  73. exact: false,
  74. })
  75. screen.getByText(`Contact support`, {
  76. exact: false,
  77. })
  78. })
  79. })
  80. it('Show a warning when coming from plans page', function () {
  81. renderWithSubscriptionDashContext(<SubscriptionDashboard />, {
  82. metaTags: [
  83. {
  84. name: 'ol-fromPlansPage',
  85. value: true,
  86. },
  87. ],
  88. })
  89. screen.getByText('You already have a subscription')
  90. })
  91. })