123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {openModal} from 'sentry/actionCreators/modal';
- import {Client} from 'sentry/api';
- import ProjectOwnership from 'sentry/views/settings/project/projectOwnership';
- jest.mock('sentry/actionCreators/modal');
- describe('Project Ownership', function () {
- let org = TestStubs.Organization();
- const project = TestStubs.ProjectDetails();
- beforeEach(function () {
- Client.clearMockResponses();
- Client.addMockResponse({
- url: `/projects/${org.slug}/${project.slug}/ownership/`,
- method: 'GET',
- body: {
- fallthrough: false,
- autoAssignment: false,
- },
- });
- Client.addMockResponse({
- url: `/organizations/${org.slug}/code-mappings/`,
- query: {project: project.id},
- method: 'GET',
- body: [],
- });
- Client.addMockResponse({
- url: `/organizations/${org.slug}/integrations/`,
- query: {features: 'codeowners'},
- method: 'GET',
- body: [TestStubs.GithubIntegrationConfig()],
- });
- Client.addMockResponse({
- url: `/projects/${org.slug}/${project.slug}/codeowners/`,
- features: {expand: 'codeMapping'},
- method: 'GET',
- body: [],
- });
- });
- describe('without codeowners', function () {
- it('renders', function () {
- const wrapper = mountWithTheme(
- <ProjectOwnership
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />
- );
- expect(wrapper).toSnapshot();
- // only rendered when `integrations-codeowners` feature flag enabled
- expect(wrapper.find('CodeOwnerButton').exists()).toBe(false);
- });
- });
- describe('codeowner action button', function () {
- it('renders button', function () {
- org = TestStubs.Organization({
- features: ['integrations-codeowners'],
- access: ['org:integrations'],
- });
- const wrapper = mountWithTheme(
- <ProjectOwnership
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />,
- TestStubs.routerContext([{organization: org}])
- );
- expect(wrapper.find('CodeOwnerButton').exists()).toBe(true);
- });
- it('clicking button opens modal', function () {
- org = TestStubs.Organization({
- features: ['integrations-codeowners'],
- access: ['org:integrations'],
- });
- const wrapper = mountWithTheme(
- <ProjectOwnership
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />,
- TestStubs.routerContext([{organization: org}])
- );
- wrapper.find('[data-test-id="add-codeowner-button"] button').simulate('click');
- expect(openModal).toHaveBeenCalled();
- });
- it('render request to add if no permissions', function () {
- org = TestStubs.Organization({features: ['integrations-codeowners'], access: []});
- const wrapper = mountWithTheme(
- <ProjectOwnership
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />,
- TestStubs.routerContext([{organization: org}])
- );
- expect(
- wrapper.find('[data-test-id="add-codeowner-request-button"] button').exists()
- ).toBe(true);
- });
- });
- });
|