useReplaysFromIssue.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {Location} from 'history';
  2. import {reactHooks} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useReplaysFromIssue from 'sentry/views/issueDetails/groupReplays/useReplaysFromIssue';
  5. jest.mock('sentry/utils/useLocation');
  6. describe('useReplaysFromIssue', () => {
  7. const location: Location = {
  8. pathname: '',
  9. search: '',
  10. query: {},
  11. hash: '',
  12. state: undefined,
  13. action: 'PUSH',
  14. key: '',
  15. };
  16. jest.mocked(useLocation).mockReturnValue(location);
  17. const organization = TestStubs.Organization({
  18. features: ['session-replay'],
  19. });
  20. it('should fetch a list of replay ids', async () => {
  21. const MOCK_GROUP = TestStubs.Group();
  22. MockApiClient.addMockResponse({
  23. url: `/organizations/${organization.slug}/replay-count/`,
  24. method: 'GET',
  25. body: {
  26. [MOCK_GROUP.id]: ['replay42', 'replay256'],
  27. },
  28. });
  29. const {result, waitForNextUpdate} = reactHooks.renderHook(useReplaysFromIssue, {
  30. initialProps: {
  31. group: MOCK_GROUP,
  32. location,
  33. organization,
  34. },
  35. });
  36. expect(result.current).toEqual({
  37. eventView: null,
  38. fetchError: undefined,
  39. pageLinks: null,
  40. });
  41. await waitForNextUpdate();
  42. expect(result.current).toEqual({
  43. eventView: expect.objectContaining({
  44. query: 'id:[replay42,replay256]',
  45. }),
  46. fetchError: undefined,
  47. pageLinks: null,
  48. });
  49. });
  50. it('should return an empty EventView when there are no replay_ids returned from the count endpoint', async () => {
  51. const MOCK_GROUP = TestStubs.Group();
  52. MockApiClient.addMockResponse({
  53. url: `/organizations/${organization.slug}/replay-count/`,
  54. method: 'GET',
  55. body: {},
  56. });
  57. const {result, waitForNextUpdate} = reactHooks.renderHook(useReplaysFromIssue, {
  58. initialProps: {
  59. group: MOCK_GROUP,
  60. location,
  61. organization,
  62. },
  63. });
  64. expect(result.current).toEqual({
  65. eventView: null,
  66. fetchError: undefined,
  67. pageLinks: null,
  68. });
  69. await waitForNextUpdate();
  70. expect(result.current).toEqual({
  71. eventView: expect.objectContaining({
  72. query: 'id:[]',
  73. }),
  74. fetchError: undefined,
  75. pageLinks: null,
  76. });
  77. });
  78. });