index.spec.tsx 3.1 KB

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