123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import {Event as EventFixture} from 'sentry-fixture/event';
- import {EventEntryStacktrace} from 'sentry-fixture/eventEntryStacktrace';
- import {Members} from 'sentry-fixture/members';
- import {Organization} from 'sentry-fixture/organization';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import ConfigStore from 'sentry/stores/configStore';
- import ProjectOwnershipModal from './modal';
- describe('Project Ownership', () => {
- const org = Organization();
- const project = TestStubs.Project();
- const issueId = '1234';
- const stacktrace = EventEntryStacktrace();
- const event = EventFixture({
- entries: [stacktrace],
- });
- const user = TestStubs.User();
- beforeEach(() => {
- ConfigStore.set('user', user);
- MockApiClient.addMockResponse({
- url: `/issues/${issueId}/tags/url/`,
- body: {
- key: 'url',
- name: 'URL',
- uniqueValues: 1,
- totalValues: 1,
- topValues: [
- {
- key: 'url',
- name: 'https://example.com/path',
- value: 'https://example.com/path',
- count: 1,
- lastSeen: '2022-08-27T03:24:53Z',
- firstSeen: '2022-08-27T03:24:53Z',
- },
- ],
- },
- });
- MockApiClient.addMockResponse({
- url: `/projects/${org.slug}/${project.slug}/ownership/`,
- body: {
- fallthrough: false,
- autoAssignment: 'Auto Assign to Suspect Commits',
- codeownersAutoSync: false,
- raw: null,
- },
- });
- // Set one frame to in-app
- stacktrace.data.frames![0].inApp = true;
- MockApiClient.addMockResponse({
- url: `/organizations/${org.slug}/members/`,
- body: Members(),
- });
- });
- afterEach(() => {
- MockApiClient.clearMockResponses();
- });
- it('renders stacktrace suggestions', () => {
- render(
- <ProjectOwnershipModal
- issueId={issueId}
- organization={org}
- project={project}
- eventData={event}
- onCancel={() => {}}
- />
- );
- // Rule builder
- expect(screen.getByLabelText('Rule pattern')).toBeInTheDocument();
- expect(screen.getByText(/Match against Issue Data/)).toBeInTheDocument();
- // First in-app (default reverse order) frame is suggested
- expect(screen.getByText('raven/base.py')).toBeInTheDocument();
- expect(screen.getByText('https://example.com/path')).toBeInTheDocument();
- });
- it('renders streamline-targeting-context suggestions', () => {
- render(
- <ProjectOwnershipModal
- issueId={issueId}
- organization={{...org, features: ['streamline-targeting-context']}}
- project={project}
- eventData={event}
- onCancel={() => {}}
- />
- );
- // Description
- expect(screen.getByText(/Assign issues based on custom rules/)).toBeInTheDocument();
- // Suggestions
- expect(
- screen.getByText(/Here’s some suggestions based on this issue/)
- ).toBeInTheDocument();
- expect(
- screen.getByText(`path:raven/base.py ${user.email}`, {exact: false})
- ).toBeInTheDocument();
- expect(
- screen.getByText(`url:*/path ${user.email}`, {exact: false})
- ).toBeInTheDocument();
- // Rule builder hidden TODO: remove when streamline-targeting-context is GA
- expect(screen.queryByLabelText('Rule pattern')).not.toBeInTheDocument();
- });
- it('can cancel', async () => {
- const onCancel = jest.fn();
- render(
- <ProjectOwnershipModal
- issueId={issueId}
- organization={org}
- project={project}
- eventData={event}
- onCancel={onCancel}
- />
- );
- // Cancel
- await userEvent.click(screen.getByText('Cancel'));
- expect(onCancel).toHaveBeenCalled();
- });
- });
|