groupSimilarIssues.spec.jsx 3.0 KB

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