useReplaysFromIssue.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import type {Location} from 'history';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {renderHook, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import {IssueCategory} from 'sentry/types/group';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useReplaysFromIssue from 'sentry/views/issueDetails/groupReplays/useReplaysFromIssue';
  8. jest.mock('sentry/utils/useLocation');
  9. describe('useReplaysFromIssue', () => {
  10. const location: Location = {
  11. pathname: '',
  12. search: '',
  13. query: {},
  14. hash: '',
  15. state: undefined,
  16. action: 'PUSH',
  17. key: '',
  18. };
  19. jest.mocked(useLocation).mockReturnValue(location);
  20. const organization = OrganizationFixture({
  21. features: ['session-replay'],
  22. });
  23. it('should fetch a list of replay ids', async () => {
  24. const MOCK_GROUP = GroupFixture();
  25. MockApiClient.addMockResponse({
  26. url: `/organizations/${organization.slug}/replay-count/`,
  27. method: 'GET',
  28. body: {
  29. [MOCK_GROUP.id]: ['replay42', 'replay256'],
  30. },
  31. });
  32. const {result} = renderHook(useReplaysFromIssue, {
  33. initialProps: {
  34. group: MOCK_GROUP,
  35. location,
  36. organization,
  37. },
  38. });
  39. expect(result.current).toEqual({
  40. eventView: null,
  41. fetchError: undefined,
  42. isFetching: true,
  43. pageLinks: null,
  44. });
  45. await waitFor(() =>
  46. expect(result.current).toEqual({
  47. eventView: expect.objectContaining({
  48. query: 'id:[replay42,replay256]',
  49. }),
  50. fetchError: undefined,
  51. isFetching: false,
  52. pageLinks: null,
  53. })
  54. );
  55. });
  56. it('should fetch a list of replay ids for a performance issue', async () => {
  57. const MOCK_GROUP = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/replay-count/`,
  60. method: 'GET',
  61. body: {
  62. [MOCK_GROUP.id]: ['replay42', 'replay256'],
  63. },
  64. });
  65. const {result} = renderHook(useReplaysFromIssue, {
  66. initialProps: {
  67. group: MOCK_GROUP,
  68. location,
  69. organization,
  70. },
  71. });
  72. expect(result.current).toEqual({
  73. eventView: null,
  74. fetchError: undefined,
  75. isFetching: true,
  76. pageLinks: null,
  77. });
  78. await waitFor(() =>
  79. expect(result.current).toEqual({
  80. eventView: expect.objectContaining({
  81. query: 'id:[replay42,replay256]',
  82. }),
  83. fetchError: undefined,
  84. isFetching: false,
  85. pageLinks: null,
  86. })
  87. );
  88. });
  89. it('should return an empty EventView when there are no replay_ids returned from the count endpoint', async () => {
  90. const MOCK_GROUP = GroupFixture();
  91. MockApiClient.addMockResponse({
  92. url: `/organizations/${organization.slug}/replay-count/`,
  93. method: 'GET',
  94. body: {},
  95. });
  96. const {result} = renderHook(useReplaysFromIssue, {
  97. initialProps: {
  98. group: MOCK_GROUP,
  99. location,
  100. organization,
  101. },
  102. });
  103. expect(result.current).toEqual({
  104. eventView: null,
  105. fetchError: undefined,
  106. isFetching: true,
  107. pageLinks: null,
  108. });
  109. await waitFor(() =>
  110. expect(result.current).toEqual({
  111. eventView: null,
  112. fetchError: undefined,
  113. isFetching: false,
  114. pageLinks: null,
  115. })
  116. );
  117. });
  118. });