Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Apr 9, 2024
1 parent 6bb567d commit b4d163c
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ import * as coreServices from '../../../../../../common/utils/core_services';
import { coreRefs } from '../../../../../framework/core_refs';
import { rootReducer } from '../../../../../framework/redux/reducers';
import { initialTabId } from '../../../../../framework/redux/store/shared_state';
import { PPLGeneratedCallOut, ProhibitedQueryCallOut } from '../callouts';
import { QueryAssistInput } from '../input';

const renderQueryAssistInput = (
overrideProps: Partial<ComponentProps<typeof QueryAssistInput>> = {}
) => {
const preloadedState = {};
const store = configureStore({ reducer: rootReducer, preloadedState });
const props: ComponentProps<typeof QueryAssistInput> = Object.assign(
const props: jest.Mocked<ComponentProps<typeof QueryAssistInput>> = Object.assign<
ComponentProps<typeof QueryAssistInput>,
Partial<ComponentProps<typeof QueryAssistInput>>
>(
{
handleQueryChange: jest.fn(),
handleTimeRangePickerRefresh: jest.fn(),
Expand All @@ -29,6 +33,8 @@ const renderQueryAssistInput = (
selectedIndex: [{ label: 'selected-test-index' }],
nlqInput: 'test-input',
setNlqInput: jest.fn(),
callOut: null,
setCallOut: jest.fn(),
handleTimePickerChange: jest.fn(),
},
overrideProps
Expand Down Expand Up @@ -68,12 +74,12 @@ describe('<QueryAssistInput /> spec', () => {
body: '{"question":"test-input","index":"selected-test-index"}',
});
expect(props.handleQueryChange).toBeCalledWith('source = index');
expect(component.getByTestId('query-assist-ppl-callout')).toBeInTheDocument();

await waitFor(() => {
fireEvent.click(component.getByTestId('closeCallOutButton'));
});
expect(component.queryByTestId('query-assist-ppl-callout')).toBeNull();
expect(props.setCallOut.mock.calls[0][0]).toBeNull();
expect(props.setCallOut.mock.calls[1][0]).toEqual(
expect.objectContaining({
type: PPLGeneratedCallOut,
})
);
});

it('should display toast for generate errors', async () => {
Expand Down Expand Up @@ -146,7 +152,7 @@ describe('<QueryAssistInput /> spec', () => {
body: { statusCode: 400, message: ERROR_DETAILS.GUARDRAILS_TRIGGERED },
});

const { component } = renderQueryAssistInput();
const { component, props } = renderQueryAssistInput();
await waitFor(() => {
// splitbutton data-test-subj doesn't work in Oui 1.5, this should be query-assist-generate-and-run-button
fireEvent.click(component.getByText('Generate and run'));
Expand All @@ -155,6 +161,11 @@ describe('<QueryAssistInput /> spec', () => {
expect(httpMock.post).toBeCalledWith(QUERY_ASSIST_API.GENERATE_PPL, {
body: '{"question":"test-input","index":"selected-test-index"}',
});
expect(component.getByTestId('query-assist-guard-callout')).toBeInTheDocument();
expect(props.setCallOut.mock.calls[0][0]).toBeNull();
expect(props.setCallOut.mock.calls[1][0]).toEqual(
expect.objectContaining({
type: ProhibitedQueryCallOut,
})
);
});
});

0 comments on commit b4d163c

Please sign in to comment.