useReplaysFromIssue.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import type {Location} from 'history';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {reactHooks} from 'sentry-test/reactTestingLibrary';
  5. import {IssueCategory} from 'sentry/types';
  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, waitForNextUpdate} = reactHooks.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 waitForNextUpdate();
  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. it('should fetch a list of replay ids for a performance issue', async () => {
  56. const MOCK_GROUP = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  57. MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/replay-count/`,
  59. method: 'GET',
  60. body: {
  61. [MOCK_GROUP.id]: ['replay42', 'replay256'],
  62. },
  63. });
  64. const {result, waitForNextUpdate} = reactHooks.renderHook(useReplaysFromIssue, {
  65. initialProps: {
  66. group: MOCK_GROUP,
  67. location,
  68. organization,
  69. },
  70. });
  71. expect(result.current).toEqual({
  72. eventView: null,
  73. fetchError: undefined,
  74. isFetching: true,
  75. pageLinks: null,
  76. });
  77. await waitForNextUpdate();
  78. expect(result.current).toEqual({
  79. eventView: expect.objectContaining({
  80. query: 'id:[replay42,replay256]',
  81. }),
  82. fetchError: undefined,
  83. isFetching: false,
  84. pageLinks: null,
  85. });
  86. });
  87. it('should return an empty EventView when there are no replay_ids returned from the count endpoint', async () => {
  88. const MOCK_GROUP = GroupFixture();
  89. MockApiClient.addMockResponse({
  90. url: `/organizations/${organization.slug}/replay-count/`,
  91. method: 'GET',
  92. body: {},
  93. });
  94. const {result, waitForNextUpdate} = reactHooks.renderHook(useReplaysFromIssue, {
  95. initialProps: {
  96. group: MOCK_GROUP,
  97. location,
  98. organization,
  99. },
  100. });
  101. expect(result.current).toEqual({
  102. eventView: null,
  103. fetchError: undefined,
  104. isFetching: true,
  105. pageLinks: null,
  106. });
  107. await waitForNextUpdate();
  108. expect(result.current).toEqual({
  109. eventView: null,
  110. fetchError: undefined,
  111. isFetching: false,
  112. pageLinks: null,
  113. });
  114. });
  115. });