Skip to content

Commit

Permalink
Cypress fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-o0o committed Jan 28, 2025
1 parent 8c97f73 commit b8747a1
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 64 deletions.
28 changes: 24 additions & 4 deletions frontend/src/__tests__/cypress/cypress/pages/modelServing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ class InferenceServiceModal extends Modal {
return this.find().findByTestId('alt-form-checkbox-auth');
}

findExistingDataConnectionOption() {
return this.find().findByTestId('existing-data-connection-radio');
findNewConnectionOption() {
return this.find().findByTestId('new-connection-radio');
}

findExistingConnectionOption() {
return this.find().findByTestId('existing-connection-radio');
}

findExternalRouteError() {
Expand All @@ -166,9 +170,25 @@ class InferenceServiceModal extends Modal {
}

findExistingConnectionSelect() {
return this.find().findByTestId('typeahead-menu-toggle')
}

findExistingConnectionSelectValueField() {
return this.findExistingConnectionSelect().findByRole('combobox', {
name: 'Type to filter'
});
}

selectExistingConnectionSelectOptionByResourceName(name: string) {
return this.find()
.findByRole('group', { name: 'Source model location' })
.findByRole('button', { name: 'Options menu' });
}

findConnectionNameInput() {
return this.find().findByTestId('connection-name-desc-name');
}

findConnectionFieldInput() {
return this.find().findByTestId('field URI');
}

findLocationNameInput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('Deploy model version', () => {
// Validate name input field
kserveModal
.findModelNameInput()
.should('contain.value', `${registeredModelMocked.name} - ${modelVersionMocked.name} - `);
.should('exist')

// Validate model framework section
kserveModal.findModelFrameworkSelect().should('be.disabled');
Expand All @@ -260,5 +260,43 @@ describe('Deploy model version', () => {
modelArtifactMocked.modelFormatVersion ?? ''
}`,
).should('exist');

// Validate connection section
kserveModal.findExistingConnectionOption().should('be.checked');
kserveModal.findLocationPathInput().should('exist');
});

it('One match connection on KServe modal', () => {
initIntercepts({});
cy.interceptK8sList(
SecretModel,
mockK8sResourceList([
mockSecretK8sResource({
namespace: 'kserve-project',
s3Bucket: 'dGVzdC1idWNrZXQ=',
endPoint: 'dGVzdC1lbmRwb2ludA==',
region: 'dGVzdC1yZWdpb24=',
}),
mockSecretK8sResource({
name: 'test-secret-not-match',
displayName: 'Test Secret Not Match',
namespace: 'kserve-project',
s3Bucket: 'dGVzdC1idWNrZXQ=',
endPoint: 'dGVzdC1lbmRwb2ludC1ub3QtbWF0Y2g=', // endpoint not match
region: 'dGVzdC1yZWdpb24=',
}),
]),
);

cy.visit(`/modelRegistry/modelregistry-sample/registeredModels/1/versions`);
const modelVersionRow = modelRegistry.getModelVersionRow('test model version');
modelVersionRow.findKebabAction('Deploy').click();
modelVersionDeployModal.selectProjectByName('KServe project');

// Validate connection section
kserveModal.findExistingConnectionOption().should('be.checked');
kserveModal.findExistingConnectionSelectValueField().click();
kserveModal.selectExistingConnectionSelectOptionByResourceName('test-secret').click();
kserveModal.findLocationPathInput().should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ServingRuntimePlatform } from '~/types';
import { be } from '~/__tests__/cypress/cypress/utils/should';
import { asClusterAdminUser } from '~/__tests__/cypress/cypress/utils/mockUsers';
import { testPagination } from '~/__tests__/cypress/cypress/utils/pagination';
import { mockConnectionTypeConfigMap } from '~/__mocks__/mockConnectionType';

type HandlersProps = {
disableKServeConfig?: boolean;
Expand Down Expand Up @@ -140,6 +141,22 @@ const initIntercepts = ({
{ namespace: 'opendatahub' },
),
);
cy.interceptOdh('GET /api/connection-types', [
mockConnectionTypeConfigMap({
displayName: 'URI - v1',
name: 'uri-v1',
category: ['existing-category'],
fields: [
{
type: 'uri',
name: 'URI field test',
envVar: 'URI',
required: true,
properties: {},
},
],
}),
]);
};

describe('Model Serving Global', () => {
Expand Down Expand Up @@ -299,22 +316,15 @@ describe('Model Serving Global', () => {
inferenceServiceModalEdit.findLocationPathInput().type('test-model/');
inferenceServiceModalEdit.findSubmitButton().should('be.enabled');

// test that user cant upload on an empty new secret
inferenceServiceModalEdit.findLocationPathInput().clear();
inferenceServiceModalEdit.findSubmitButton().should('be.disabled');
inferenceServiceModalEdit.findLocationPathInput().type('/');
// test that user cant upload on an empty field
inferenceServiceModalEdit.findNewConnectionOption().click();
inferenceServiceModalEdit.findSubmitButton().should('be.disabled');

// test that adding required values validates submit
inferenceServiceModalEdit.findLocationNameInput().type('Test Name');
inferenceServiceModalEdit.findLocationAccessKeyInput().type('test-key');
inferenceServiceModalEdit.findLocationSecretKeyInput().type('test-secret-key');
inferenceServiceModalEdit.findLocationEndpointInput().type('test-endpoint');
inferenceServiceModalEdit.findLocationBucketInput().type('test-bucket');
inferenceServiceModalEdit.findLocationPathInput().clear();
inferenceServiceModalEdit.findLocationPathInput().type('test-model/');
inferenceServiceModalEdit.findConnectionNameInput().type('Test Name');
inferenceServiceModalEdit.findConnectionFieldInput().type('/');
inferenceServiceModalEdit.findSubmitButton().click().should('be.disabled');
inferenceServiceModalEdit.findConnectionFieldInput().clear().type('https://test');
inferenceServiceModalEdit.findSubmitButton().should('be.enabled');

inferenceServiceModalEdit.findExistingConnectionOption().click();
inferenceServiceModalEdit.findSubmitButton().click();

cy.wait('@editModel').then((interception) => {
Expand Down Expand Up @@ -364,8 +374,12 @@ describe('Model Serving Global', () => {
inferenceServiceModal.findServingRuntimeSelect().should('be.disabled');
inferenceServiceModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
inferenceServiceModal.findSubmitButton().should('be.disabled');
inferenceServiceModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
inferenceServiceModal.findExistingConnectionSelect().should('be.disabled');
inferenceServiceModal.findNewConnectionOption().click();
inferenceServiceModal.findConnectionNameInput().type('Test Name');
inferenceServiceModal.findConnectionFieldInput().type('https://test');
inferenceServiceModal.findSubmitButton().should('be.enabled');
inferenceServiceModal.findExistingConnectionOption().click();
inferenceServiceModal.findExistingConnectionSelect().should('have.attr', 'disabled');
inferenceServiceModal.findLocationPathInput().type('test-model/');
inferenceServiceModal.findSubmitButton().should('be.enabled');
inferenceServiceModal.findLocationPathInput().clear();
Expand All @@ -384,11 +398,6 @@ describe('Model Serving Global', () => {
.contains('Invalid path format');
inferenceServiceModal.findSubmitButton().should('be.disabled');
inferenceServiceModal.findLocationPathInput().clear();
inferenceServiceModal.findLocationNameInput().type('Test Name');
inferenceServiceModal.findLocationAccessKeyInput().type('test-key');
inferenceServiceModal.findLocationSecretKeyInput().type('test-secret-key');
inferenceServiceModal.findLocationEndpointInput().type('test-endpoint');
inferenceServiceModal.findLocationBucketInput().type('test-bucket');
inferenceServiceModal.findLocationPathInput().type('test-model/');
inferenceServiceModal.findSubmitButton().should('be.enabled');

Expand Down Expand Up @@ -451,8 +460,7 @@ describe('Model Serving Global', () => {
inferenceServiceModal.findServingRuntimeSelect().should('be.disabled');
inferenceServiceModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
inferenceServiceModal.findSubmitButton().should('be.disabled');
inferenceServiceModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
inferenceServiceModal.findExistingConnectionSelect().should('be.disabled');
inferenceServiceModal.findExistingConnectionSelect().should('have.attr', 'disabled');
inferenceServiceModal.findLocationPathInput().type('test-model/');
inferenceServiceModal.findSubmitButton().should('be.enabled');
inferenceServiceModal.findLocationPathInput().type('test-model/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
TemplateModel,
} from '~/__tests__/cypress/cypress/utils/models';
import { mockRoleK8sResource } from '~/__mocks__/mockRoleK8sResource';
import { mockConnectionTypeConfigMap } from '~/__mocks__/mockConnectionType';

type HandlersProps = {
disableKServeConfig?: boolean;
Expand All @@ -73,6 +74,7 @@ type HandlersProps = {
roleAlreadyExists?: boolean;
rejectInferenceService?: boolean;
rejectServingRuntime?: boolean;
rejectConnection?: boolean;
requiredCapabilities?: StackCapability[];
};

Expand Down Expand Up @@ -113,6 +115,7 @@ const initIntercepts = ({
roleAlreadyExists = false,
rejectInferenceService = false,
rejectServingRuntime = false,
rejectConnection = false,
requiredCapabilities = [],
}: HandlersProps) => {
cy.interceptOdh(
Expand Down Expand Up @@ -372,6 +375,28 @@ const initIntercepts = ({
{ namespace: 'opendatahub' },
),
);
cy.interceptOdh(
'GET /api/config',
mockDashboardConfig({
disableConnectionTypes: false,
}),
);
cy.interceptOdh('GET /api/connection-types', [
mockConnectionTypeConfigMap({
displayName: 'URI - v1',
name: 'uri-v1',
category: ['existing-category'],
fields: [
{
type: 'uri',
name: 'URI field test',
envVar: 'URI',
required: true,
properties: {},
},
],
}),
]);
};

describe('Serving Runtime List', () => {
Expand Down Expand Up @@ -424,17 +449,12 @@ describe('Serving Runtime List', () => {
inferenceServiceModal.findModelNameInput().type('Test Name');
inferenceServiceModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
inferenceServiceModal.findSubmitButton().should('be.disabled');
inferenceServiceModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
inferenceServiceModal.findExistingConnectionSelect().should('be.disabled');
inferenceServiceModal.findLocationPathInput().type('test-model/');
inferenceServiceModal.findNewConnectionOption().click();
inferenceServiceModal.findConnectionNameInput().type('Test Name');
inferenceServiceModal.findConnectionFieldInput().type('https://test');
inferenceServiceModal.findSubmitButton().should('be.enabled');
inferenceServiceModal.findLocationPathInput().clear();
inferenceServiceModal.findSubmitButton().should('be.disabled');
inferenceServiceModal.findLocationNameInput().type('Test Name');
inferenceServiceModal.findLocationAccessKeyInput().type('test-key');
inferenceServiceModal.findLocationSecretKeyInput().type('test-secret-key');
inferenceServiceModal.findLocationEndpointInput().type('test-endpoint');
inferenceServiceModal.findLocationBucketInput().type('test-bucket');
inferenceServiceModal.findExistingConnectionOption().click();
inferenceServiceModal.findExistingConnectionSelect().should('have.attr', 'disabled');
inferenceServiceModal.findLocationPathInput().type('test-model/');
inferenceServiceModal.findSubmitButton().should('be.enabled');

Expand Down Expand Up @@ -521,10 +541,7 @@ describe('Serving Runtime List', () => {
.findServingRuntimeSelect()
.should('have.text', 'OVMS Model Serving')
.should('be.enabled');
inferenceServiceModalEdit
.findExistingConnectionSelect()
.should('have.text', 'Test Secret')
.should('be.disabled');
inferenceServiceModalEdit.findExistingConnectionSelect().should('have.attr', 'disabled');
});

it('ModelMesh ServingRuntime list', () => {
Expand Down Expand Up @@ -740,18 +757,15 @@ describe('Serving Runtime List', () => {
kserveModal.findAuthenticationCheckbox().check();
kserveModal.findExternalRouteError().should('not.exist');
kserveModal.findServiceAccountNameInput().should('have.value', 'default-name');
kserveModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
kserveModal.findExistingConnectionSelect().should('be.disabled');
kserveModal.findLocationPathInput().type('test-model/');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findLocationPathInput().clear();
kserveModal.findSubmitButton().should('be.disabled');
kserveModal.findLocationNameInput().type('Test Name');
kserveModal.findLocationAccessKeyInput().type('test-key');
kserveModal.findLocationSecretKeyInput().type('test-secret-key');
kserveModal.findLocationEndpointInput().type('test-endpoint');
kserveModal.findLocationBucketInput().type('test-bucket');
kserveModal.findNewConnectionOption().click();
kserveModal.findConnectionNameInput().type('Test Name');
kserveModal.findConnectionFieldInput().type('https://test');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findExistingConnectionOption().click();
kserveModal.findExistingConnectionSelect().should('have.attr', 'disabled');
kserveModal.findLocationPathInput().type('test-model/');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findConfigurationParamsSection().should('exist');
kserveModal.findServingRuntimeArgumentsSectionInput().type('--arg=value');
kserveModal.findServingRuntimeEnvVarsSectionAddButton().click();
Expand Down Expand Up @@ -976,8 +990,8 @@ describe('Serving Runtime List', () => {
kserveModal.findModelNameInput().type('Test Name');
kserveModal.findServingRuntimeTemplateDropdown().findSelectOption('Caikit').click();
kserveModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
kserveModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
kserveModal.findExistingConnectionSelect().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('have.attr', 'disabled');
kserveModal.findNewConnectionOption().click();
kserveModal.findLocationNameInput().type('Test Name');
kserveModal.findLocationAccessKeyInput().type('test-key');
kserveModal.findLocationSecretKeyInput().type('test-secret-key');
Expand Down Expand Up @@ -1254,9 +1268,12 @@ describe('Serving Runtime List', () => {
kserveModal.findServingRuntimeTemplateDropdown().findSelectOption('Caikit').click();
kserveModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
kserveModal.findSubmitButton().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
kserveModal.findExistingConnectionSelect().should('be.disabled');

kserveModal.findNewConnectionOption().click();
kserveModal.findConnectionNameInput().type('Test Name');
kserveModal.findConnectionFieldInput().type('https://test');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findExistingConnectionOption().click();
kserveModal.findExistingConnectionSelect().should('have.attr', 'disabled');
kserveModal.findLocationPathInput().type('test-model/');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findLocationPathInput().clear();
Expand Down Expand Up @@ -1344,8 +1361,7 @@ describe('Serving Runtime List', () => {
kserveModal.findAuthenticationCheckbox().check();
kserveModal.findExternalRouteError().should('not.exist');
kserveModal.findServiceAccountNameInput().should('have.value', 'default-name');
kserveModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
kserveModal.findExistingConnectionSelect().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('have.attr', 'disabled');
kserveModal.findLocationPathInput().type('test-model/');
kserveModal.findSubmitButton().should('be.enabled');
// raw
Expand Down Expand Up @@ -2130,6 +2146,7 @@ describe('Serving Runtime List', () => {
disableKServeConfig: false,
servingRuntimes: [],
rejectInferenceService: true,
projectEnableModelMesh: false,
});

projectDetails.visitSection('test-project', 'model-server');
Expand All @@ -2141,8 +2158,7 @@ describe('Serving Runtime List', () => {
kserveModal.findServingRuntimeTemplateDropdown().findSelectOption('Caikit').click();
kserveModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
kserveModal.findSubmitButton().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
kserveModal.findExistingConnectionSelect().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('have.attr', 'disabled');
kserveModal.findLocationPathInput().type('test-model/');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findSubmitButton().click();
Expand Down Expand Up @@ -2175,8 +2191,7 @@ describe('Serving Runtime List', () => {
kserveModal.findServingRuntimeTemplateDropdown().findSelectOption('Caikit').click();
kserveModal.findModelFrameworkSelect().findSelectOption('onnx - 1').click();
kserveModal.findSubmitButton().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('contain.text', 'Test Secret');
kserveModal.findExistingConnectionSelect().should('be.disabled');
kserveModal.findExistingConnectionSelect().should('have.attr', 'disabled');
kserveModal.findLocationPathInput().type('test-model/');
kserveModal.findSubmitButton().should('be.enabled');
kserveModal.findSubmitButton().click();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TypeaheadSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ const TypeaheadSelect: React.FunctionComponent<TypeaheadSelectProps> = ({
ref={toggleRef}
variant="typeahead"
aria-label="Typeahead menu toggle"
data-testid={dataTestId}
data-testid="typeahead-menu-toggle"
onClick={onToggleClick}
isExpanded={isOpen}
isDisabled={isDisabled || (selectOptions.length <= 1 && notAllowEmpty)}
Expand Down

0 comments on commit b8747a1

Please sign in to comment.