Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicates from inference_endpoint combo #181935

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { registerTestBed } from '@kbn/test-jest-helpers';
import { act } from 'react-dom/test-utils';
import { SelectInferenceId } from './select_inference_id';

const onChangeMock = jest.fn();
const setValueMock = jest.fn();

jest.mock('../../../../../app_context', () => ({
useAppContext: jest.fn().mockReturnValue({
core: { application: {} },
docLinks: {},
plugins: {
ml: {
mlApi: {
trainedModels: {
getTrainedModels: jest.fn().mockResolvedValue([]),
},
},
},
},
}),
}));

describe('SelectInferenceId', () => {
let exists: any;
let find: any;

beforeAll(async () => {
const setup = registerTestBed(SelectInferenceId, {
defaultProps: {
onChange: onChangeMock,
'data-test-subj': 'data-inference-endpoint-list',
setValue: setValueMock,
},
memoryRouter: { wrapComponent: false },
});

await act(async () => {
const testBed = setup();
exists = testBed.exists;
find = testBed.find;
});
});

it('should display the select inference endpoint combo', () => {
expect(exists('selectInferenceId')).toBe(true);
});

it('should contain the buttons for InferenceEndpoint management', () => {
find('inferenceIdButton').simulate('click');
expect(exists('addInferenceEndpointButton')).toBe(true);
expect(exists('manageInferenceEndpointButton')).toBe(true);
});

it('should display the inference endpoints in the combo', () => {
find('inferenceIdButton').simulate('click');
expect(find('data-inference-endpoint-list').contains('e5')).toBe(true);
expect(find('data-inference-endpoint-list').contains('elser_model_2')).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ export const SelectInferenceId = ({
}, [models]);

useEffect(() => {
setOptions([...defaultInferenceIds, ...inferenceIdOptionsFromModels]);
const mergedOptions = {
saikatsarkar056 marked this conversation as resolved.
Show resolved Hide resolved
...inferenceIdOptionsFromModels.reduce(
(acc, option) => ({ ...acc, [option.label]: option }),
{}
),
...defaultInferenceIds.reduce((acc, option) => ({ ...acc, [option.label]: option }), {}),
};
setOptions(Object.values(mergedOptions));
}, [inferenceIdOptionsFromModels, defaultInferenceIds]);
const [isCreateInferenceApiLoading, setIsCreateInferenceApiLoading] = useState(false);

Expand Down Expand Up @@ -184,6 +191,7 @@ export const SelectInferenceId = ({
iconType="arrowDown"
iconSide="right"
color="text"
data-test-subj="inferenceIdButton"
onClick={() => {
setIsInferencePopoverVisible(!isInferencePopoverVisible);
}}
Expand Down Expand Up @@ -298,7 +306,7 @@ export const SelectInferenceId = ({
};
return (
<Form form={form}>
<EuiFlexGroup>
<EuiFlexGroup data-test-subj="selectInferenceId">
<EuiFlexItem grow={false}>
{inferencePopover()}
{isInferenceFlyoutVisible && (
Expand Down