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

Model registry deploy modal has faulty submit button disable detection #3209

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { renderHook } from '@testing-library/react';
import usePrefillDeployModalFromModelRegistry from '~/pages/modelRegistry/screens/RegisteredModels/usePrefillDeployModalFromModelRegistry';
import { ProjectKind } from '~/k8sTypes';
import { RegisteredModelDeployInfo } from '~/pages/modelRegistry/screens/RegisteredModels/useRegisteredModelDeployInfo';
import { mockInferenceServiceModalData } from '~/__mocks__/mockInferenceServiceModalData';
import { DataConnection } from '~/pages/projects/types';

describe('usePrefillDeployModalFromModelRegistry', () => {
const mockProjectContext = {
currentProject: {
apiVersion: 'v1',
kind: 'Project',
metadata: {
name: 'test-project',
namespace: 'test-namespace',
},
} as ProjectKind,
dataConnections: [] as DataConnection[],
};

const data = mockInferenceServiceModalData({});

const mockSetCreateData = jest.fn();

const mockRegisteredModelDeployInfo: RegisteredModelDeployInfo = {
modelName: 'test-model',
modelArtifactUri: 's3://bucket/path',
modelArtifactStorageKey: 'test-key',
};

it('should ensure awsData array never has more than one element per key', () => {
renderHook(() =>
usePrefillDeployModalFromModelRegistry(
mockProjectContext,
data,
mockSetCreateData,
mockRegisteredModelDeployInfo,
),
);

const { awsData } = mockSetCreateData.mock.calls.find(([key]) => key === 'storage')[1];

const keys = awsData.map((item: { key: string }) => item.key);
const uniqueKeys = new Set(keys);

expect(keys.length).toBe(uniqueKeys.size);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ const usePrefillDeployModalFromModelRegistry = (
type: InferenceServiceStorageType.EXISTING_STORAGE,
});
} else {
const prefilledKeys: (typeof EMPTY_AWS_SECRET_DATA)[number]['key'][] = [
AwsKeys.NAME,
AwsKeys.AWS_S3_BUCKET,
AwsKeys.S3_ENDPOINT,
AwsKeys.DEFAULT_REGION,
];
const prefilledAWSData = [
{ key: AwsKeys.NAME, value: registeredModelDeployInfo.modelArtifactStorageKey || '' },
{ key: AwsKeys.AWS_S3_BUCKET, value: storageFields.bucket },
{ key: AwsKeys.S3_ENDPOINT, value: storageFields.endpoint },
{ key: AwsKeys.DEFAULT_REGION, value: storageFields.region || '' },
...EMPTY_AWS_SECRET_DATA,
...EMPTY_AWS_SECRET_DATA.filter((item) => !prefilledKeys.includes(item.key)),
];
if (recommendedDataConnections.length === 0) {
setCreateData('storage', {
Expand Down
Loading