123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {openCreateOwnershipRule} from 'sentry/actionCreators/modal';
- import OwnedBy from 'sentry/components/group/ownedBy';
- import MemberListStore from 'sentry/stores/memberListStore';
- import {buildTeamId, buildUserId} from 'sentry/utils';
- jest.mock('sentry/actionCreators/modal');
- describe('Group > OwnedBy', () => {
- it('renders unowned', () => {
- const group = TestStubs.Group();
- render(
- <OwnedBy
- group={group}
- organization={TestStubs.Organization()}
- project={TestStubs.Project()}
- />
- );
- expect(screen.getByText('No-one')).toBeInTheDocument();
- });
- it('renders team owner', () => {
- const team = TestStubs.Team();
- const group = TestStubs.Group({
- owners: [
- {
- date_added: new Date(),
- owner: buildTeamId(team.id),
- type: 'codeowners',
- },
- ],
- });
- render(
- <OwnedBy
- group={group}
- organization={TestStubs.Organization()}
- project={TestStubs.Project({teams: [team]})}
- />
- );
- expect(screen.getByText(`#${team.slug}`)).toBeInTheDocument();
- });
- it('renders member owner', () => {
- const user = TestStubs.User();
- MemberListStore.loadInitialData([user]);
- const group = TestStubs.Group({
- owners: [
- {
- date_added: new Date(),
- owner: buildUserId(user.id),
- type: 'codeowners',
- },
- ],
- });
- render(
- <OwnedBy
- group={group}
- organization={TestStubs.Organization()}
- project={TestStubs.Project()}
- />
- );
- expect(screen.getByText(user.name)).toBeInTheDocument();
- });
- it('does not render suspect commit', () => {
- const user = TestStubs.User();
- MemberListStore.loadInitialData([user]);
- const group = TestStubs.Group({
- owners: [
- {
- date_added: new Date(),
- owner: buildUserId(user.id),
- type: 'suspectCommit',
- },
- ],
- });
- render(
- <OwnedBy
- group={group}
- organization={TestStubs.Organization()}
- project={TestStubs.Project()}
- />
- );
- expect(screen.getByText('No-one')).toBeInTheDocument();
- });
- it('allows project:write to edit owners', () => {
- render(
- <OwnedBy
- group={TestStubs.Group()}
- organization={TestStubs.Organization()}
- project={TestStubs.Project()}
- />
- );
- userEvent.click(screen.getByLabelText('Create Ownership Rule'));
- expect(openCreateOwnershipRule).toHaveBeenCalledWith(
- expect.objectContaining({issueId: '1'})
- );
- });
- });
|