onboarding.spec.tsx 3.8 KB

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