autofixChanges.spec.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {AutofixCodebaseChangeData} from 'sentry-fixture/autofixCodebaseChangeData';
  2. import {AutofixStepFixture} from 'sentry-fixture/autofixStep';
  3. import {
  4. render,
  5. renderGlobalModal,
  6. screen,
  7. userEvent,
  8. within,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import {AutofixChanges} from 'sentry/components/events/autofix/autofixChanges';
  11. import {
  12. type AutofixChangesStep,
  13. AutofixStepType,
  14. } from 'sentry/components/events/autofix/types';
  15. describe('AutofixChanges', function () {
  16. const defaultProps = {
  17. groupId: '1',
  18. onRetry: jest.fn(),
  19. step: AutofixStepFixture({
  20. type: AutofixStepType.CHANGES,
  21. changes: [AutofixCodebaseChangeData()],
  22. }) as AutofixChangesStep,
  23. };
  24. it('displays link to PR when one exists', function () {
  25. MockApiClient.addMockResponse({
  26. url: '/issues/1/autofix/setup/',
  27. body: {
  28. genAIConsent: {ok: true},
  29. codebaseIndexing: {ok: true},
  30. integration: {ok: true},
  31. githubWriteIntegration: {
  32. repos: [{ok: true, owner: 'owner', name: 'hello-world', id: 100}],
  33. },
  34. },
  35. });
  36. render(<AutofixChanges {...defaultProps} />);
  37. expect(
  38. screen.queryByRole('button', {name: 'Create a Pull Request'})
  39. ).not.toBeInTheDocument();
  40. expect(screen.getByRole('button', {name: 'View Pull Request'})).toHaveAttribute(
  41. 'href',
  42. 'https://github.com/owner/hello-world/pull/200'
  43. );
  44. });
  45. it('displays setup button when permissions do not exist for repo', async function () {
  46. MockApiClient.addMockResponse({
  47. url: '/issues/1/autofix/setup/',
  48. body: {
  49. genAIConsent: {ok: true},
  50. codebaseIndexing: {ok: true},
  51. integration: {ok: true},
  52. githubWriteIntegration: {
  53. repos: [
  54. {ok: false, provider: 'github', owner: 'owner', name: 'hello-world', id: 100},
  55. ],
  56. },
  57. },
  58. });
  59. render(
  60. <AutofixChanges
  61. {...defaultProps}
  62. step={
  63. AutofixStepFixture({
  64. type: AutofixStepType.CHANGES,
  65. changes: [
  66. AutofixCodebaseChangeData({
  67. pull_request: undefined,
  68. }),
  69. ],
  70. }) as AutofixChangesStep
  71. }
  72. />
  73. );
  74. renderGlobalModal();
  75. await userEvent.click(screen.getByRole('button', {name: 'Create a Pull Request'}));
  76. expect(await screen.findByRole('dialog')).toBeInTheDocument();
  77. expect(
  78. within(screen.getByRole('dialog')).getByText('Allow Autofix to Make Pull Requests')
  79. ).toBeInTheDocument();
  80. });
  81. });