quotaExceededAlert.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {QuotaExceededAlert} from './quotaExceededAlert';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. describe('Renders QuotaExceededAlert correctly', function () {
  10. const {organization} = initializeOrg();
  11. const subscription = SubscriptionFixture({
  12. organization,
  13. onDemandPeriodEnd: '2024-12-30',
  14. onDemandBudgets: {
  15. enabled: true,
  16. } as any,
  17. planTier: 'am1' as any,
  18. categories: {
  19. spans: {
  20. usageExceeded: true,
  21. },
  22. } as any,
  23. });
  24. beforeEach(function () {
  25. jest.useFakeTimers();
  26. jest.setSystemTime(new Date('2024-12-14'));
  27. jest.mocked(usePageFilters).mockReturnValue({
  28. isReady: true,
  29. desyncedFilters: new Set(),
  30. pinnedFilters: new Set(),
  31. shouldPersist: true,
  32. selection: {
  33. datetime: {
  34. period: '7d',
  35. start: null,
  36. end: null,
  37. utc: false,
  38. },
  39. environments: [],
  40. projects: [2],
  41. },
  42. });
  43. jest.mocked(useLocation).mockReturnValue({
  44. pathname: '',
  45. search: '',
  46. query: {statsPeriod: '7d'},
  47. hash: '',
  48. state: undefined,
  49. action: 'PUSH',
  50. key: '',
  51. });
  52. });
  53. afterEach(function () {
  54. MockApiClient.clearMockResponses();
  55. });
  56. it('renders alert when quota is exceeded', async function () {
  57. // Mock performance usage stats endpoint
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/stats_v2/`,
  60. method: 'GET',
  61. body: {
  62. groups: [
  63. {
  64. by: {
  65. reason: 'span_usage_exceeded',
  66. },
  67. totals: {
  68. 'sum(quantity)': 1000,
  69. },
  70. },
  71. ],
  72. },
  73. });
  74. render(<QuotaExceededAlert subscription={subscription} referrer="trace-view" />, {
  75. organization,
  76. });
  77. expect(await screen.findByText(/You[''\u2019]ve exceeded your/i)).toBeInTheDocument();
  78. const onDemandTexts = screen.getAllByText(/on-demand budget/i);
  79. expect(onDemandTexts).toHaveLength(2);
  80. expect(
  81. screen.getByText(
  82. /during this date range and results will be skewed. We can’t collect more spans until/
  83. )
  84. ).toBeInTheDocument();
  85. expect(screen.getByText(/Dec 31, 2024/)).toBeInTheDocument();
  86. expect(screen.getByText(/or adjust your date range prior to/)).toBeInTheDocument();
  87. expect(screen.getByText(/Dec 07, 2024/)).toBeInTheDocument();
  88. expect(
  89. screen.getByRole('link', {name: /increase your on-demand budget/})
  90. ).toHaveAttribute(
  91. 'href',
  92. '/settings/billing/checkout/?referrer=trace-view&skipBundles=true'
  93. );
  94. });
  95. });