mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import {MembersFixture} from 'sentry-fixture/members';
|
|
import {UserFixture} from 'sentry-fixture/user';
|
|
|
|
import {initializeOrg} from 'sentry-test/initializeOrg';
|
|
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
|
|
|
|
import MemberListStore from 'sentry/stores/memberListStore';
|
|
import OwnerInput from 'sentry/views/settings/project/projectOwnership/ownerInput';
|
|
|
|
describe('Project Ownership Input', function () {
|
|
const {organization, project} = initializeOrg();
|
|
let put: jest.Mock;
|
|
|
|
beforeEach(function () {
|
|
MockApiClient.addMockResponse({
|
|
url: `/organizations/${organization.slug}/members/`,
|
|
method: 'GET',
|
|
body: MembersFixture(),
|
|
});
|
|
put = MockApiClient.addMockResponse({
|
|
url: `/projects/${organization.slug}/${project.slug}/ownership/`,
|
|
method: 'PUT',
|
|
body: {raw: 'url:src @[email protected]'},
|
|
});
|
|
MemberListStore.init();
|
|
MemberListStore.loadInitialData([UserFixture({id: '1', email: '[email protected]'})]);
|
|
});
|
|
|
|
it('renders', async function () {
|
|
render(
|
|
<OwnerInput
|
|
page="issue_details"
|
|
onCancel={() => {}}
|
|
dateUpdated={null}
|
|
organization={organization}
|
|
initialText="url:src @[email protected]"
|
|
project={project}
|
|
/>
|
|
);
|
|
|
|
const submitButton = screen.getByRole('button', {name: 'Save'});
|
|
expect(put).not.toHaveBeenCalled();
|
|
|
|
// if text is unchanged, submit button is disabled
|
|
await userEvent.click(submitButton);
|
|
expect(put).not.toHaveBeenCalled();
|
|
|
|
const textarea = screen.getByRole('textbox', {name: 'Ownership Rules'});
|
|
|
|
await userEvent.clear(textarea);
|
|
await userEvent.type(textarea, 'new');
|
|
await userEvent.click(submitButton);
|
|
|
|
expect(put).toHaveBeenCalled();
|
|
});
|
|
|
|
it('updates on add preserving existing text', async function () {
|
|
render(
|
|
<OwnerInput
|
|
page="issue_details"
|
|
onCancel={() => {}}
|
|
dateUpdated={null}
|
|
organization={organization}
|
|
initialText="url:src @[email protected]"
|
|
project={project}
|
|
/>
|
|
);
|
|
|
|
await userEvent.type(
|
|
screen.getByRole('textbox', {name: 'Ownership Rules'}),
|
|
'\npath:file.js [email protected]'
|
|
);
|
|
|
|
await userEvent.click(screen.getByRole('button', {name: 'Save'}));
|
|
|
|
expect(put).toHaveBeenCalledWith(
|
|
`/projects/${organization.slug}/${project.slug}/ownership/`,
|
|
expect.objectContaining({
|
|
data: {
|
|
raw: 'url:src @[email protected]' + '\n' + 'path:file.js [email protected]',
|
|
},
|
|
})
|
|
);
|
|
});
|
|
});
|