groupSimilarIssues.spec.tsx 3.2 KB

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