traceFullQuery.spec.jsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {Fragment} from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  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. const wrapper = mountWithTheme(
  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. await tick();
  52. wrapper.update();
  53. expect(getMock).toHaveBeenCalledTimes(1);
  54. expect(wrapper.find('div[data-test-id="type"]').text()).toEqual('full');
  55. });
  56. it('fetches data on mount with detailed param', async function () {
  57. const getMock = MockApiClient.addMockResponse({
  58. url: `/organizations/test-org/events-trace/${traceId}/`,
  59. body: [],
  60. match: [MockApiClient.matchQuery({detailed: '1'})],
  61. });
  62. const wrapper = mountWithTheme(
  63. <TraceFullDetailedQuery
  64. api={api}
  65. traceId={traceId}
  66. eventId={eventId}
  67. location={location}
  68. orgSlug="test-org"
  69. statsPeriod="24h"
  70. >
  71. {renderTraceFull}
  72. </TraceFullDetailedQuery>
  73. );
  74. await tick();
  75. wrapper.update();
  76. expect(getMock).toHaveBeenCalledTimes(1);
  77. expect(wrapper.find('div[data-test-id="type"]').text()).toEqual('full');
  78. });
  79. });