useReplaysFromIssue.spec.tsx 3.3 KB

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