traceLiteQuery.spec.jsx 1.5 KB

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