Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
278 changes: 278 additions & 0 deletions static/app/components/group/groupSummaryWithAutofix.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
import {GroupFixture} from 'sentry-fixture/group';
import {OrganizationFixture} from 'sentry-fixture/organization';
import {ProjectFixture} from 'sentry-fixture/project';
import {UserFixture} from 'sentry-fixture/user';

import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';

import {useAutofixData} from 'sentry/components/events/autofix/useAutofix';
import {AutofixSummary} from 'sentry/components/group/groupSummaryWithAutofix';
import {trackAnalytics} from 'sentry/utils/analytics';

jest.mock('sentry/components/events/autofix/useAutofix');
jest.mock('sentry/utils/analytics');

describe('AutofixSummary', () => {
const organization = OrganizationFixture();
const project = ProjectFixture();

Check failure on line 17 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

'project' is declared but its value is never read.
const group = GroupFixture({id: '1', shortId: 'TEST-1'});
const user = UserFixture();

beforeEach(() => {
jest.clearAllMocks();
MockApiClient.clearMockResponses();

jest.mocked(useAutofixData).mockReturnValue({
data: {
run_id: 'test-run-id',
status: 'COMPLETED',
steps: [],
},
isPending: false,
isError: false,
error: null,
} as any);
});

it('renders feedback buttons for root cause card', async () => {

Check failure on line 37 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / pre-commit lint

Async arrow function has no 'await' expression

Check failure on line 37 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / eslint

Async arrow function has no 'await' expression
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription={null}
solutionCopyText={null}
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization}
);

expect(screen.getByRole('button', {name: 'This was helpful'})).toBeInTheDocument();
expect(
screen.getByRole('button', {name: 'This was not helpful'})
).toBeInTheDocument();
});

it('renders feedback buttons for solution card', async () => {

Check failure on line 58 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / pre-commit lint

Async arrow function has no 'await' expression

Check failure on line 58 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / eslint

Async arrow function has no 'await' expression
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription="This is the solution"
solutionCopyText="Solution text"
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization}
);

const helpfulButtons = screen.getAllByRole('button', {name: 'This was helpful'});
expect(helpfulButtons).toHaveLength(2); // One for root cause, one for solution
});

it('tracks analytics event when thumbs up is clicked', async () => {
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription={null}
solutionCopyText={null}
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization, user}

Check failure on line 89 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

Object literal may only specify known properties, and 'user' does not exist in type 'BaseRenderOptions<false> & { initialRouterConfig?: RouterConfig | undefined; outletContext?: Record<string, unknown> | undefined; }'.
);

const thumbsUpButton = screen.getByRole('button', {name: 'This was helpful'});
await userEvent.click(thumbsUpButton);

await waitFor(() => {
expect(trackAnalytics).toHaveBeenCalledWith(
'seer.autofix.feedback_submitted',
expect.objectContaining({
step_type: 'root_cause',
positive: true,
group_id: '1',
autofix_run_id: 'test-run-id',
user_id: user.id,
organization,
})
);
});
});

it('tracks analytics event when thumbs down is clicked', async () => {
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription={null}
solutionCopyText={null}
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization, user}

Check failure on line 122 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

Object literal may only specify known properties, and 'user' does not exist in type 'BaseRenderOptions<false> & { initialRouterConfig?: RouterConfig | undefined; outletContext?: Record<string, unknown> | undefined; }'.
);

const thumbsDownButton = screen.getByRole('button', {
name: 'This was not helpful',
});
await userEvent.click(thumbsDownButton);

await waitFor(() => {
expect(trackAnalytics).toHaveBeenCalledWith(
'seer.autofix.feedback_submitted',
expect.objectContaining({
step_type: 'root_cause',
positive: false,
group_id: '1',
autofix_run_id: 'test-run-id',
user_id: user.id,
organization,
})
);
});
});

it('shows "Thanks!" message after feedback is submitted', async () => {
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription={null}
solutionCopyText={null}
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization}
);

const thumbsUpButton = screen.getByRole('button', {name: 'This was helpful'});
await userEvent.click(thumbsUpButton);

expect(await screen.findByText('Thanks!')).toBeInTheDocument();
expect(
screen.queryByRole('button', {name: 'This was helpful'})
).not.toBeInTheDocument();
});

it('does not render feedback buttons when loading', async () => {

Check failure on line 169 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / pre-commit lint

Async arrow function has no 'await' expression

Check failure on line 169 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / eslint

Async arrow function has no 'await' expression
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription={null}
solutionCopyText={null}
solutionIsLoading
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization}
);

// Root cause should have feedback buttons
expect(screen.getByRole('button', {name: 'This was helpful'})).toBeInTheDocument();

// Solution should not have feedback buttons because it's loading
const helpfulButtons = screen.getAllByRole('button', {name: 'This was helpful'});
expect(helpfulButtons).toHaveLength(1);
});

it('tracks different step_type for solution feedback', async () => {
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription="This is the solution"
solutionCopyText="Solution text"
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization, user}

Check failure on line 204 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

Object literal may only specify known properties, and 'user' does not exist in type 'BaseRenderOptions<false> & { initialRouterConfig?: RouterConfig | undefined; outletContext?: Record<string, unknown> | undefined; }'.
);

const thumbsUpButtons = screen.getAllByRole('button', {name: 'This was helpful'});
// Click the second thumbs up (solution)
await userEvent.click(thumbsUpButtons[1]);

Check failure on line 209 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

Argument of type 'HTMLElement | undefined' is not assignable to parameter of type 'Element'.

await waitFor(() => {
expect(trackAnalytics).toHaveBeenCalledWith(
'seer.autofix.feedback_submitted',
expect.objectContaining({
step_type: 'solution',
positive: true,
})
);
});
});

it('tracks changes step_type for code changes feedback', async () => {
render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription="This is the solution"
solutionCopyText="Solution text"
solutionIsLoading={false}
codeChangesDescription="These are the code changes"
codeChangesIsLoading={false}
/>,
{organization, user}

Check failure on line 234 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

Object literal may only specify known properties, and 'user' does not exist in type 'BaseRenderOptions<false> & { initialRouterConfig?: RouterConfig | undefined; outletContext?: Record<string, unknown> | undefined; }'.
);

const thumbsUpButtons = screen.getAllByRole('button', {name: 'This was helpful'});
// Click the third thumbs up (code changes)
await userEvent.click(thumbsUpButtons[2]);

Check failure on line 239 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / typescript

Argument of type 'HTMLElement | undefined' is not assignable to parameter of type 'Element'.

await waitFor(() => {
expect(trackAnalytics).toHaveBeenCalledWith(
'seer.autofix.feedback_submitted',
expect.objectContaining({
step_type: 'changes',
positive: true,
})
);
});
});

it('does not render feedback buttons when run_id is missing', async () => {

Check failure on line 252 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / pre-commit lint

Async arrow function has no 'await' expression

Check failure on line 252 in static/app/components/group/groupSummaryWithAutofix.spec.tsx

View workflow job for this annotation

GitHub Actions / eslint

Async arrow function has no 'await' expression
jest.mocked(useAutofixData).mockReturnValue({
data: null,
isPending: false,
isError: false,
error: null,
} as any);

render(
<AutofixSummary
group={group}
rootCauseDescription="This is the root cause"
rootCauseCopyText="Root cause text"
solutionDescription={null}
solutionCopyText={null}
solutionIsLoading={false}
codeChangesDescription={null}
codeChangesIsLoading={false}
/>,
{organization}
);

expect(
screen.queryByRole('button', {name: 'This was helpful'})
).not.toBeInTheDocument();
});
});
Loading
Loading