traceFullQuery.spec.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Fragment} from 'react';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {Client} from 'sentry/api';
  4. import {
  5. TraceFullDetailedQuery,
  6. TraceFullQuery,
  7. } from 'sentry/utils/performance/quickTrace/traceFullQuery';
  8. const traceId = 'abcdef1234567890';
  9. const eventId = '0987654321fedcba';
  10. function renderTraceFull({isLoading, error, type}) {
  11. if (isLoading) {
  12. return 'loading';
  13. }
  14. if (error !== null) {
  15. return error;
  16. }
  17. return (
  18. <Fragment>
  19. <div key="type" data-test-id="type">
  20. {type}
  21. </div>
  22. </Fragment>
  23. );
  24. }
  25. describe('TraceFullQuery', 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', async function () {
  35. const getMock = MockApiClient.addMockResponse({
  36. url: `/organizations/test-org/events-trace/${traceId}/`,
  37. body: [],
  38. });
  39. render(
  40. <TraceFullQuery
  41. api={api}
  42. traceId={traceId}
  43. eventId={eventId}
  44. location={location}
  45. orgSlug="test-org"
  46. statsPeriod="24h"
  47. >
  48. {renderTraceFull}
  49. </TraceFullQuery>
  50. );
  51. expect(await screen.findByTestId('type')).toHaveTextContent('full');
  52. expect(getMock).toHaveBeenCalledTimes(1);
  53. });
  54. it('fetches data on mount with detailed param', async function () {
  55. const getMock = MockApiClient.addMockResponse({
  56. url: `/organizations/test-org/events-trace/${traceId}/`,
  57. body: [],
  58. match: [MockApiClient.matchQuery({detailed: '1'})],
  59. });
  60. render(
  61. <TraceFullDetailedQuery
  62. api={api}
  63. traceId={traceId}
  64. eventId={eventId}
  65. location={location}
  66. orgSlug="test-org"
  67. statsPeriod="24h"
  68. >
  69. {renderTraceFull}
  70. </TraceFullDetailedQuery>
  71. );
  72. expect(await screen.findByTestId('type')).toHaveTextContent('full');
  73. expect(getMock).toHaveBeenCalledTimes(1);
  74. });
  75. });