useReplaysFromIssue.spec.tsx 3.2 KB

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