index.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. waitFor,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import GroupSimilarIssues from 'sentry/views/issueDetails/groupSimilarIssues';
  9. const MockNavigate = jest.fn();
  10. jest.mock('sentry/utils/useNavigate', () => ({
  11. useNavigate: () => MockNavigate,
  12. }));
  13. describe('Issues Similar View', function () {
  14. let mock;
  15. const project = TestStubs.Project({
  16. features: ['similarity-view'],
  17. });
  18. const routerContext = TestStubs.routerContext([
  19. {
  20. router: {
  21. ...TestStubs.router(),
  22. params: {orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'},
  23. },
  24. },
  25. ]);
  26. const scores = [
  27. {'exception:stacktrace:pairs': 0.375},
  28. {'exception:stacktrace:pairs': 0.01264},
  29. {'exception:stacktrace:pairs': 0.875},
  30. {'exception:stacktrace:pairs': 0.001488},
  31. ];
  32. const mockData = {
  33. similar: TestStubs.Groups().map((issue, i) => [issue, scores[i]]),
  34. };
  35. const router = TestStubs.router();
  36. beforeEach(function () {
  37. mock = MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/issues/group-id/similar/?limit=50',
  39. body: mockData.similar,
  40. });
  41. });
  42. afterEach(() => {
  43. MockApiClient.clearMockResponses();
  44. jest.clearAllMocks();
  45. });
  46. it('renders with mocked data', async function () {
  47. render(
  48. <GroupSimilarIssues
  49. project={project}
  50. params={{orgId: 'org-slug', groupId: 'group-id'}}
  51. location={router.location}
  52. router={router}
  53. routeParams={router.params}
  54. routes={router.routes}
  55. route={{}}
  56. />,
  57. {context: routerContext}
  58. );
  59. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  60. await waitFor(() => expect(mock).toHaveBeenCalled());
  61. });
  62. it('can merge and redirect to new parent', async function () {
  63. const merge = MockApiClient.addMockResponse({
  64. method: 'PUT',
  65. url: '/projects/org-slug/project-slug/issues/',
  66. body: {
  67. merge: {children: ['123'], parent: '321'},
  68. },
  69. });
  70. render(
  71. <GroupSimilarIssues
  72. project={project}
  73. params={{orgId: 'org-slug', groupId: 'group-id'}}
  74. location={router.location}
  75. router={router}
  76. routeParams={router.params}
  77. routes={router.routes}
  78. route={{}}
  79. />,
  80. {context: routerContext}
  81. );
  82. renderGlobalModal();
  83. await userEvent.click(await screen.findByTestId('similar-item-row'));
  84. await userEvent.click(await screen.findByRole('button', {name: 'Merge (1)'}));
  85. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  86. await waitFor(() => {
  87. expect(merge).toHaveBeenCalledWith(
  88. '/projects/org-slug/project-slug/issues/',
  89. expect.objectContaining({
  90. data: {merge: 1},
  91. })
  92. );
  93. });
  94. expect(MockNavigate).toHaveBeenCalledWith(
  95. '/organizations/org-slug/issues/321/similar/'
  96. );
  97. });
  98. });