From 6fd385986eb890f151b2b49d73d616dce46b9c81 Mon Sep 17 00:00:00 2001 From: Samiul Monir Date: Wed, 18 Sep 2024 23:54:03 -0400 Subject: [PATCH] Fix tests for tabular page and use table data hook --- .../actions/delete/delete_action.tsx | 4 +- .../tabular_page.test.tsx | 45 +++++++------------ .../public/hooks/use_table_data.test.tsx | 19 +------- 3 files changed, 19 insertions(+), 49 deletions(-) diff --git a/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_actions/actions/delete/delete_action.tsx b/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_actions/actions/delete/delete_action.tsx index 7bc428f49affa..caedf4e913387 100644 --- a/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_actions/actions/delete/delete_action.tsx +++ b/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_actions/actions/delete/delete_action.tsx @@ -28,7 +28,7 @@ export const DeleteAction: React.FC = ({ selectedEndpoint }) deleteEndpoint({ type: selectedEndpoint.type, - id: selectedEndpoint.endpoint.inference_id, + id: selectedEndpoint.endpoint, }); }; @@ -37,7 +37,7 @@ export const DeleteAction: React.FC = ({ selectedEndpoint }) ({ })); 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 {children}; - }; - render(wrapper({ children: })); - }); + it('should display all inference ids in the table', () => { + render(); - 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(); + + 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'); }); }); diff --git a/x-pack/plugins/search_inference_endpoints/public/hooks/use_table_data.test.tsx b/x-pack/plugins/search_inference_endpoints/public/hooks/use_table_data.test.tsx index b3b23b4e88f58..b16fb5f7675cb 100644 --- a/x-pack/plugins/search_inference_endpoints/public/hooks/use_table_data.test.tsx +++ b/x-pack/plugins/search_inference_endpoints/public/hooks/use_table_data.test.tsx @@ -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); @@ -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(); }); });