onboarding.spec.tsx 3.7 KB

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