upgrade-subscription.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import UpgradeSubscription from '@/features/group-management/components/upgrade-subscription/upgrade-subscription'
  2. import { SubscriptionChangePreview } from '../../../../../types/subscription/subscription-change-preview'
  3. describe('<UpgradeSubscription />', function () {
  4. const resetPreviewAndRemount = (preview: SubscriptionChangePreview) => {
  5. cy.window().then(win => {
  6. win.metaAttributesCache.set('ol-subscriptionChangePreview', preview)
  7. })
  8. cy.mount(<UpgradeSubscription />)
  9. }
  10. beforeEach(function () {
  11. this.totalLicenses = 2
  12. this.preview = {
  13. change: {
  14. type: 'group-plan-upgrade',
  15. prevPlan: { name: 'Standard group' },
  16. },
  17. currency: 'USD',
  18. immediateCharge: {
  19. subtotal: 353.99,
  20. tax: 70.8,
  21. total: 424.79,
  22. discount: 0,
  23. },
  24. paymentMethod: 'Visa **** 1111',
  25. nextPlan: { annual: true },
  26. nextInvoice: {
  27. date: '2025-11-05T11:35:32.000Z',
  28. plan: { name: 'Pro group', amount: 0 },
  29. addOns: [
  30. {
  31. code: 'additional-license',
  32. name: 'Seat',
  33. quantity: 2,
  34. unitAmount: 399,
  35. amount: 798,
  36. },
  37. ],
  38. subtotal: 798,
  39. tax: { rate: 0.2, amount: 159.6 },
  40. total: 957.6,
  41. },
  42. }
  43. cy.window().then(win => {
  44. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  45. win.metaAttributesCache.set('ol-totalLicenses', this.totalLicenses)
  46. })
  47. resetPreviewAndRemount(this.preview)
  48. })
  49. it('shows the group name', function () {
  50. cy.findByTestId('group-heading').within(() => {
  51. cy.findByRole('heading', { name: 'My Awesome Team' })
  52. })
  53. })
  54. it('shows the "Add more licenses to my plan" label', function () {
  55. cy.findByText(/add more licenses to my plan/i).should(
  56. 'have.attr',
  57. 'href',
  58. '/user/subscription/group/add-users'
  59. )
  60. })
  61. it('shows the "Upgrade" and "Cancel" buttons', function () {
  62. cy.findByRole('button', { name: /upgrade/i })
  63. cy.findByRole('link', { name: /cancel/i }).should(
  64. 'have.attr',
  65. 'href',
  66. '/user/subscription'
  67. )
  68. })
  69. describe('shows plan details', function () {
  70. it('shows per user price', function () {
  71. cy.findByTestId('per-user-price').within(() => {
  72. cy.findByText('$399')
  73. })
  74. })
  75. it('shows additional features', function () {
  76. cy.findByText(/unlimited collaborators per project/i)
  77. cy.findByText(/sso/i)
  78. cy.findByText(/managed user accounts/i)
  79. })
  80. })
  81. describe('shows upgrade summary', function () {
  82. it('shows subtotal, tax and total price', function () {
  83. cy.findByTestId('subtotal').within(() => {
  84. cy.findByText('$353.99')
  85. })
  86. cy.findByTestId('tax').within(() => {
  87. cy.findByText('$70.80')
  88. })
  89. cy.findByTestId('total').within(() => {
  90. cy.findByText('$424.79')
  91. })
  92. cy.findByTestId('discount').should('not.exist')
  93. })
  94. it('shows subtotal, discount, tax and total price', function () {
  95. resetPreviewAndRemount({
  96. ...this.preview,
  97. immediateCharge: {
  98. subtotal: 353.99,
  99. tax: 70.8,
  100. total: 424.79,
  101. discount: 50,
  102. },
  103. })
  104. cy.findByTestId('subtotal').within(() => {
  105. cy.findByText('$353.99')
  106. })
  107. cy.findByTestId('tax').within(() => {
  108. cy.findByText('$70.80')
  109. })
  110. cy.findByTestId('total').within(() => {
  111. cy.findByText('$424.79')
  112. })
  113. cy.findByTestId('discount').within(() => {
  114. cy.findByText('($50.00)')
  115. })
  116. })
  117. it('shows total users', function () {
  118. cy.findByText(/you have 2 licenses on your subscription./i)
  119. })
  120. })
  121. describe('submit upgrade request', function () {
  122. it('request succeeded', function () {
  123. cy.intercept('POST', '/user/subscription/group/upgrade-subscription', {
  124. statusCode: 200,
  125. }).as('upgradeRequest')
  126. cy.findByRole('button', { name: /upgrade/i }).click()
  127. cy.findByText(/you’ve upgraded your plan!/i)
  128. })
  129. it('request failed', function () {
  130. cy.intercept('POST', '/user/subscription/group/upgrade-subscription', {
  131. statusCode: 400,
  132. }).as('upgradeRequest')
  133. cy.findByRole('button', { name: /upgrade/i }).click()
  134. cy.findByText(/something went wrong/i)
  135. })
  136. })
  137. })