projects.spec.tsx 1.6 KB

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