useReplaysFromIssue.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {Location} from 'history';
  2. import {reactHooks} from 'sentry-test/reactTestingLibrary';
  3. import {IssueCategory} from 'sentry/types';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useReplaysFromIssue from 'sentry/views/issueDetails/groupReplays/useReplaysFromIssue';
  6. jest.mock('sentry/utils/useLocation');
  7. describe('useReplaysFromIssue', () => {
  8. const location: Location = {
  9. pathname: '',
  10. search: '',
  11. query: {},
  12. hash: '',
  13. state: undefined,
  14. action: 'PUSH',
  15. key: '',
  16. };
  17. jest.mocked(useLocation).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 fetch a list of replay ids for a performance issue', async () => {
  52. const MOCK_GROUP = TestStubs.Group({issueCategory: IssueCategory.PERFORMANCE});
  53. MockApiClient.addMockResponse({
  54. url: `/organizations/${organization.slug}/replay-count/`,
  55. method: 'GET',
  56. body: {
  57. [MOCK_GROUP.id]: ['replay42', 'replay256'],
  58. },
  59. });
  60. const {result, waitForNextUpdate} = reactHooks.renderHook(useReplaysFromIssue, {
  61. initialProps: {
  62. group: MOCK_GROUP,
  63. location,
  64. organization,
  65. },
  66. });
  67. expect(result.current).toEqual({
  68. eventView: null,
  69. fetchError: undefined,
  70. pageLinks: null,
  71. });
  72. await waitForNextUpdate();
  73. expect(result.current).toEqual({
  74. eventView: expect.objectContaining({
  75. query: 'id:[replay42,replay256]',
  76. }),
  77. fetchError: undefined,
  78. pageLinks: null,
  79. });
  80. });
  81. it('should return an empty EventView when there are no replay_ids returned from the count endpoint', async () => {
  82. const MOCK_GROUP = TestStubs.Group();
  83. MockApiClient.addMockResponse({
  84. url: `/organizations/${organization.slug}/replay-count/`,
  85. method: 'GET',
  86. body: {},
  87. });
  88. const {result, waitForNextUpdate} = reactHooks.renderHook(useReplaysFromIssue, {
  89. initialProps: {
  90. group: MOCK_GROUP,
  91. location,
  92. organization,
  93. },
  94. });
  95. expect(result.current).toEqual({
  96. eventView: null,
  97. fetchError: undefined,
  98. pageLinks: null,
  99. });
  100. await waitForNextUpdate();
  101. expect(result.current).toEqual({
  102. eventView: expect.objectContaining({
  103. query: 'id:[]',
  104. }),
  105. fetchError: undefined,
  106. pageLinks: null,
  107. });
  108. });
  109. });