groupSimilarIssues.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. beforeEach(function () {
  33. mock = MockApiClient.addMockResponse({
  34. url: '/issues/group-id/similar/?limit=50&version=1',
  35. body: mockData.similar,
  36. });
  37. });
  38. afterEach(() => {
  39. MockApiClient.clearMockResponses();
  40. jest.clearAllMocks();
  41. });
  42. it('renders initially with loading component', function () {
  43. render(
  44. <GroupSimilarIssues
  45. project={project}
  46. params={{orgId: 'org-slug', groupId: 'group-id'}}
  47. location={{}}
  48. />,
  49. {context: routerContext}
  50. );
  51. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  52. });
  53. it('renders with mocked data', async function () {
  54. const wrapper = render(
  55. <GroupSimilarIssues
  56. project={project}
  57. query=""
  58. params={{orgId: 'org-slug', groupId: 'group-id'}}
  59. location={{}}
  60. />,
  61. {context: routerContext}
  62. );
  63. await waitFor(() => expect(mock).toHaveBeenCalled());
  64. expect(wrapper.container).toSnapshot();
  65. });
  66. it('can merge and redirect to new parent', async function () {
  67. const merge = MockApiClient.addMockResponse({
  68. method: 'PUT',
  69. url: '/projects/org-slug/project-slug/issues/',
  70. body: {
  71. merge: {children: ['123'], parent: '321'},
  72. },
  73. });
  74. render(
  75. <GroupSimilarIssues
  76. project={project}
  77. params={{orgId: 'org-slug', groupId: 'group-id'}}
  78. location={{}}
  79. />,
  80. {context: routerContext}
  81. );
  82. renderGlobalModal();
  83. userEvent.click(await screen.findByTestId('similar-item-row'));
  84. userEvent.click(await screen.findByRole('button', {name: 'Merge (1)'}));
  85. userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  86. await waitFor(() => {
  87. expect(merge).toHaveBeenCalledWith(
  88. '/projects/org-slug/project-slug/issues/',
  89. expect.objectContaining({
  90. data: {merge: 1},
  91. })
  92. );
  93. });
  94. expect(browserHistory.push).toHaveBeenCalledWith(
  95. '/organizations/org-slug/issues/321/similar/'
  96. );
  97. });
  98. });