Skip to content

Commit dde0282

Browse files
committed
Fix global tests for refactor
1 parent 830b072 commit dde0282

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed

frontend/packages/modelServing/src/components/global/GlobalDeploymentsView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import ApplicationsPage from '@odh-dashboard/internal/pages/ApplicationsPage';
33
import { ProjectObjectType } from '@odh-dashboard/internal/concepts/design/utils';
44
import TitleWithIcon from '@odh-dashboard/internal/concepts/design/TitleWithIcon';
55
import type { ProjectKind } from '@odh-dashboard/internal/k8sTypes';
6-
import ModelServingLoading from '@odh-dashboard/internal/pages/modelServing/screens/global/ModelServingLoading';
76
import { useNavigate, useParams } from 'react-router-dom';
87
import { byName, ProjectsContext } from '@odh-dashboard/internal/concepts/projects/ProjectsContext';
98
import { GlobalNoModelsView } from './GlobalNoModelsView';
109
import GlobalDeploymentsTable from './GlobalDeploymentsTable';
1110
import ModelServingProjectSelection from './ModelServingProjectSelection';
1211
import NoProjectsPage from './NoProjectsPage';
12+
import GlobalModelsLoading from './GlobalModelsLoading';
1313
import { ModelDeploymentsContext } from '../../concepts/ModelDeploymentsContext';
1414

1515
type GlobalDeploymentsViewProps = {
@@ -32,7 +32,7 @@ const GlobalDeploymentsView: React.FC<GlobalDeploymentsViewProps> = ({ projects
3232
<ApplicationsPage
3333
loaded={!isLoading}
3434
loadingContent={
35-
<ModelServingLoading
35+
<GlobalModelsLoading
3636
title="Loading"
3737
description="Retrieving model data from all projects in the cluster. This can take a few minutes."
3838
onCancel={() => {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
Button,
3+
EmptyState,
4+
EmptyStateActions,
5+
EmptyStateBody,
6+
EmptyStateFooter,
7+
EmptyStateVariant,
8+
PageSection,
9+
Spinner,
10+
} from '@patternfly/react-core';
11+
import React from 'react';
12+
13+
type ModelServingLoadingProps = {
14+
title: string;
15+
description: string;
16+
onCancel: () => void;
17+
};
18+
19+
const ModelServingLoading: React.FC<ModelServingLoadingProps> = ({
20+
title,
21+
description,
22+
onCancel,
23+
}) => (
24+
<PageSection hasBodyWrapper={false} isFilled>
25+
<EmptyState
26+
headingLevel="h1"
27+
titleText={title}
28+
variant={EmptyStateVariant.lg}
29+
data-testid="loading-empty-state"
30+
>
31+
<Spinner size="xl" />
32+
<EmptyStateBody>{description}</EmptyStateBody>
33+
<EmptyStateFooter>
34+
<EmptyStateActions>
35+
<Button data-testid="empty-state-cancel-button" variant="primary" onClick={onCancel}>
36+
Cancel
37+
</Button>
38+
</EmptyStateActions>
39+
</EmptyStateFooter>
40+
</EmptyState>
41+
</PageSection>
42+
);
43+
44+
export default ModelServingLoading;

frontend/packages/modelServing/src/components/global/GlobalModelsPage.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { isModelServingPlatformExtension } from '../../../extension-points';
1111
const GlobalModelsPage: React.FC = () => {
1212
const availablePlatforms = useExtensions(isModelServingPlatformExtension);
1313

14-
const { projects, loaded: projectsLoaded, preferredProject } = React.useContext(ProjectsContext);
14+
const { projects, preferredProject } = React.useContext(ProjectsContext);
1515

1616
const { namespace } = useParams();
1717
const navigate = useNavigate();
@@ -51,13 +51,6 @@ const GlobalModelsPage: React.FC = () => {
5151
);
5252
}
5353

54-
if (!projectsLoaded) {
55-
return (
56-
<Bullseye>
57-
<Spinner />
58-
</Bullseye>
59-
);
60-
}
6154
return (
6255
<ModelDeploymentsProvider modelServingPlatforms={availablePlatforms} projects={projectsToShow}>
6356
<GlobalDeploymentsView projects={projectsToShow} />

frontend/src/__tests__/cypress/cypress/pages/modelServing.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ class ModelServingGlobal {
5656
return cy.findByTestId('deploy-button');
5757
}
5858

59+
clickDeployModelButtonWithRetry() {
60+
this.findDeployModelButton().click();
61+
// If modal doesn't appear, retry once
62+
cy.get('body').then(($body) => {
63+
if ($body.find('[role="dialog"]:visible').length === 0) {
64+
this.findDeployModelButton().click();
65+
}
66+
});
67+
return this;
68+
}
69+
5970
findNoProjectSelectedTooltip() {
6071
return cy.findByTestId('deploy-model-tooltip');
6172
}

frontend/src/__tests__/cypress/cypress/tests/mocked/modelServing/modelServingGlobal.cy.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ const initIntercepts = ({
162162
body: mockK8sResourceList(servingRuntimes),
163163
},
164164
).as('getServingRuntimes');
165+
cy.interceptK8sList(
166+
{ model: ServingRuntimeModel, ns: 'test-project' },
167+
{
168+
delay: delayServingRuntimes ? 500 : 0, //TODO: Remove the delay when we add support for loading states
169+
body: mockK8sResourceList(servingRuntimes),
170+
},
171+
);
165172
cy.interceptK8sList(
166173
{ model: InferenceServiceModel, ns: 'test-project' },
167174
mockK8sResourceList(inferenceServices),
@@ -301,19 +308,14 @@ describe('Model Serving Global', () => {
301308

302309
// Visit the all-projects view (no project name passed here)
303310
modelServingGlobal.visit();
304-
cy.findByRole('button', { name: 'Models' }).should('exist').click();
305311

312+
// Wait for the loading state to be visible and hit the cancel button -> this redirects to the preferred project page
306313
modelServingGlobal.shouldWaitAndCancel();
307314

315+
// Verify the empty state is visible
308316
modelServingGlobal.shouldBeEmpty();
309317

310-
cy.wait('@getServingRuntimes').then((response) => {
311-
expect(response.error?.message).to.eq('Socket closed before finished writing response');
312-
});
313-
314-
cy.wait('@getInferenceServices').then((response) => {
315-
expect(response.error?.message).to.eq('Socket closed before finished writing response');
316-
});
318+
cy.url().should('include', '/modelServing/test-project');
317319
});
318320

319321
it('All projects with every type of serving listed', () => {
@@ -667,7 +669,7 @@ describe('Model Serving Global', () => {
667669
});
668670
modelServingGlobal.visit('test-project');
669671

670-
modelServingGlobal.findDeployModelButton().click();
672+
modelServingGlobal.clickDeployModelButtonWithRetry();
671673

672674
kserveModal.shouldBeOpen();
673675
kserveModal.findServingRuntimeTemplateHelptext().should('not.exist');
@@ -684,7 +686,9 @@ describe('Model Serving Global', () => {
684686
});
685687
modelServingGlobal.visit('test-project');
686688

687-
modelServingGlobal.findDeployModelButton().click();
689+
modelServingGlobal.clickDeployModelButtonWithRetry();
690+
691+
kserveModal.shouldBeOpen();
688692

689693
kserveModal.findModelNameInput().should('exist');
690694

@@ -752,7 +756,9 @@ describe('Model Serving Global', () => {
752756
disableHardwareProfiles: false,
753757
});
754758
modelServingGlobal.visit('test-project');
755-
modelServingGlobal.findDeployModelButton().click();
759+
modelServingGlobal.findDeployModelButton().should('be.enabled');
760+
modelServingGlobal.clickDeployModelButtonWithRetry();
761+
kserveModal.shouldBeOpen();
756762
kserveModal.findModelNameInput().should('exist');
757763

758764
// Verify hardware profile section exists
@@ -826,7 +832,7 @@ describe('Model Serving Global', () => {
826832
disableProjectScoped: false,
827833
});
828834
modelServingGlobal.visit('test-project');
829-
modelServingGlobal.findDeployModelButton().click();
835+
modelServingGlobal.clickDeployModelButtonWithRetry();
830836
kserveModal.findModelNameInput().should('exist');
831837

832838
// Verify accelerator profile section exists
@@ -926,9 +932,10 @@ describe('Model Serving Global', () => {
926932
});
927933
modelServingGlobal.visit('test-project');
928934

929-
modelServingGlobal.findDeployModelButton().click();
935+
modelServingGlobal.clickDeployModelButtonWithRetry();
930936

931937
kserveModal.shouldBeOpen();
938+
kserveModal.findPredefinedArgsButton().scrollIntoView();
932939
kserveModal.findPredefinedArgsButton().click();
933940
kserveModal.findPredefinedArgsList().should('not.exist');
934941
kserveModal.findPredefinedArgsTooltip().should('exist');
@@ -947,7 +954,7 @@ describe('Model Serving Global', () => {
947954
});
948955
modelServingGlobal.visit('test-project');
949956

950-
modelServingGlobal.findDeployModelButton().click();
957+
modelServingGlobal.clickDeployModelButtonWithRetry();
951958

952959
kserveModal.shouldBeOpen();
953960
kserveModal.findPredefinedVarsButton().click();

0 commit comments

Comments
 (0)