123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- import {AutofixDataFixture} from 'sentry-fixture/autofixData';
- import {AutofixStepFixture} from 'sentry-fixture/autofixStep';
- import {EventFixture} from 'sentry-fixture/event';
- import {FrameFixture} from 'sentry-fixture/frame';
- import {GroupFixture} from 'sentry-fixture/group';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {
- render,
- screen,
- userEvent,
- waitFor,
- waitForElementToBeRemoved,
- } from 'sentry-test/reactTestingLibrary';
- import {t} from 'sentry/locale';
- import {EntryType} from 'sentry/types/event';
- import {SolutionsHubDrawer} from 'sentry/views/issueDetails/streamline/solutionsHubDrawer';
- describe('SolutionsHubDrawer', () => {
- const organization = OrganizationFixture({
- genAIConsent: true,
- hideAiFeatures: false,
- features: ['gen-ai-features'],
- });
- const mockEvent = EventFixture({
- entries: [
- {
- type: EntryType.EXCEPTION,
- data: {values: [{stacktrace: {frames: [FrameFixture()]}}]},
- },
- ],
- });
- const mockGroup = GroupFixture();
- const mockProject = ProjectFixture();
- const mockAutofixData = AutofixDataFixture({steps: [AutofixStepFixture()]});
- beforeEach(() => {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/setup/`,
- body: {
- genAIConsent: {ok: true},
- integration: {ok: true},
- githubWriteIntegration: {ok: true},
- },
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${mockProject.organization.slug}/issues/${mockGroup.id}/summarize/`,
- method: 'POST',
- body: {
- whatsWrong: 'Test whats wrong',
- trace: 'Test trace',
- possibleCause: 'Test possible cause',
- headline: 'Test headline',
- },
- });
- });
- it('renders consent state if not consented', async () => {
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/setup/`,
- body: {
- genAIConsent: {ok: false},
- integration: {ok: false},
- githubWriteIntegration: {ok: false},
- },
- });
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- body: {autofix: null},
- });
- render(
- <SolutionsHubDrawer event={mockEvent} group={mockGroup} project={mockProject} />,
- {organization}
- );
- expect(screen.getByTestId('ai-setup-loading-indicator')).toBeInTheDocument();
- await waitForElementToBeRemoved(() =>
- screen.queryByTestId('ai-setup-loading-indicator')
- );
- expect(screen.getByText(mockEvent.id)).toBeInTheDocument();
- expect(screen.getByRole('heading', {name: 'Solutions Hub'})).toBeInTheDocument();
- expect(screen.getByTestId('ai-setup-data-consent')).toBeInTheDocument();
- });
- it('renders initial state correctly', async () => {
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- body: {autofix: null},
- });
- render(
- <SolutionsHubDrawer event={mockEvent} group={mockGroup} project={mockProject} />,
- {organization}
- );
- expect(screen.getByTestId('ai-setup-loading-indicator')).toBeInTheDocument();
- await waitForElementToBeRemoved(() =>
- screen.queryByTestId('ai-setup-loading-indicator')
- );
- expect(screen.getByRole('heading', {name: 'Solutions Hub'})).toBeInTheDocument();
- const startButton = screen.getByRole('button', {name: 'Start Autofix'});
- expect(startButton).toBeInTheDocument();
- });
- it('triggers autofix on clicking the Start button', async () => {
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- method: 'POST',
- body: {autofix: null},
- });
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- method: 'GET',
- body: {autofix: null},
- });
- render(
- <SolutionsHubDrawer event={mockEvent} group={mockGroup} project={mockProject} />,
- {organization}
- );
- expect(screen.getByTestId('ai-setup-loading-indicator')).toBeInTheDocument();
- await waitForElementToBeRemoved(() =>
- screen.queryByTestId('ai-setup-loading-indicator')
- );
- const startButton = screen.getByRole('button', {name: 'Start Autofix'});
- await userEvent.click(startButton);
- expect(
- await screen.findByRole('button', {name: t('Start Over')})
- ).toBeInTheDocument();
- });
- it('displays autofix steps and Start Over button when autofixData is available', async () => {
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- body: {autofix: mockAutofixData},
- });
- render(
- <SolutionsHubDrawer event={mockEvent} group={mockGroup} project={mockProject} />,
- {organization}
- );
- expect(
- await screen.findByRole('button', {name: t('Start Over')})
- ).toBeInTheDocument();
- });
- it('resets autofix on clicking the start over button', async () => {
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- body: {autofix: mockAutofixData},
- });
- render(
- <SolutionsHubDrawer event={mockEvent} group={mockGroup} project={mockProject} />,
- {organization}
- );
- const startOverButton = await screen.findByRole('button', {name: t('Start Over')});
- expect(startOverButton).toBeInTheDocument();
- await userEvent.click(startOverButton);
- await waitFor(() => {
- expect(screen.getByRole('button', {name: 'Start Autofix'})).toBeInTheDocument();
- });
- });
- it('shows setup if not complete', async () => {
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/setup/`,
- body: {
- genAIConsent: {ok: true},
- integration: {ok: false},
- githubWriteIntegration: {ok: false, repos: []},
- },
- });
- MockApiClient.addMockResponse({
- url: `/issues/${mockGroup.id}/autofix/`,
- body: {autofix: null},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/integrations/?provider_key=github&includeConfig=0',
- body: [],
- });
- render(
- <SolutionsHubDrawer event={mockEvent} group={mockGroup} project={mockProject} />,
- {organization}
- );
- expect(screen.getByTestId('ai-setup-loading-indicator')).toBeInTheDocument();
- await waitForElementToBeRemoved(() =>
- screen.queryByTestId('ai-setup-loading-indicator')
- );
- expect(screen.getByRole('heading', {name: 'Solutions Hub'})).toBeInTheDocument();
- expect(screen.queryByRole('button', {name: 'Start Autofix'})).not.toBeInTheDocument();
- expect(await screen.findByText('Install the GitHub Integration')).toBeInTheDocument();
- });
- });
|