Skip to content

Commit

Permalink
Model registry deploy modal has faulty submit button disable detection (
Browse files Browse the repository at this point in the history
#3209)

* working version

* addressed comments
  • Loading branch information
YuliaKrimerman authored Sep 17, 2024
1 parent 5613032 commit e9c8a33
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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

0 comments on commit e9c8a33

Please sign in to comment.