index.spec.tsx 3.0 KB

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