123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- import {GroupsFixture} from 'sentry-fixture/groups';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {RouterContextFixture} from 'sentry-fixture/routerContextFixture';
- import {RouterFixture} from 'sentry-fixture/routerFixture';
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- waitFor,
- } from 'sentry-test/reactTestingLibrary';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import GroupSimilarIssues from 'sentry/views/issueDetails/groupSimilarIssues';
- const MockNavigate = jest.fn();
- jest.mock('sentry/utils/useNavigate', () => ({
- useNavigate: () => MockNavigate,
- }));
- jest.mock('sentry/utils/analytics');
- describe('Issues Similar View', function () {
- let mock;
- const project = ProjectFixture({
- features: ['similarity-view'],
- });
- const routerContext = RouterContextFixture([
- {
- router: {
- ...RouterFixture(),
- params: {orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'},
- },
- },
- ]);
- const scores = [
- {'exception:stacktrace:pairs': 0.375},
- {'exception:stacktrace:pairs': 0.01264},
- {'exception:stacktrace:pairs': 0.875},
- {'exception:stacktrace:pairs': 0.001488},
- ];
- const mockData = {
- similar: GroupsFixture().map((issue, i) => [issue, scores[i]]),
- };
- const router = RouterFixture();
- beforeEach(function () {
- mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/group-id/similar/?limit=50',
- body: mockData.similar,
- });
- });
- afterEach(() => {
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- });
- const selectNthSimilarItem = async (index: number) => {
- const items = await screen.findAllByTestId('similar-item-row');
- const item = items.at(index);
- expect(item).toBeDefined();
- await userEvent.click(item!);
- };
- it('renders with mocked data', async function () {
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
- await waitFor(() => expect(mock).toHaveBeenCalled());
- expect(await screen.findByText('Show 3 issues below threshold')).toBeInTheDocument();
- });
- it('can merge and redirect to new parent', async function () {
- const merge = MockApiClient.addMockResponse({
- method: 'PUT',
- url: '/projects/org-slug/project-slug/issues/',
- body: {
- merge: {children: ['123'], parent: '321'},
- },
- });
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- await selectNthSimilarItem(0);
- await userEvent.click(await screen.findByRole('button', {name: 'Merge (1)'}));
- await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
- await waitFor(() => {
- expect(merge).toHaveBeenCalledWith(
- '/projects/org-slug/project-slug/issues/',
- expect.objectContaining({
- data: {merge: 1},
- })
- );
- });
- expect(MockNavigate).toHaveBeenCalledWith(
- '/organizations/org-slug/issues/321/similar/'
- );
- });
- it('correctly shows merge count', async function () {
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- await selectNthSimilarItem(0);
- expect(screen.getByText('Merge (1)')).toBeInTheDocument();
- // Correctly show "Merge (0)" when the item is un-clicked
- await selectNthSimilarItem(0);
- expect(screen.getByText('Merge (0)')).toBeInTheDocument();
- });
- it('shows empty message', async function () {
- // Manually clear responses and add an empty response
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/group-id/similar/?limit=50',
- body: [],
- });
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
- await waitFor(() => expect(mock).toHaveBeenCalled());
- expect(
- await screen.findByText("There don't seem to be any similar issues.")
- ).toBeInTheDocument();
- expect(
- screen.queryByText(
- 'This can occur when the issue has no stacktrace or in-app frames.'
- )
- ).not.toBeInTheDocument();
- });
- });
- describe('Issues Similar Embeddings View', function () {
- let mock;
- const project = ProjectFixture({
- features: ['similarity-view', 'similarity-embeddings'],
- });
- const routerContext = RouterContextFixture([
- {
- router: {
- ...RouterFixture(),
- params: {orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'},
- },
- },
- ]);
- const similarEmbeddingsScores = [
- {exception: 0.01, message: 0.3748, shouldBeGrouped: 'Yes'},
- {exception: 0.005, message: 0.3738, shouldBeGrouped: 'Yes'},
- {exception: 0.7384, message: 0.3743, shouldBeGrouped: 'No'},
- {exception: 0.3849, message: 0.4738, shouldBeGrouped: 'No'},
- ];
- const mockData = {
- simlarEmbeddings: GroupsFixture().map((issue, i) => [
- issue,
- similarEmbeddingsScores[i],
- ]),
- };
- const router = RouterFixture();
- beforeEach(function () {
- mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/group-id/similar-issues-embeddings/?k=10&threshold=0.01',
- body: mockData.simlarEmbeddings,
- });
- });
- afterEach(() => {
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- });
- const selectNthSimilarItem = async (index: number) => {
- const items = await screen.findAllByTestId('similar-item-row');
- const item = items.at(index);
- expect(item).toBeDefined();
- await userEvent.click(item!);
- };
- it('renders with mocked data', async function () {
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
- await waitFor(() => expect(mock).toHaveBeenCalled());
- expect(await screen.findByText('Would Group')).toBeInTheDocument();
- expect(screen.queryByText('Show 3 issues below threshold')).not.toBeInTheDocument();
- });
- it('can merge and redirect to new parent', async function () {
- const merge = MockApiClient.addMockResponse({
- method: 'PUT',
- url: '/projects/org-slug/project-slug/issues/',
- body: {
- merge: {children: ['123'], parent: '321'},
- },
- });
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- await selectNthSimilarItem(0);
- await userEvent.click(await screen.findByRole('button', {name: 'Merge (1)'}));
- await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
- await waitFor(() => {
- expect(merge).toHaveBeenCalledWith(
- '/projects/org-slug/project-slug/issues/',
- expect.objectContaining({
- data: {merge: 1},
- })
- );
- });
- expect(MockNavigate).toHaveBeenCalledWith(
- '/organizations/org-slug/issues/321/similar/'
- );
- });
- it('correctly shows merge count', async function () {
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- await selectNthSimilarItem(0);
- expect(screen.getByText('Merge (1)')).toBeInTheDocument();
- // Correctly show "Merge (0)" when the item is un-clicked
- await selectNthSimilarItem(0);
- expect(screen.getByText('Merge (0)')).toBeInTheDocument();
- });
- it('sends issue similarity embeddings agree analytics', async function () {
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- await selectNthSimilarItem(0);
- await userEvent.click(await screen.findByRole('button', {name: 'Agree (1)'}));
- expect(trackAnalytics).toHaveBeenCalledTimes(1);
- expect(trackAnalytics).toHaveBeenCalledWith(
- 'issue_details.similar_issues.similarity_embeddings_feedback_recieved',
- expect.objectContaining({
- projectId: project.id,
- groupId: 'group-id',
- value: 'Yes',
- wouldGroup: similarEmbeddingsScores[0].shouldBeGrouped,
- })
- );
- });
- it('shows empty message', async function () {
- // Manually clear responses and add an empty response
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/group-id/similar-issues-embeddings/?k=10&threshold=0.01',
- body: [],
- });
- render(
- <GroupSimilarIssues
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={router.location}
- router={router}
- routeParams={router.params}
- routes={router.routes}
- route={{}}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
- await waitFor(() => expect(mock).toHaveBeenCalled());
- expect(
- await screen.findByText(
- "There don't seem to be any similar issues. This can occur when the issue has no stacktrace or in-app frames."
- )
- ).toBeInTheDocument();
- });
- });
|