groupSimilar.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {browserHistory} from 'react-router';
  2. import React from 'react';
  3. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  4. import GroupSimilar from 'app/views/organizationGroupDetails/groupSimilar';
  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:application-chunks': 0.000235,
  24. 'exception:stacktrace:pairs': 0.001488,
  25. },
  26. ];
  27. const mockData = {
  28. similar: TestStubs.Groups().map((issue, i) => [issue, scores[i]]),
  29. };
  30. beforeEach(function() {
  31. mock = MockApiClient.addMockResponse({
  32. url: '/issues/group-id/similar/?limit=50',
  33. body: mockData.similar,
  34. });
  35. });
  36. it('renders initially with loading component', function() {
  37. const component = shallow(
  38. <GroupSimilar
  39. project={project}
  40. params={{orgId: 'org-slug', groupId: 'group-id'}}
  41. location={{}}
  42. />,
  43. routerContext
  44. );
  45. expect(component).toMatchSnapshot();
  46. });
  47. it('renders with mocked data', async function() {
  48. const wrapper = mountWithTheme(
  49. <GroupSimilar
  50. project={project}
  51. query=""
  52. params={{orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'}}
  53. location={{}}
  54. />,
  55. routerContext
  56. );
  57. await tick();
  58. await tick();
  59. wrapper.update();
  60. expect(mock).toHaveBeenCalled();
  61. expect(wrapper.find('GroupGroupingView')).toMatchSnapshot();
  62. });
  63. it('can merge and redirect to new parent', async function() {
  64. const wrapper = mountWithTheme(
  65. <GroupSimilar
  66. project={project}
  67. params={{orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'}}
  68. location={{}}
  69. />,
  70. routerContext
  71. );
  72. const merge = MockApiClient.addMockResponse({
  73. method: 'PUT',
  74. url: '/projects/org-slug/project-slug/issues/',
  75. body: {
  76. merge: {children: ['123'], parent: '321'},
  77. },
  78. });
  79. await tick();
  80. await tick();
  81. wrapper.update();
  82. wrapper
  83. .find('[data-test-id="similar-item-row"]')
  84. .first()
  85. .simulate('click');
  86. await tick();
  87. wrapper.update();
  88. wrapper.find('[data-test-id="merge"] a').simulate('click');
  89. wrapper.find('Button[data-test-id="confirm-button"]').simulate('click');
  90. await tick();
  91. wrapper.update();
  92. expect(merge).toHaveBeenCalledWith(
  93. '/projects/org-slug/project-slug/issues/',
  94. expect.objectContaining({
  95. data: {merge: 1},
  96. })
  97. );
  98. expect(browserHistory.push).toHaveBeenCalledWith(
  99. '/organizations/org-slug/issues/321/similar/'
  100. );
  101. });
  102. });