checkoutOverview.spec.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {BillingConfigFixture} from 'getsentry-test/fixtures/billingConfig';
  3. import {PlanDetailsLookupFixture} from 'getsentry-test/fixtures/planDetailsLookup';
  4. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  7. import SubscriptionStore from 'getsentry/stores/subscriptionStore';
  8. import {OnDemandBudgetMode, PlanTier} from 'getsentry/types';
  9. import AMCheckout from 'getsentry/views/amCheckout/';
  10. import CheckoutOverview from 'getsentry/views/amCheckout/checkoutOverview';
  11. import type {CheckoutFormData} from 'getsentry/views/amCheckout/types';
  12. describe('CheckoutOverview', function () {
  13. const api = new MockApiClient();
  14. const {organization, routerProps} = initializeOrg();
  15. const subscription = SubscriptionFixture({organization, plan: 'am1_f'});
  16. const params = {};
  17. const billingConfig = BillingConfigFixture(PlanTier.AM2);
  18. const teamPlanAnnual = PlanDetailsLookupFixture('am1_team_auf')!;
  19. const teamPlanMonthly = PlanDetailsLookupFixture('am2_team')!;
  20. beforeEach(function () {
  21. SubscriptionStore.set(organization.slug, subscription);
  22. MockApiClient.addMockResponse({
  23. url: `/customers/${organization.slug}/plan-migrations/?applied=0`,
  24. method: 'GET',
  25. body: {},
  26. });
  27. MockApiClient.addMockResponse({
  28. url: `/subscriptions/${organization.slug}/`,
  29. method: 'GET',
  30. body: {},
  31. });
  32. MockApiClient.addMockResponse({
  33. url: `/customers/${organization.slug}/billing-config/`,
  34. method: 'GET',
  35. body: BillingConfigFixture(PlanTier.AM2),
  36. });
  37. MockApiClient.addMockResponse({
  38. url: `/organizations/${organization.slug}/promotions/trigger-check/`,
  39. method: 'POST',
  40. });
  41. });
  42. it('renders with default plan', async function () {
  43. render(
  44. <AMCheckout
  45. {...routerProps}
  46. api={api}
  47. checkoutTier={PlanTier.AM2}
  48. onToggleLegacy={jest.fn()}
  49. params={params}
  50. />
  51. );
  52. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  53. });
  54. it('renders breakdown for team annual plan', function () {
  55. const formData = {
  56. plan: 'am1_team_auf',
  57. reserved: {errors: 100000, transactions: 500000, attachments: 25},
  58. onDemandMaxSpend: 5000,
  59. };
  60. render(
  61. <CheckoutOverview
  62. activePlan={teamPlanAnnual}
  63. billingConfig={billingConfig}
  64. formData={formData}
  65. onUpdate={jest.fn()}
  66. organization={organization}
  67. subscription={subscription}
  68. />
  69. );
  70. });
  71. it('changes initial step number based on url location.hash', async function () {
  72. render(
  73. <AMCheckout
  74. {...routerProps}
  75. api={api}
  76. checkoutTier={PlanTier.AM1}
  77. location={LocationFixture({hash: '#step3'})}
  78. onToggleLegacy={jest.fn()}
  79. params={params}
  80. />
  81. );
  82. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  83. // Should show description for step 3 (on-demand max spend)
  84. expect(
  85. screen.getByText(/On-Demand spend allows you to pay for additional data/i)
  86. ).toBeInTheDocument();
  87. });
  88. it('renders On-Demand max along with team annual plan', () => {
  89. const formData: CheckoutFormData = {
  90. plan: 'am2_team',
  91. reserved: {errors: 100000, transactions: 500000, attachments: 25},
  92. onDemandBudget: {
  93. budgetMode: OnDemandBudgetMode.SHARED,
  94. sharedMaxBudget: 5000,
  95. },
  96. };
  97. render(
  98. <CheckoutOverview
  99. activePlan={teamPlanMonthly}
  100. billingConfig={billingConfig}
  101. formData={formData}
  102. onUpdate={jest.fn()}
  103. organization={organization}
  104. subscription={subscription}
  105. />
  106. );
  107. expect(screen.getByTestId('on-demand-additional-cost')).toHaveTextContent(
  108. '+ On-Demand charges up to $50/mo based on usage'
  109. );
  110. });
  111. it('renders On-Demand with monthly total for annual plan', () => {
  112. const formData: CheckoutFormData = {
  113. plan: 'am2_team',
  114. reserved: {errors: 100000, transactions: 500000, attachments: 25},
  115. onDemandBudget: {
  116. budgetMode: OnDemandBudgetMode.SHARED,
  117. sharedMaxBudget: 5000,
  118. },
  119. };
  120. render(
  121. <CheckoutOverview
  122. activePlan={teamPlanAnnual}
  123. billingConfig={billingConfig}
  124. formData={formData}
  125. onUpdate={jest.fn()}
  126. organization={organization}
  127. subscription={subscription}
  128. />
  129. );
  130. expect(screen.getByTestId('on-demand-additional-cost')).toHaveTextContent(
  131. '+ On-Demand charges up to $50/mo based on usage'
  132. );
  133. });
  134. it('hides On-Demand max when On-Demand is $0', () => {
  135. const formData: CheckoutFormData = {
  136. plan: 'am2_team',
  137. reserved: {errors: 100000, transactions: 500000, attachments: 25},
  138. onDemandBudget: {
  139. budgetMode: OnDemandBudgetMode.SHARED,
  140. sharedMaxBudget: 0,
  141. },
  142. };
  143. render(
  144. <CheckoutOverview
  145. activePlan={teamPlanMonthly}
  146. billingConfig={billingConfig}
  147. formData={formData}
  148. onUpdate={jest.fn()}
  149. organization={organization}
  150. subscription={subscription}
  151. />
  152. );
  153. expect(screen.getByText('Team Plan')).toBeInTheDocument();
  154. expect(screen.queryByTestId('on-demand-additional-cost')).not.toBeInTheDocument();
  155. });
  156. });