onboarding.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {ReplayRequestFrameFixture} from 'sentry-fixture/replay/replaySpanFrameData';
  2. import {ReplayRecordFixture} from 'sentry-fixture/replayRecord';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import hydrateSpans from 'sentry/utils/replays/hydrateSpans';
  6. import useProjectSdkNeedsUpdate from 'sentry/utils/useProjectSdkNeedsUpdate';
  7. import {Output} from 'sentry/views/replays/detail/network/details/getOutputType';
  8. jest.mock('sentry/utils/useProjectSdkNeedsUpdate');
  9. import {Setup} from 'sentry/views/replays/detail/network/details/onboarding';
  10. const [MOCK_ITEM] = hydrateSpans(ReplayRecordFixture(), [
  11. ReplayRequestFrameFixture({
  12. op: 'resource.fetch',
  13. startTimestamp: new Date(),
  14. endTimestamp: new Date(),
  15. description: '/api/0/issues/1234',
  16. }),
  17. ]);
  18. describe('Setup', () => {
  19. jest
  20. .mocked(useProjectSdkNeedsUpdate)
  21. .mockReturnValue({isError: false, isFetching: false, needsUpdate: false});
  22. describe('Setup is not complete', () => {
  23. it('should render the full snippet when no setup is done yet', () => {
  24. const {container} = render(
  25. <Setup
  26. item={MOCK_ITEM}
  27. projectId="0"
  28. showSnippet={Output.SETUP}
  29. visibleTab="details"
  30. />
  31. );
  32. expect(
  33. screen.getByText('Capture Request and Response Headers and Bodies')
  34. ).toBeInTheDocument();
  35. expect(container.querySelector('code')).toHaveTextContent(
  36. `networkRequestHeaders: ['X-Custom-Header'],`
  37. );
  38. });
  39. });
  40. describe('Url is skipped', () => {
  41. it('should render a note on the Details tab to allow this url', () => {
  42. render(
  43. <Setup
  44. item={MOCK_ITEM}
  45. projectId="0"
  46. showSnippet={Output.URL_SKIPPED}
  47. visibleTab="details"
  48. />
  49. );
  50. expect(
  51. screen.getByText('Capture Request and Response Headers')
  52. ).toBeInTheDocument();
  53. expect(
  54. screen.getByText(
  55. textWithMarkupMatcher(
  56. 'Add the following to your networkDetailAllowUrls list to start capturing data:'
  57. )
  58. )
  59. ).toBeInTheDocument();
  60. });
  61. it('should render a note on the Requst & Response tabs to allow this url and enable capturing bodies', () => {
  62. render(
  63. <Setup
  64. item={MOCK_ITEM}
  65. projectId="0"
  66. showSnippet={Output.URL_SKIPPED}
  67. visibleTab="request"
  68. />
  69. );
  70. expect(screen.getByText('Capture Request and Response Bodies')).toBeInTheDocument();
  71. expect(
  72. screen.getByText(
  73. textWithMarkupMatcher(
  74. 'Add the following to your networkDetailAllowUrls list to start capturing data:'
  75. )
  76. )
  77. ).toBeInTheDocument();
  78. });
  79. });
  80. describe('Body is skipped', () => {
  81. it('should render a note on the Requst & Response tabs to enable capturing bodies', () => {
  82. render(
  83. <Setup
  84. item={MOCK_ITEM}
  85. projectId="0"
  86. showSnippet={Output.BODY_SKIPPED}
  87. visibleTab="request"
  88. />
  89. );
  90. expect(screen.getByText('Capture Request and Response Bodies')).toBeInTheDocument();
  91. expect(
  92. screen.getByText(
  93. textWithMarkupMatcher(
  94. 'Enable networkCaptureBodies: true to capture both Request and Response bodies.'
  95. )
  96. )
  97. ).toBeInTheDocument();
  98. });
  99. });
  100. describe('Showing the data', () => {
  101. it('should render a short message reminding you to configure custom headers', () => {
  102. render(
  103. <Setup
  104. item={MOCK_ITEM}
  105. projectId="0"
  106. showSnippet={Output.DATA}
  107. visibleTab="details"
  108. />
  109. );
  110. expect(
  111. screen.getByText(
  112. textWithMarkupMatcher(
  113. 'You can capture additional headers by adding them to the networkRequestHeaders and networkResponseHeaders lists in your SDK config.'
  114. )
  115. )
  116. ).toBeInTheDocument();
  117. });
  118. });
  119. });