onboarding.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. 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. const expectedSnippet = [
  36. `Sentry.init({`,
  37. ` integrations: [`,
  38. ` Sentry.replayIntegration({`,
  39. ` networkDetailAllowUrls: ['/api/0/issues/1234'],`,
  40. ` networkRequestHeaders: ['X-Custom-Header'],`,
  41. ` networkResponseHeaders: ['X-Custom-Header'],`,
  42. ` }),`,
  43. ` ],`,
  44. `})`,
  45. ].join('\n');
  46. const snippetElem = screen.getByText(
  47. `networkRequestHeaders: ['X-Custom-Header'],`,
  48. {exact: false}
  49. );
  50. // Using toHaveTextContent would be nice here, but it loses the newlines.
  51. expect(snippetElem.innerHTML).toBe(expectedSnippet);
  52. });
  53. });
  54. describe('Url is skipped', () => {
  55. it('should render a note on the Details tab to allow this url', () => {
  56. render(
  57. <Setup
  58. item={MOCK_ITEM!}
  59. projectId="0"
  60. showSnippet={Output.URL_SKIPPED}
  61. visibleTab="details"
  62. />
  63. );
  64. expect(
  65. screen.getByText('Capture Request and Response Headers')
  66. ).toBeInTheDocument();
  67. expect(
  68. screen.getByText(
  69. textWithMarkupMatcher(
  70. 'Add the following to your networkDetailAllowUrls list to start capturing data:'
  71. )
  72. )
  73. ).toBeInTheDocument();
  74. });
  75. it('should render a note on the Requst & Response tabs to allow this url and enable capturing bodies', () => {
  76. render(
  77. <Setup
  78. item={MOCK_ITEM!}
  79. projectId="0"
  80. showSnippet={Output.URL_SKIPPED}
  81. visibleTab="request"
  82. />
  83. );
  84. expect(screen.getByText('Capture Request and Response Bodies')).toBeInTheDocument();
  85. expect(
  86. screen.getByText(
  87. textWithMarkupMatcher(
  88. 'Add the following to your networkDetailAllowUrls list to start capturing data:'
  89. )
  90. )
  91. ).toBeInTheDocument();
  92. });
  93. });
  94. describe('Body is skipped', () => {
  95. it('should render a note on the Requst & Response tabs to enable capturing bodies', () => {
  96. render(
  97. <Setup
  98. item={MOCK_ITEM!}
  99. projectId="0"
  100. showSnippet={Output.BODY_SKIPPED}
  101. visibleTab="request"
  102. />
  103. );
  104. expect(screen.getByText('Capture Request and Response Bodies')).toBeInTheDocument();
  105. expect(
  106. screen.getByText(
  107. textWithMarkupMatcher(
  108. 'Enable networkCaptureBodies: true to capture both Request and Response bodies.'
  109. )
  110. )
  111. ).toBeInTheDocument();
  112. });
  113. });
  114. describe('Showing the data', () => {
  115. it('should render a short message reminding you to configure custom headers', () => {
  116. render(
  117. <Setup
  118. item={MOCK_ITEM!}
  119. projectId="0"
  120. showSnippet={Output.DATA}
  121. visibleTab="details"
  122. />
  123. );
  124. expect(
  125. screen.getByText(
  126. textWithMarkupMatcher(
  127. 'You can capture additional headers by adding them to the networkRequestHeaders and networkResponseHeaders lists in your SDK config.'
  128. )
  129. )
  130. ).toBeInTheDocument();
  131. });
  132. });
  133. });