traceMetaQuery.spec.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {Fragment} from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'sentry/api';
  4. import TraceMetaQuery from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  5. const traceId = 'abcdef1234567890';
  6. function renderMeta({isLoading, error, meta}) {
  7. if (isLoading) {
  8. return 'loading';
  9. }
  10. if (error !== null) {
  11. return error;
  12. }
  13. return (
  14. <Fragment>
  15. <div key="projects" data-test-id="projects">
  16. {meta.projects}
  17. </div>
  18. <div key="transactions" data-test-id="transactions">
  19. {meta.transactions}
  20. </div>
  21. <div key="errors" data-test-id="errors">
  22. {meta.errors}
  23. </div>
  24. </Fragment>
  25. );
  26. }
  27. describe('TraceMetaQuery', function () {
  28. let api, location;
  29. beforeEach(function () {
  30. api = new Client();
  31. location = {
  32. pathname: '/',
  33. query: {},
  34. };
  35. });
  36. it('fetches data on mount', async function () {
  37. const getMock = MockApiClient.addMockResponse({
  38. url: `/organizations/test-org/events-trace-meta/${traceId}/`,
  39. body: {
  40. projects: 4,
  41. transactions: 5,
  42. errors: 2,
  43. },
  44. });
  45. const wrapper = mountWithTheme(
  46. <TraceMetaQuery
  47. api={api}
  48. traceId={traceId}
  49. location={location}
  50. orgSlug="test-org"
  51. statsPeriod="24h"
  52. >
  53. {renderMeta}
  54. </TraceMetaQuery>
  55. );
  56. await tick();
  57. wrapper.update();
  58. expect(getMock).toHaveBeenCalledTimes(1);
  59. expect(wrapper.find('div[data-test-id="projects"]').text()).toEqual('4');
  60. expect(wrapper.find('div[data-test-id="transactions"]').text()).toEqual('5');
  61. expect(wrapper.find('div[data-test-id="errors"]').text()).toEqual('2');
  62. });
  63. });