traceLiteQuery.spec.jsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {Fragment} from 'react';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  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. render(
  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. expect(await screen.findByText('partial')).toBeInTheDocument();
  53. expect(getMock).toHaveBeenCalledTimes(1);
  54. });
  55. });