useReplaysFromIssue.spec.tsx 2.3 KB

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