projects.spec.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {_debouncedLoadStats} from 'sentry/actionCreators/projects';
  3. import {Client} from 'sentry/api';
  4. describe('Projects ActionCreators', function () {
  5. const api = new Client();
  6. const {organization, project} = initializeOrg();
  7. it('loadStatsForProject', function () {
  8. jest.useFakeTimers();
  9. const mock = MockApiClient.addMockResponse({
  10. url: '/organizations/org-slug/projects/',
  11. });
  12. expect(mock).not.toHaveBeenCalled();
  13. _debouncedLoadStats(api, new Set([...Array(50)].map((_, i) => String(i))), {
  14. projectId: project.id,
  15. orgId: organization.slug,
  16. });
  17. expect(mock).toHaveBeenCalledTimes(5);
  18. expect(mock).toHaveBeenLastCalledWith(
  19. '/organizations/org-slug/projects/',
  20. expect.objectContaining({
  21. query: {
  22. statsPeriod: '24h',
  23. query: 'id:40 id:41 id:42 id:43 id:44 id:45 id:46 id:47 id:48 id:49',
  24. },
  25. })
  26. );
  27. });
  28. it('loadStatsForProject() with additional query', function () {
  29. jest.useFakeTimers();
  30. const mock = MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/projects/',
  32. });
  33. expect(mock).not.toHaveBeenCalled();
  34. _debouncedLoadStats(api, new Set(['1', '2', '3']), {
  35. projectId: project.id,
  36. orgId: organization.slug,
  37. query: {transactionStats: '1'},
  38. });
  39. expect(mock).toHaveBeenCalledTimes(1);
  40. expect(mock).toHaveBeenLastCalledWith(
  41. '/organizations/org-slug/projects/',
  42. expect.objectContaining({
  43. query: {
  44. statsPeriod: '24h',
  45. query: 'id:1 id:2 id:3',
  46. transactionStats: '1',
  47. },
  48. })
  49. );
  50. });
  51. });