index.spec.tsx 2.9 KB

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