index.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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: '/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. const wrapper = 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. expect(wrapper.container).toSnapshot();
  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. });