Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Sep 10, 2024
1 parent 48c42fc commit 7df6453
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ jest.mock('../hooks', () => ({
}));

jest.mock('./query_assist_input', () => ({
QueryAssistInput: ({ inputRef }: ComponentProps<typeof QueryAssistInput>) => (
<input ref={inputRef} />
QueryAssistInput: ({ inputRef, error }: ComponentProps<typeof QueryAssistInput>) => (
<>
<input ref={inputRef} />
<div>{JSON.stringify(error)}</div>
</>
),
}));

Expand Down Expand Up @@ -128,7 +131,7 @@ describe('QueryAssistBar', () => {
});
});

it('displays badge for agent errors', async () => {
it('passes agent errors to input', async () => {
const generateQueryMock = jest.fn().mockResolvedValue({
error: new AgentError({
error: { type: 'mock-type', reason: 'mock-reason', details: 'mock-details' },
Expand All @@ -146,7 +149,7 @@ describe('QueryAssistBar', () => {
fireEvent.click(screen.getByRole('button'));

await waitFor(() => {
expect(screen.getByTestId('queryAssistErrorBadge')).toBeInTheDocument();
expect(screen.getByText(/mock-reason/)).toBeInTheDocument();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

import { I18nProvider } from '@osd/i18n/react';
import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import React, { ComponentProps } from 'react';
import { SuggestionsComponentProps } from '../../../../data/public/ui/typeahead/suggestions_component';
import { AgentError } from '../utils';
import { QueryAssistInput } from './query_assist_input';

jest.mock('../../services', () => ({
Expand Down Expand Up @@ -73,4 +74,14 @@ describe('<QueryAssistInput /> spec', () => {
fireEvent.click(suggestionButton);
expect(inputElement.value).toBe('mock suggestion 1');
});

it('should show error badge if there is an error', async () => {
renderQueryAssistInput({
error: new AgentError({
error: { type: 'mock-type', reason: 'mock-reason', details: 'mock-details' },
status: 303,
}),
});
expect(screen.getByTestId('queryAssistErrorBadge')).toBeInTheDocument();
});
});

0 comments on commit 7df6453

Please sign in to comment.