trialEndingModal.spec.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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} from 'sentry-test/reactTestingLibrary';
  5. import {resetMockDate, setMockDate} from 'sentry-test/utils';
  6. import TrialEndingModal from 'getsentry/components/trialEndingModal';
  7. import SubscriptionStore from 'getsentry/stores/subscriptionStore';
  8. describe('TrialEndingModal', function () {
  9. beforeEach(() => {
  10. setMockDate(new Date('2021-03-03'));
  11. MockApiClient.clearMockResponses();
  12. MockApiClient.addMockResponse({
  13. url: `/organizations/org-slug/members/`,
  14. method: 'GET',
  15. body: [
  16. MemberFixture({
  17. email: 'admin@example.com',
  18. }),
  19. ],
  20. });
  21. });
  22. afterEach(() => {
  23. resetMockDate();
  24. });
  25. it('shows request upgrade when user does not have billing permissions', function () {
  26. const org = OrganizationFixture({access: []});
  27. const sub = SubscriptionFixture({organization: org});
  28. SubscriptionStore.set(org.slug, sub);
  29. render(<TrialEndingModal closeModal={jest.fn()} organization={org} />);
  30. expect(screen.getByTestId('trial-ending-modal')).toBeInTheDocument();
  31. expect(screen.getByLabelText('Request Upgrade')).toBeInTheDocument();
  32. });
  33. it('shows an upgrade button with billing permission', function () {
  34. const org = OrganizationFixture({access: ['org:billing']});
  35. const sub = SubscriptionFixture({organization: org});
  36. SubscriptionStore.set(org.slug, sub);
  37. render(<TrialEndingModal closeModal={jest.fn()} organization={org} />);
  38. expect(screen.getByTestId('trial-ending-modal')).toBeInTheDocument();
  39. expect(screen.getByLabelText('Upgrade Now')).toBeInTheDocument();
  40. });
  41. it('displays 3 days left', function () {
  42. const org = OrganizationFixture({access: ['org:billing']});
  43. const sub = SubscriptionFixture({organization: org, trialEnd: '2021-03-06'});
  44. SubscriptionStore.set(org.slug, sub);
  45. render(<TrialEndingModal closeModal={jest.fn()} organization={org} />);
  46. expect(screen.getByTestId('trial-ending-modal')).toBeInTheDocument();
  47. expect(screen.getByText('Trial Ends in 3 Days')).toBeInTheDocument();
  48. expect(screen.getByText(/Developer Plan in 3 days/)).toBeInTheDocument();
  49. });
  50. it('displays 1 day left', function () {
  51. const org = OrganizationFixture({access: ['org:billing']});
  52. const sub = SubscriptionFixture({organization: org, trialEnd: '2021-03-04'});
  53. SubscriptionStore.set(org.slug, sub);
  54. render(<TrialEndingModal closeModal={jest.fn()} organization={org} />);
  55. expect(screen.getByText('Trial Ends in 1 Day')).toBeInTheDocument();
  56. expect(screen.getByText(/Developer Plan in 1 day/)).toBeInTheDocument();
  57. });
  58. it('does not display negative days left', function () {
  59. const org = OrganizationFixture({access: ['org:billing']});
  60. const sub = SubscriptionFixture({organization: org, trialEnd: '2021-03-01'});
  61. SubscriptionStore.set(org.slug, sub);
  62. render(<TrialEndingModal closeModal={jest.fn()} organization={org} />);
  63. expect(screen.queryByTestId('trial-ending-modal')).not.toBeInTheDocument();
  64. });
  65. });