Skip to content

Commit

Permalink
Fix tests for tabular page and use table data hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Samiul-TheSoccerFan committed Sep 19, 2024
1 parent 8be0bd3 commit 6fd3859
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DeleteAction: React.FC<DeleteActionProps> = ({ selectedEndpoint })

deleteEndpoint({
type: selectedEndpoint.type,
id: selectedEndpoint.endpoint.inference_id,
id: selectedEndpoint.endpoint,
});
};

Expand All @@ -37,7 +37,7 @@ export const DeleteAction: React.FC<DeleteActionProps> = ({ selectedEndpoint })
<EuiButtonIcon
aria-label={i18n.translate('xpack.searchInferenceEndpoints.actions.deleteEndpoint', {
defaultMessage: 'Delete inference endpoint {selectedEndpointName}',
values: { selectedEndpointName: selectedEndpoint?.endpoint.inference_id },
values: { selectedEndpointName: selectedEndpoint?.endpoint },
})}
key="delete"
iconType="trash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { screen } from '@testing-library/react';
import { render } from '@testing-library/react';
import { TabularPage } from './tabular_page';
import { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
import { TRAINED_MODEL_STATS_QUERY_KEY } from '../../../common/constants';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const inferenceEndpoints = [
{
Expand Down Expand Up @@ -56,39 +54,26 @@ jest.mock('../../hooks/use_delete_endpoint', () => ({
}));

describe('When the tabular page is loaded', () => {
beforeEach(() => {
const queryClient = new QueryClient();
queryClient.setQueryData([TRAINED_MODEL_STATS_QUERY_KEY], {
trained_model_stats: [
{
model_id: '.elser_model_2',
deployment_stats: { deployment_id: 'my-elser-model-05', state: 'started' },
},
{
model_id: '.own_model',
deployment_stats: { deployment_id: 'local-model', state: 'started' },
},
],
});
const wrapper = ({ children }: { children: React.ReactNode }) => {
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
};
render(wrapper({ children: <TabularPage inferenceEndpoints={inferenceEndpoints} /> }));
});
it('should display all inference ids in the table', () => {
render(<TabularPage inferenceEndpoints={inferenceEndpoints} />);

it('should display all model_ids in the table', () => {
const rows = screen.getAllByRole('row');
expect(rows[1]).toHaveTextContent('local-model');
expect(rows[2]).toHaveTextContent('my-elser-model-05');
expect(rows[3]).toHaveTextContent('third-party-model');
});
it('should render deployment status for inference endpoints with local trained models', () => {
const deploymentStatusStarted = screen.getAllByTestId('table-column-deployment-started');
expect(deploymentStatusStarted).toHaveLength(2);
});
it('should not render deployment status for third-party endpoints', () => {
expect(screen.queryByTestId('table-column-deployment-undefined')).not.toBeInTheDocument();
expect(screen.queryByTestId('table-column-deployment-starting')).not.toBeInTheDocument();
expect(screen.queryByTestId('table-column-deployment-stopping')).not.toBeInTheDocument();

it('should display all service and model ids in the table', () => {
render(<TabularPage inferenceEndpoints={inferenceEndpoints} />);

const rows = screen.getAllByRole('row');
expect(rows[1]).toHaveTextContent('Elasticsearch');
expect(rows[1]).toHaveTextContent('.own_model');

expect(rows[2]).toHaveTextContent('Elasticsearch');
expect(rows[2]).toHaveTextContent('.elser_model_2');

expect(rows[3]).toHaveTextContent('OpenAI');
expect(rows[3]).toHaveTextContent('.own_model');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ describe('useTableData', () => {
b.inference_id.localeCompare(a.inference_id)
);

const sortedEndpoints = result.current.sortedTableData.map(
(item) => item.endpoint.inference_id
);
const sortedEndpoints = result.current.sortedTableData.map((item) => item.endpoint);
const expectedModelIds = expectedSortedData.map((item) => item.inference_id);

expect(sortedEndpoints).toEqual(expectedModelIds);
Expand Down Expand Up @@ -153,19 +151,6 @@ describe('useTableData', () => {
{ wrapper }
);
const filteredData = result.current.sortedTableData;
expect(
filteredData.every((item) => item.endpoint.inference_id.includes(searchKey))
).toBeTruthy();
});

it('should update deployment status based on deploymentStatus object', () => {
const { result } = renderHook(
() => useTableData(inferenceEndpoints, queryParams, filterOptions, searchKey),
{ wrapper }
);

const updatedData = result.current.sortedTableData;

expect(updatedData[2].deployment).toEqual('started');
expect(filteredData.every((item) => item.endpoint.includes(searchKey))).toBeTruthy();
});
});

0 comments on commit 6fd3859

Please sign in to comment.