partnerPlanEndingModal.spec.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import {MemberFixture} from 'sentry-fixture/member';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import {resetMockDate, setMockDate} from 'sentry-test/utils';
  6. import {PlanFixture} from 'getsentry/__fixtures__/plan';
  7. import PartnerPlanEndingModal from 'getsentry/components/partnerPlanEndingModal';
  8. import SubscriptionStore from 'getsentry/stores/subscriptionStore';
  9. import {PlanName} from 'getsentry/types';
  10. describe('PartnerPlanEndingModal', function () {
  11. beforeEach(() => {
  12. setMockDate(new Date('2024-08-01'));
  13. MockApiClient.clearMockResponses();
  14. MockApiClient.addMockResponse({
  15. url: `/organizations/org-slug/members/`,
  16. method: 'GET',
  17. body: [
  18. MemberFixture({
  19. email: 'admin@example.com',
  20. }),
  21. ],
  22. });
  23. });
  24. afterEach(() => {
  25. resetMockDate();
  26. });
  27. it('shows request upgrade when user does not have billing permissions', async function () {
  28. const org = OrganizationFixture({access: []});
  29. const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-08'});
  30. SubscriptionStore.set(org.slug, sub);
  31. const mockCall = MockApiClient.addMockResponse({
  32. url: `/organizations/org-slug/partner-migration-request/?referrer=partner_plan_ending_modal`,
  33. method: 'POST',
  34. });
  35. render(
  36. <PartnerPlanEndingModal
  37. closeModal={jest.fn()}
  38. organization={org}
  39. subscription={sub}
  40. />
  41. );
  42. expect(screen.getByTestId('partner-plan-ending-modal')).toBeInTheDocument();
  43. expect(screen.getByLabelText('Request to Upgrade')).toBeInTheDocument();
  44. await userEvent.click(screen.getByLabelText('Request to Upgrade'));
  45. expect(mockCall).toHaveBeenCalled();
  46. });
  47. it('shows an upgrade now button with billing permission', function () {
  48. const org = OrganizationFixture({access: ['org:billing']});
  49. const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-08'});
  50. SubscriptionStore.set(org.slug, sub);
  51. render(
  52. <PartnerPlanEndingModal
  53. closeModal={jest.fn()}
  54. organization={org}
  55. subscription={sub}
  56. />
  57. );
  58. expect(screen.getByTestId('partner-plan-ending-modal')).toBeInTheDocument();
  59. expect(screen.getByLabelText('Upgrade Now')).toBeInTheDocument();
  60. });
  61. it('displays 7 days left', function () {
  62. const org = OrganizationFixture({access: ['org:billing']});
  63. const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-08'});
  64. SubscriptionStore.set(org.slug, sub);
  65. render(
  66. <PartnerPlanEndingModal
  67. closeModal={jest.fn()}
  68. organization={org}
  69. subscription={sub}
  70. />
  71. );
  72. expect(screen.getByTestId('partner-plan-ending-modal')).toBeInTheDocument();
  73. expect(screen.getByText('7 days left')).toBeInTheDocument();
  74. expect(screen.getByText('New Plan on Aug 9, 2024')).toBeInTheDocument();
  75. });
  76. it('displays 1 day left', function () {
  77. const org = OrganizationFixture({access: ['org:billing']});
  78. const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-02'});
  79. SubscriptionStore.set(org.slug, sub);
  80. render(
  81. <PartnerPlanEndingModal
  82. closeModal={jest.fn()}
  83. organization={org}
  84. subscription={sub}
  85. />
  86. );
  87. expect(screen.getByText('1 day left')).toBeInTheDocument();
  88. expect(screen.getByText('New Plan on Aug 3, 2024')).toBeInTheDocument();
  89. });
  90. it('displays team related content', function () {
  91. const org = OrganizationFixture({access: ['org:billing']});
  92. const sub = SubscriptionFixture({
  93. organization: org,
  94. contractPeriodEnd: '2024-08-30',
  95. planDetails: PlanFixture({
  96. name: PlanName.TEAM_SPONSORED,
  97. }),
  98. });
  99. SubscriptionStore.set(org.slug, sub);
  100. render(
  101. <PartnerPlanEndingModal
  102. closeModal={jest.fn()}
  103. organization={org}
  104. subscription={sub}
  105. />
  106. );
  107. expect(screen.queryAllByText('Business')).toHaveLength(0);
  108. expect(screen.getByText('Team')).toBeInTheDocument();
  109. });
  110. it('displays business related content', function () {
  111. const org = OrganizationFixture({access: ['org:billing']});
  112. const sub = SubscriptionFixture({
  113. organization: org,
  114. contractPeriodEnd: '2024-08-30',
  115. planDetails: PlanFixture({
  116. name: PlanName.BUSINESS_SPONSORED,
  117. }),
  118. });
  119. SubscriptionStore.set(org.slug, sub);
  120. render(
  121. <PartnerPlanEndingModal
  122. closeModal={jest.fn()}
  123. organization={org}
  124. subscription={sub}
  125. />
  126. );
  127. expect(screen.queryAllByText('Team')).toHaveLength(0);
  128. expect(screen.getByText('Business')).toBeInTheDocument();
  129. });
  130. it('does not display if plan ended', function () {
  131. const org = OrganizationFixture({access: ['org:billing']});
  132. const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-07-31'});
  133. SubscriptionStore.set(org.slug, sub);
  134. render(
  135. <PartnerPlanEndingModal
  136. closeModal={jest.fn()}
  137. organization={org}
  138. subscription={sub}
  139. />
  140. );
  141. expect(screen.queryByTestId('partner-plan-ending-modal')).not.toBeInTheDocument();
  142. });
  143. });