1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import {AutofixCodebaseChangeData} from 'sentry-fixture/autofixCodebaseChangeData';
- import {AutofixStepFixture} from 'sentry-fixture/autofixStep';
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- within,
- } from 'sentry-test/reactTestingLibrary';
- import {AutofixChanges} from 'sentry/components/events/autofix/autofixChanges';
- import {
- type AutofixChangesStep,
- AutofixStepType,
- } from 'sentry/components/events/autofix/types';
- describe('AutofixChanges', function () {
- const defaultProps = {
- groupId: '1',
- onRetry: jest.fn(),
- step: AutofixStepFixture({
- type: AutofixStepType.CHANGES,
- changes: [AutofixCodebaseChangeData()],
- }) as AutofixChangesStep,
- };
- it('displays link to PR when one exists', function () {
- MockApiClient.addMockResponse({
- url: '/issues/1/autofix/setup/',
- body: {
- genAIConsent: {ok: true},
- codebaseIndexing: {ok: true},
- integration: {ok: true},
- githubWriteIntegration: {
- repos: [{ok: true, owner: 'owner', name: 'hello-world', id: 100}],
- },
- },
- });
- render(<AutofixChanges {...defaultProps} />);
- expect(
- screen.queryByRole('button', {name: 'Create a Pull Request'})
- ).not.toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'View Pull Request'})).toHaveAttribute(
- 'href',
- 'https://github.com/owner/hello-world/pull/200'
- );
- });
- it('displays setup button when permissions do not exist for repo', async function () {
- MockApiClient.addMockResponse({
- url: '/issues/1/autofix/setup/',
- body: {
- genAIConsent: {ok: true},
- codebaseIndexing: {ok: true},
- integration: {ok: true},
- githubWriteIntegration: {
- repos: [
- {ok: false, provider: 'github', owner: 'owner', name: 'hello-world', id: 100},
- ],
- },
- },
- });
- render(
- <AutofixChanges
- {...defaultProps}
- step={
- AutofixStepFixture({
- type: AutofixStepType.CHANGES,
- changes: [
- AutofixCodebaseChangeData({
- pull_request: undefined,
- }),
- ],
- }) as AutofixChangesStep
- }
- />
- );
- renderGlobalModal();
- await userEvent.click(screen.getByRole('button', {name: 'Create a Pull Request'}));
- expect(await screen.findByRole('dialog')).toBeInTheDocument();
- expect(
- within(screen.getByRole('dialog')).getByText('Allow Autofix to Make Pull Requests')
- ).toBeInTheDocument();
- });
- });
|