|
@@ -1,6 +1,6 @@
|
|
|
import {AutofixRootCauseData} from 'sentry-fixture/autofixRootCauseData';
|
|
|
|
|
|
-import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
|
|
|
+import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
|
|
|
|
|
|
import {AutofixRootCause} from 'sentry/components/events/autofix/autofixRootCause';
|
|
|
|
|
@@ -11,11 +11,13 @@ describe('AutofixRootCause', function () {
|
|
|
mockApi = MockApiClient.addMockResponse({
|
|
|
url: '/issues/1/autofix/update/',
|
|
|
method: 'POST',
|
|
|
+ body: {success: true},
|
|
|
});
|
|
|
});
|
|
|
|
|
|
afterEach(function () {
|
|
|
MockApiClient.clearMockResponses();
|
|
|
+ jest.clearAllTimers();
|
|
|
});
|
|
|
|
|
|
const defaultProps = {
|
|
@@ -29,20 +31,39 @@ describe('AutofixRootCause', function () {
|
|
|
it('can view a relevant code snippet', async function () {
|
|
|
render(<AutofixRootCause {...defaultProps} />);
|
|
|
|
|
|
- expect(screen.getByText('Root Cause')).toBeInTheDocument();
|
|
|
- expect(
|
|
|
- screen.getByText(defaultProps.causes[0]!.root_cause_reproduction![0]!.title)
|
|
|
- ).toBeInTheDocument();
|
|
|
+ // Wait for initial render and animations
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(screen.getByText('Root Cause')).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
+
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(
|
|
|
+ screen.getByText(defaultProps.causes[0]!.root_cause_reproduction![0]!.title)
|
|
|
+ ).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
|
|
|
await userEvent.click(screen.getByTestId('autofix-root-cause-timeline-item-0'));
|
|
|
- expect(
|
|
|
- screen.getByText(
|
|
|
- defaultProps.causes[0]!.root_cause_reproduction![0]!.code_snippet_and_analysis
|
|
|
- )
|
|
|
- ).toBeInTheDocument();
|
|
|
+
|
|
|
+ // Wait for code snippet to appear with increased timeout for animation
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(
|
|
|
+ screen.getByText(
|
|
|
+ defaultProps.causes[0]!.root_cause_reproduction![0]!.code_snippet_and_analysis
|
|
|
+ )
|
|
|
+ ).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
- it('shows graceful error state when there are no causes', function () {
|
|
|
+ it('shows graceful error state when there are no causes', async function () {
|
|
|
render(
|
|
|
<AutofixRootCause
|
|
|
{...{
|
|
@@ -53,14 +74,30 @@ describe('AutofixRootCause', function () {
|
|
|
/>
|
|
|
);
|
|
|
|
|
|
- expect(
|
|
|
- screen.getByText('No root cause found. The error comes from outside the codebase.')
|
|
|
- ).toBeInTheDocument();
|
|
|
+ // Wait for error state to render
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(
|
|
|
+ screen.getByText(
|
|
|
+ 'No root cause found. The error comes from outside the codebase.'
|
|
|
+ )
|
|
|
+ ).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
it('can edit and submit custom root cause', async function () {
|
|
|
render(<AutofixRootCause {...defaultProps} />);
|
|
|
|
|
|
+ // Wait for initial render
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(screen.getByText('Root Cause')).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
+
|
|
|
// Click edit button
|
|
|
await userEvent.click(screen.getByTestId('autofix-root-cause-edit-button'));
|
|
|
|
|
@@ -74,23 +111,28 @@ describe('AutofixRootCause', function () {
|
|
|
// Click Save button
|
|
|
await userEvent.click(screen.getByTestId('autofix-root-cause-save-edit-button'));
|
|
|
|
|
|
- // Verify API was called with correct payload
|
|
|
- expect(mockApi).toHaveBeenCalledWith(
|
|
|
- '/issues/1/autofix/update/',
|
|
|
- expect.objectContaining({
|
|
|
- method: 'POST',
|
|
|
- data: {
|
|
|
- run_id: '101',
|
|
|
- payload: {
|
|
|
- type: 'select_root_cause',
|
|
|
- custom_root_cause: 'This is a custom root cause',
|
|
|
- },
|
|
|
- },
|
|
|
- })
|
|
|
+ // Wait for API call to complete
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(mockApi).toHaveBeenCalledWith(
|
|
|
+ '/issues/1/autofix/update/',
|
|
|
+ expect.objectContaining({
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ run_id: '101',
|
|
|
+ payload: {
|
|
|
+ type: 'select_root_cause',
|
|
|
+ custom_root_cause: 'This is a custom root cause',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ );
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
);
|
|
|
});
|
|
|
|
|
|
- it('shows selected root cause when rootCauseSelection is provided', function () {
|
|
|
+ it('shows selected root cause when rootCauseSelection is provided', async function () {
|
|
|
const selectedCause = AutofixRootCauseData();
|
|
|
render(
|
|
|
<AutofixRootCause
|
|
@@ -103,14 +145,25 @@ describe('AutofixRootCause', function () {
|
|
|
/>
|
|
|
);
|
|
|
|
|
|
- // Verify selected root cause is displayed
|
|
|
- expect(screen.getByText('Root Cause')).toBeInTheDocument();
|
|
|
- expect(
|
|
|
- screen.getByText(selectedCause.root_cause_reproduction![0]!.title)
|
|
|
- ).toBeInTheDocument();
|
|
|
+ // Wait for selected root cause to render
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(screen.getByText('Root Cause')).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
+
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(
|
|
|
+ screen.getByText(selectedCause.root_cause_reproduction![0]!.title)
|
|
|
+ ).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
- it('shows custom root cause when rootCauseSelection has custom_root_cause', function () {
|
|
|
+ it('shows custom root cause when rootCauseSelection has custom_root_cause', async function () {
|
|
|
render(
|
|
|
<AutofixRootCause
|
|
|
{...{
|
|
@@ -122,7 +175,19 @@ describe('AutofixRootCause', function () {
|
|
|
/>
|
|
|
);
|
|
|
|
|
|
- expect(screen.getByText('Custom Root Cause')).toBeInTheDocument();
|
|
|
- expect(screen.getByText('This is a custom root cause')).toBeInTheDocument();
|
|
|
+ // Wait for custom root cause to render
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(screen.getByText('Custom Root Cause')).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
+
|
|
|
+ await waitFor(
|
|
|
+ () => {
|
|
|
+ expect(screen.getByText('This is a custom root cause')).toBeInTheDocument();
|
|
|
+ },
|
|
|
+ {timeout: 2000}
|
|
|
+ );
|
|
|
});
|
|
|
});
|