promotionModal.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {DiscountInfoFixture} from 'getsentry-test/fixtures/discountInfo';
  3. import {PromotionFixture} from 'getsentry-test/fixtures/promotion';
  4. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import PromotionModal from 'getsentry/components/promotionModal';
  6. describe('Promotion Modal', function () {
  7. const organization = OrganizationFixture();
  8. const acceptFn = jest.fn();
  9. const closeModal = jest.fn();
  10. const promotion = PromotionFixture({
  11. name: 'Test Promotion',
  12. slug: 'test_promotion',
  13. timeLimit: '',
  14. startDate: '',
  15. endDate: '',
  16. showDiscountInfo: true,
  17. discountInfo: DiscountInfoFixture({
  18. amount: 2500,
  19. billingInterval: 'monthly',
  20. billingPeriods: 3,
  21. creditCategory: 'subscription',
  22. discountType: 'percentPoints',
  23. disclaimerText:
  24. "*Receive 40% off the monthly price of Sentry's Team or Business plan subscriptions for your first three months if you upgrade today",
  25. durationText: 'First three months',
  26. maxCentsPerPeriod: 10000,
  27. modalDisclaimerText: '*Discount applies only to monthly Sentry Business Plans',
  28. }),
  29. });
  30. afterEach(() => {
  31. MockApiClient.clearMockResponses();
  32. jest.clearAllMocks();
  33. });
  34. it('renders modal', async function () {
  35. MockApiClient.addMockResponse({
  36. method: 'POST',
  37. url: `/organizations/${organization.slug}/promotions/test_promotion/claim/`,
  38. body: {},
  39. });
  40. MockApiClient.addMockResponse({
  41. method: 'POST',
  42. url: `/organizations/${organization.slug}/promotions/test_promotion/decline/`,
  43. body: {},
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/promotions/trigger-check/`,
  47. method: 'POST',
  48. });
  49. render(
  50. <PromotionModal
  51. organization={organization}
  52. promotion={promotion}
  53. price={2900}
  54. onAccept={() => acceptFn()}
  55. closeModal={closeModal}
  56. promptFeature=""
  57. />
  58. );
  59. expect(screen.getByText('Limited Time Offer')).toBeInTheDocument();
  60. expect(screen.getByText('Get 25% off for the next 3 months*')).toBeInTheDocument();
  61. expect(
  62. screen.getByText(
  63. 'Receive a 25% discount for the next 3 months for your total monthly bill up to $100 per month.'
  64. )
  65. ).toBeInTheDocument();
  66. expect(
  67. screen.getByText('*Discount applies only to monthly Sentry Business Plans')
  68. ).toBeInTheDocument();
  69. expect(screen.getByText('29.00')).toBeInTheDocument();
  70. expect(screen.getByText('21.75')).toBeInTheDocument();
  71. expect(screen.getByText("Let's do it")).toBeInTheDocument();
  72. await userEvent.click(screen.getByRole('button', {name: "Let's do it"}));
  73. await waitFor(() => {
  74. expect(acceptFn).toHaveBeenCalled();
  75. });
  76. expect(closeModal).toHaveBeenCalled();
  77. expect(screen.getByText('Nah, I hate savings')).toBeInTheDocument();
  78. await userEvent.click(screen.getByRole('button', {name: 'Nah, I hate savings'}));
  79. await waitFor(() => {
  80. expect(closeModal).toHaveBeenCalled();
  81. });
  82. });
  83. it('caps discount as max amount', function () {
  84. MockApiClient.addMockResponse({
  85. url: `/organizations/${organization.slug}/promotions/trigger-check/`,
  86. method: 'POST',
  87. });
  88. render(
  89. <PromotionModal
  90. organization={organization}
  91. promotion={promotion}
  92. price={100000}
  93. onAccept={() => acceptFn()}
  94. closeModal={jest.fn()}
  95. promptFeature=""
  96. />
  97. );
  98. expect(screen.getByText('1000.00')).toBeInTheDocument();
  99. expect(screen.getByText('900.00')).toBeInTheDocument();
  100. });
  101. });