similarIssues.spec.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. import {GroupsFixture} from 'sentry-fixture/groups';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {RouterFixture} from 'sentry-fixture/routerFixture';
  4. import {
  5. render,
  6. renderGlobalModal,
  7. screen,
  8. userEvent,
  9. waitFor,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import GroupSimilarIssues from 'sentry/views/issueDetails/groupSimilarIssues/similarIssues';
  12. const MockNavigate = jest.fn();
  13. jest.mock('sentry/utils/useNavigate', () => ({
  14. useNavigate: () => MockNavigate,
  15. }));
  16. jest.mock('sentry/utils/analytics');
  17. describe('Issues Similar View', function () {
  18. let mock: jest.Mock;
  19. const project = ProjectFixture({
  20. features: ['similarity-view'],
  21. });
  22. const router = RouterFixture({
  23. params: {orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'},
  24. });
  25. const scores = [
  26. {'exception:stacktrace:pairs': 0.375},
  27. {'exception:stacktrace:pairs': 0.01264},
  28. {'exception:stacktrace:pairs': 0.875},
  29. {'exception:stacktrace:pairs': 0.001488},
  30. ];
  31. const mockData = {
  32. similar: GroupsFixture().map((issue, i) => [issue, scores[i]]),
  33. };
  34. beforeEach(function () {
  35. mock = MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/issues/group-id/similar/?limit=50',
  37. body: mockData.similar,
  38. });
  39. });
  40. afterEach(() => {
  41. MockApiClient.clearMockResponses();
  42. jest.clearAllMocks();
  43. });
  44. const selectNthSimilarItem = async (index: number) => {
  45. const items = await screen.findAllByTestId('similar-item-row');
  46. const item = items.at(index);
  47. expect(item).toBeDefined();
  48. await userEvent.click(item!);
  49. };
  50. it('renders with mocked data', async function () {
  51. render(
  52. <GroupSimilarIssues
  53. project={project}
  54. params={{orgId: 'org-slug', groupId: 'group-id'}}
  55. location={router.location}
  56. />,
  57. {router}
  58. );
  59. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  60. await waitFor(() => expect(mock).toHaveBeenCalled());
  61. expect(await screen.findByText('Show 3 issues below threshold')).toBeInTheDocument();
  62. });
  63. it('can merge and redirect to new parent', async function () {
  64. const merge = MockApiClient.addMockResponse({
  65. method: 'PUT',
  66. url: '/projects/org-slug/project-slug/issues/',
  67. body: {
  68. merge: {children: ['123'], parent: '321'},
  69. },
  70. });
  71. render(
  72. <GroupSimilarIssues
  73. project={project}
  74. params={{orgId: 'org-slug', groupId: 'group-id'}}
  75. location={router.location}
  76. />,
  77. {router}
  78. );
  79. renderGlobalModal();
  80. await selectNthSimilarItem(0);
  81. await userEvent.click(await screen.findByRole('button', {name: 'Merge (1)'}));
  82. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  83. await waitFor(() => {
  84. expect(merge).toHaveBeenCalledWith(
  85. '/projects/org-slug/project-slug/issues/',
  86. expect.objectContaining({
  87. data: {merge: 1},
  88. })
  89. );
  90. });
  91. expect(MockNavigate).toHaveBeenCalledWith(
  92. '/organizations/org-slug/issues/321/similar/'
  93. );
  94. });
  95. it('correctly shows merge count', async function () {
  96. render(
  97. <GroupSimilarIssues
  98. project={project}
  99. params={{orgId: 'org-slug', groupId: 'group-id'}}
  100. location={router.location}
  101. />,
  102. {router}
  103. );
  104. renderGlobalModal();
  105. await selectNthSimilarItem(0);
  106. expect(screen.getByText('Merge (1)')).toBeInTheDocument();
  107. // Correctly show "Merge (0)" when the item is un-clicked
  108. await selectNthSimilarItem(0);
  109. expect(screen.getByText('Merge (0)')).toBeInTheDocument();
  110. });
  111. it('shows empty message', async function () {
  112. // Manually clear responses and add an empty response
  113. MockApiClient.clearMockResponses();
  114. jest.clearAllMocks();
  115. mock = MockApiClient.addMockResponse({
  116. url: '/organizations/org-slug/issues/group-id/similar/?limit=50',
  117. body: [],
  118. });
  119. render(
  120. <GroupSimilarIssues
  121. project={project}
  122. params={{orgId: 'org-slug', groupId: 'group-id'}}
  123. location={router.location}
  124. />,
  125. {router}
  126. );
  127. renderGlobalModal();
  128. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  129. await waitFor(() => expect(mock).toHaveBeenCalled());
  130. expect(
  131. await screen.findByText("There don't seem to be any similar issues.")
  132. ).toBeInTheDocument();
  133. expect(
  134. screen.queryByText(
  135. 'This can occur when the issue has no stacktrace or in-app frames.'
  136. )
  137. ).not.toBeInTheDocument();
  138. });
  139. });
  140. describe('Issues Similar Embeddings View', function () {
  141. let mock;
  142. const project = ProjectFixture({
  143. features: ['similarity-view', 'similarity-embeddings'],
  144. });
  145. const router = RouterFixture({
  146. params: {orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'},
  147. });
  148. const similarEmbeddingsScores = [
  149. {exception: 0.01, shouldBeGrouped: 'Yes'},
  150. {exception: 0.005, shouldBeGrouped: 'Yes'},
  151. {exception: 0.7384, shouldBeGrouped: 'No'},
  152. {exception: 0.3849, shouldBeGrouped: 'No'},
  153. ];
  154. const mockData = {
  155. simlarEmbeddings: GroupsFixture().map((issue, i) => [
  156. issue,
  157. similarEmbeddingsScores[i],
  158. ]),
  159. };
  160. beforeEach(function () {
  161. mock = MockApiClient.addMockResponse({
  162. url: '/organizations/org-slug/issues/group-id/similar-issues-embeddings/?k=10&threshold=0.01&useReranking=true',
  163. body: mockData.simlarEmbeddings,
  164. });
  165. });
  166. afterEach(() => {
  167. MockApiClient.clearMockResponses();
  168. jest.clearAllMocks();
  169. });
  170. const selectNthSimilarItem = async (index: number) => {
  171. const items = await screen.findAllByTestId('similar-item-row');
  172. const item = items.at(index);
  173. expect(item).toBeDefined();
  174. await userEvent.click(item!);
  175. };
  176. it('renders with mocked data', async function () {
  177. render(
  178. <GroupSimilarIssues
  179. project={project}
  180. params={{orgId: 'org-slug', groupId: 'group-id'}}
  181. location={router.location}
  182. />,
  183. {router}
  184. );
  185. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  186. await waitFor(() => expect(mock).toHaveBeenCalled());
  187. expect(screen.queryByText('Show 3 issues below threshold')).not.toBeInTheDocument();
  188. });
  189. it('can merge and redirect to new parent', async function () {
  190. const merge = MockApiClient.addMockResponse({
  191. method: 'PUT',
  192. url: '/projects/org-slug/project-slug/issues/',
  193. body: {
  194. merge: {children: ['123'], parent: '321'},
  195. },
  196. });
  197. render(
  198. <GroupSimilarIssues
  199. project={project}
  200. params={{orgId: 'org-slug', groupId: 'group-id'}}
  201. location={router.location}
  202. />,
  203. {router}
  204. );
  205. renderGlobalModal();
  206. await selectNthSimilarItem(0);
  207. await userEvent.click(await screen.findByRole('button', {name: 'Merge (1)'}));
  208. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  209. await waitFor(() => {
  210. expect(merge).toHaveBeenCalledWith(
  211. '/projects/org-slug/project-slug/issues/',
  212. expect.objectContaining({
  213. data: {merge: 1},
  214. })
  215. );
  216. });
  217. expect(MockNavigate).toHaveBeenCalledWith(
  218. '/organizations/org-slug/issues/321/similar/'
  219. );
  220. });
  221. it('correctly shows merge count', async function () {
  222. render(
  223. <GroupSimilarIssues
  224. project={project}
  225. params={{orgId: 'org-slug', groupId: 'group-id'}}
  226. location={router.location}
  227. />,
  228. {router}
  229. );
  230. renderGlobalModal();
  231. await selectNthSimilarItem(0);
  232. expect(screen.getByText('Merge (1)')).toBeInTheDocument();
  233. // Correctly show "Merge (0)" when the item is un-clicked
  234. await selectNthSimilarItem(0);
  235. expect(screen.getByText('Merge (0)')).toBeInTheDocument();
  236. });
  237. it('shows empty message', async function () {
  238. // Manually clear responses and add an empty response
  239. MockApiClient.clearMockResponses();
  240. jest.clearAllMocks();
  241. mock = MockApiClient.addMockResponse({
  242. url: '/organizations/org-slug/issues/group-id/similar-issues-embeddings/?k=10&threshold=0.01&useReranking=true',
  243. body: [],
  244. });
  245. render(
  246. <GroupSimilarIssues
  247. project={project}
  248. params={{orgId: 'org-slug', groupId: 'group-id'}}
  249. location={router.location}
  250. />,
  251. {router}
  252. );
  253. renderGlobalModal();
  254. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  255. await waitFor(() => expect(mock).toHaveBeenCalled());
  256. expect(
  257. await screen.findByText(
  258. "There don't seem to be any similar issues. This can occur when the issue has no stacktrace or in-app frames."
  259. )
  260. ).toBeInTheDocument();
  261. });
  262. });