Skip to content

Commit

Permalink
Add duplicate connection type page
Browse files Browse the repository at this point in the history
  • Loading branch information
emilys314 committed Aug 7, 2024
1 parent 457d01d commit a842c0c
Show file tree
Hide file tree
Showing 34 changed files with 907 additions and 1,185 deletions.
67 changes: 67 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/connectionTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { TableRow } from './components/table';

class CreateConnectionTypeTableRow extends TableRow {
findSectionHeading() {
return this.find().findByTestId(['section-heading']);
}

findType() {
return this.find().findByTestId(['field-type']);
}

findDefault() {
return this.find().findByTestId(['field-default']);
}

findEnvVar() {
return this.find().findByTestId(['field-env']);
}

findRequired() {
return this.find().findByTestId(['field-required']);
}
}

class CreateConnectionTypePage {
visitCreatePage() {
cy.visitWithLogin('/connectionTypes/create');
cy.findAllByText('Create connection type').should('exist');
}

visitDuplicatePage(name = 'existing') {
cy.visitWithLogin(`/connectionTypes/duplicate/${name}`);
cy.findAllByText('Create connection type').should('exist');
}

connectionTypeName() {
return cy.findByTestId('connection-type-name');
}

connectionTypeDesc() {
return cy.findByTestId('connection-type-description');
}

connectionTypeEnable() {
return cy.findByTestId('connection-type-enable');
}

findFieldsTable() {
return cy.findByTestId('connection-type-fields-table');
}

getFieldsTableRow(name = '') {
return new CreateConnectionTypeTableRow(() =>
this.findFieldsTable().findByText(name).parents('tr'),
);
}

findAllFieldsTableRows() {
return this.findFieldsTable().findAllByTestId(['row']);
}

findSubmitButton() {
return cy.findByTestId('submit-button');
}
}

export const createConnectionTypePage = new CreateConnectionTypePage();
4 changes: 0 additions & 4 deletions frontend/src/__tests__/cypress/cypress/pages/modelRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ class ModelRegistry {
findModelVersionsTableFilter() {
return cy.findByTestId('model-versions-table-filter');
}

findRegisterModelButton() {
return cy.findByRole('button', { name: 'Register model' });
}
}

export const modelRegistry = new ModelRegistry();
Expand Down

This file was deleted.

35 changes: 19 additions & 16 deletions frontend/src/__tests__/cypress/cypress/support/commands/odh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { K8sResourceListResult } from '@openshift/dynamic-plugin-sdk-utils'
import type { GenericStaticResponse, RouteHandlerController } from 'cypress/types/net-stubbing';
import type { BaseMetricCreationResponse, BaseMetricListResponse } from '~/api';
import type {
ModelArtifact,
ModelArtifactList,
ModelVersion,
ModelVersionList,
Expand Down Expand Up @@ -50,6 +49,7 @@ import type {
} from '~/concepts/pipelines/kfTypes';
import type { GrpcResponse } from '~/__mocks__/mlmd/utils';
import type { BuildMockPipelinveVersionsType } from '~/__mocks__';
import type { ConnectionTypeConfigMap } from '~/concepts/connectionTypes/types';

type SuccessErrorResponse = {
success: boolean;
Expand Down Expand Up @@ -295,21 +295,11 @@ declare global {
options: { path: { serviceName: string; apiVersion: string } },
response: OdhResponse<RegisteredModelList>,
) => Cypress.Chainable<null>) &
((
type: 'POST /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models',
options: { path: { serviceName: string; apiVersion: string } },
response: OdhResponse<RegisteredModel>,
) => Cypress.Chainable<null>) &
((
type: 'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
options: { path: { serviceName: string; apiVersion: string; registeredModelId: number } },
response: OdhResponse<ModelVersionList>,
) => Cypress.Chainable<null>) &
((
type: 'POST /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId/versions',
options: { path: { serviceName: string; apiVersion: string; registeredModelId: number } },
response: OdhResponse<ModelVersion>,
) => Cypress.Chainable<null>) &
((
type: 'GET /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/registered_models/:registeredModelId',
options: { path: { serviceName: string; apiVersion: string; registeredModelId: number } },
Expand All @@ -332,11 +322,6 @@ declare global {
options: { path: { serviceName: string; apiVersion: string; modelVersionId: number } },
response: OdhResponse<ModelArtifactList>,
) => Cypress.Chainable<null>) &
((
type: 'POST /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/model_versions/:modelVersionId/artifacts',
options: { path: { serviceName: string; apiVersion: string; modelVersionId: number } },
response: OdhResponse<ModelArtifact>,
) => Cypress.Chainable<null>) &
((
type: 'PATCH /api/service/modelregistry/:serviceName/api/model_registry/:apiVersion/model_versions/:modelVersionId',
options: { path: { serviceName: string; apiVersion: string; modelVersionId: number } },
Expand Down Expand Up @@ -581,6 +566,24 @@ declare global {
path: { namespace: string };
},
response: OdhResponse<number>,
) => Cypress.Chainable<null>) &
((
type: 'GET /api/connection-types',
response: ConnectionTypeConfigMap[],
) => Cypress.Chainable<null>) &
((
type: 'PATCH /api/connection-types/:name',
options: {
path: { name: string };
},
response: { success: boolean; error: string },
) => Cypress.Chainable<null>) &
((
type: 'GET /api/connection-types/:name',
options: {
path: { name: string };
},
response: ConnectionTypeConfigMap,
) => Cypress.Chainable<null>);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
mockConnectionTypeConfigMap,
mockConnectionTypeConfigMapObj,
} from '~/__mocks__/mockConnectionType';
import { createConnectionTypePage } from '~/__tests__/cypress/cypress/pages/connectionTypes';
import { asClusterAdminUser } from '~/__tests__/cypress/cypress/utils/mockUsers';
import type { SectionField, ShortTextField } from '~/concepts/connectionTypes/types';

describe('create', () => {
it('Display base page', () => {
asClusterAdminUser();
createConnectionTypePage.visitCreatePage();

createConnectionTypePage.connectionTypeName().should('exist');
createConnectionTypePage.connectionTypeDesc().should('exist');
createConnectionTypePage.connectionTypeEnable().should('exist');
createConnectionTypePage.findFieldsTable().should('exist');
});

it('Allows create button with valid name', () => {
asClusterAdminUser();
createConnectionTypePage.visitCreatePage();

createConnectionTypePage.connectionTypeName().should('have.value', '');
createConnectionTypePage.findSubmitButton().should('be.disabled');

createConnectionTypePage.connectionTypeName().type('hello');
createConnectionTypePage.findSubmitButton().should('be.enabled');
});
});

describe('duplicate', () => {
const existing = mockConnectionTypeConfigMapObj({ name: 'existing' });

beforeEach(() => {
asClusterAdminUser();
cy.interceptOdh(
'GET /api/connection-types/:name',
{ path: { name: 'existing' } },
mockConnectionTypeConfigMap({ name: 'existing' }),
);
});

it('Prefill details from existing connection', () => {
createConnectionTypePage.visitDuplicatePage('existing');

createConnectionTypePage
.connectionTypeName()
.should(
'have.value',
`Duplicate of ${existing.metadata.annotations['openshift.io/display-name']}`,
);
createConnectionTypePage
.connectionTypeDesc()
.should('have.value', existing.metadata.annotations['openshift.io/description']);
createConnectionTypePage.connectionTypeEnable().should('be.checked');
});

it('Prefill fields table from existing connection', () => {
createConnectionTypePage.visitDuplicatePage('existing');

createConnectionTypePage
.findAllFieldsTableRows()
.should('have.length', existing.data?.fields?.length);

// Row 0 - Section
const dataField0 = existing.data?.fields?.[0] as SectionField;
const row0 = createConnectionTypePage.getFieldsTableRow(dataField0.name);
row0.findSectionHeading().should('exist');

// Row 1 - Short text field
const dataField1 = existing.data?.fields?.[1] as ShortTextField;
const row1 = createConnectionTypePage.getFieldsTableRow(dataField1.name);
row1.findType().should('have.text', dataField1.type);
row1.findDefault().should('have.text', '-');
row1.findRequired().not('be.checked');

// Row 2 - Short text field
const dataField2 = existing.data?.fields?.[2] as ShortTextField;
const row2 = createConnectionTypePage.getFieldsTableRow(dataField2.name);
row2.findType().should('have.text', dataField2.type);
row2.findDefault().should('have.text', dataField2.properties.defaultValue);
row2.findRequired().should('be.checked');
});
});
Loading

0 comments on commit a842c0c

Please sign in to comment.