123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import {browserHistory} from 'react-router';
- import React from 'react';
- import {mountWithTheme, shallow} from 'sentry-test/enzyme';
- import GroupSimilar from 'app/views/organizationGroupDetails/groupSimilar';
- describe('Issues Similar View', function() {
- let mock;
- const project = TestStubs.Project({
- features: ['similarity-view'],
- });
- const routerContext = TestStubs.routerContext([
- {
- router: {
- ...TestStubs.router(),
- 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:application-chunks': 0.000235,
- 'exception:stacktrace:pairs': 0.001488,
- },
- ];
- const mockData = {
- similar: TestStubs.Groups().map((issue, i) => [issue, scores[i]]),
- };
- beforeEach(function() {
- mock = MockApiClient.addMockResponse({
- url: '/issues/group-id/similar/?limit=50',
- body: mockData.similar,
- });
- });
- it('renders initially with loading component', function() {
- const component = shallow(
- <GroupSimilar
- project={project}
- params={{orgId: 'org-slug', groupId: 'group-id'}}
- location={{}}
- />,
- routerContext
- );
- expect(component).toMatchSnapshot();
- });
- it('renders with mocked data', async function() {
- const wrapper = mountWithTheme(
- <GroupSimilar
- project={project}
- query=""
- params={{orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'}}
- location={{}}
- />,
- routerContext
- );
- await tick();
- await tick();
- wrapper.update();
- expect(mock).toHaveBeenCalled();
- expect(wrapper.find('GroupGroupingView')).toMatchSnapshot();
- });
- it('can merge and redirect to new parent', async function() {
- const wrapper = mountWithTheme(
- <GroupSimilar
- project={project}
- params={{orgId: 'org-slug', projectId: 'project-slug', groupId: 'group-id'}}
- location={{}}
- />,
- routerContext
- );
- const merge = MockApiClient.addMockResponse({
- method: 'PUT',
- url: '/projects/org-slug/project-slug/issues/',
- body: {
- merge: {children: ['123'], parent: '321'},
- },
- });
- await tick();
- await tick();
- wrapper.update();
- wrapper
- .find('[data-test-id="similar-item-row"]')
- .first()
- .simulate('click');
- await tick();
- wrapper.update();
- wrapper.find('[data-test-id="merge"] a').simulate('click');
- wrapper.find('Button[data-test-id="confirm-button"]').simulate('click');
- await tick();
- wrapper.update();
- expect(merge).toHaveBeenCalledWith(
- '/projects/org-slug/project-slug/issues/',
- expect.objectContaining({
- data: {merge: 1},
- })
- );
- expect(browserHistory.push).toHaveBeenCalledWith(
- '/organizations/org-slug/issues/321/similar/'
- );
- });
- });
|