Skip to content

Commit

Permalink
Support for Trusty DB fields (#3305)
Browse files Browse the repository at this point in the history
* Support for Trusty DB fields

* Added granularity to the type of error & useDebounce func

* Fix tests & add a DBConnecting state check

* unsecret-ify the mock secret

* Reduce already installed creationTimestamp for trusty tests

* Remove odd cancel in debounce logic
  • Loading branch information
andrewballantyne authored Oct 11, 2024
1 parent 63e8206 commit 0c15247
Show file tree
Hide file tree
Showing 37 changed files with 1,188 additions and 588 deletions.
62 changes: 45 additions & 17 deletions frontend/src/__mocks__/mockSecretK8sResource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
import { KnownLabels, SecretKind } from '~/k8sTypes';
import { genUID } from '~/__mocks__/mockUtils';

type MockCustomSecretData = {
name: string;
namespace: string;
uid?: string;
labels?: Record<string, string>;
annotations?: Record<string, string>;
data: Record<string, string>;
};

export const mockCustomSecretK8sResource = ({
name,
namespace,
uid = 'some-test-uid',
labels = {},
annotations = {},
data,
}: MockCustomSecretData): SecretKind => ({
kind: 'Secret',
apiVersion: 'route.openshift.io/v1',
metadata: {
name,
namespace,
uid,
resourceVersion: '5985371',
creationTimestamp: '2023-03-22T16:18:56Z',
labels: {
[KnownLabels.DASHBOARD_RESOURCE]: 'true',
...labels,
},
annotations,
},
data,
type: 'Opaque',
});

type MockResourceConfigType = {
name?: string;
namespace?: string;
Expand All @@ -21,30 +56,23 @@ export const mockSecretK8sResource = ({
endPoint = 'aHR0cHM6Ly9zMy5hbWF6b25hd3MuY29tLw==',
region = 'dXMtZWFzdC0x',
uid = genUID('secret'),
}: MockResourceConfigType): SecretKind => ({
kind: 'Secret',
apiVersion: 'route.openshift.io/v1',
metadata: {
}: MockResourceConfigType): SecretKind =>
mockCustomSecretK8sResource({
name,
namespace,
uid,
resourceVersion: '5985371',
creationTimestamp: '2023-03-22T16:18:56Z',
labels: {
[KnownLabels.DASHBOARD_RESOURCE]: 'true',
[KnownLabels.DATA_CONNECTION_AWS]: 'true',
},
annotations: {
'opendatahub.io/connection-type': connectionType,
'openshift.io/display-name': displayName,
},
},
data: {
AWS_ACCESS_KEY_ID: 'c2RzZA==',
AWS_DEFAULT_REGION: region,
AWS_S3_BUCKET: s3Bucket,
AWS_S3_ENDPOINT: endPoint,
AWS_SECRET_ACCESS_KEY: 'c2RzZA==',
},
type: 'Opaque',
});
data: {
AWS_ACCESS_KEY_ID: 'c2RzZA==',
AWS_DEFAULT_REGION: region,
AWS_S3_BUCKET: s3Bucket,
AWS_S3_ENDPOINT: endPoint,
AWS_SECRET_ACCESS_KEY: 'c2RzZA==',
},
});
13 changes: 6 additions & 7 deletions frontend/src/__mocks__/mockTrustyAIServiceK8sResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type MockTrustyAIServiceK8sResourceOptions = {
namespace?: string;
};

export const mockTrustyAIServiceK8sResource = ({
export const mockTrustyAIServiceForDbK8sResource = ({
isAvailable = true,
creationTimestamp = new Date().toISOString(),
namespace = 'test-project',
Expand All @@ -27,9 +27,8 @@ export const mockTrustyAIServiceK8sResource = ({
schedule: '5s',
},
storage: {
folder: '/inputs',
format: 'PVC',
size: '1Gi',
format: 'DATABASE',
databaseConfigurations: 'test-secret',
},
},
status: {
Expand All @@ -43,10 +42,10 @@ export const mockTrustyAIServiceK8sResource = ({
},
{
lastTransitionTime: '2024-01-11T18:29:06Z',
message: 'PersistentVolumeClaim found',
reason: 'PVCFound',
message: 'Database connected',
reason: 'DBConnected',
status: 'True',
type: 'PVCAvailable',
type: 'DBAvailable',
},
{
lastTransitionTime: '2024-01-11T18:29:06Z',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { DeleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';

/** Duped to avoid importing code from the app into tests (and breaking webpack) */
const TRUSTYAI_INSTALL_MODAL_TEST_ID = 'trusty-db-config';

export class TrustyAICRState {
configureModal = new TrustyAICRModal();

deleteModal = new TrustyAIUninstallModal();

findError(): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.findByTestId('trustyai-service-error');
}

findUninstallButton(): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.findByTestId('trustyai-uninstall-button');
}

findInstallButton(): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.findByTestId('trustyai-configure-button');
}
}

class TrustyAICRModal extends Modal {
constructor() {
super('Configure TrustyAI service');
}

findSubmitButton(): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.findByTestId('modal-submit-button');
}

private findField(fieldName: string): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.findByTestId(`${TRUSTYAI_INSTALL_MODAL_TEST_ID}-${fieldName}`);
}

findExistingRadio(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('radio-existing');
}

findNewRadio(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('radio-new');
}

findExistingNameField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('existing-secret');
}

findNewKindField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databaseKind');
}

findNewUsernameField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databaseUsername');
}

findNewPasswordField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databasePassword');
}

findNewServiceField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databaseService');
}

findNewPortField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databasePort');
}

findNewDbNameField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databaseName');
}

findNewGenerationField(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.findField('databaseGeneration');
}
}

class TrustyAIUninstallModal extends DeleteModal {
constructor() {
super('Warning alert: Uninstall TrustyAI');
}

findSubmitButton() {
return this.findFooter().findByRole('button', { name: 'Uninstall' });
}
}
35 changes: 3 additions & 32 deletions frontend/src/__tests__/cypress/cypress/pages/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { appChrome } from '~/__tests__/cypress/cypress/pages/appChrome';
import { DeleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal';
import { Contextual } from '~/__tests__/cypress/cypress/pages/components/Contextual';
import { K8sNameDescriptionField } from '~/__tests__/cypress/cypress/pages/components/subComponents/K8sNameDescriptionField';
import { TrustyAICRState } from '~/__tests__/cypress/cypress/pages/components/TrustyAICRState';
import { TableRow } from './components/table';

class ProjectListToolbar extends Contextual<HTMLElement> {
Expand Down Expand Up @@ -300,43 +301,13 @@ class ProjectDetails {
}

class ProjectDetailsSettingsTab extends ProjectDetails {
trustyai = new TrustyAICRState();

visit(project: string) {
super.visit(project);
this.findTab('Settings').click();

this.findTrustyAIInstallCheckbox();
cy.testA11y();
}

findTrustyAIInstallCheckbox() {
return cy.findByTestId('trustyai-service-installation');
}

getTrustyAIUninstallModal() {
return new TrustyAIUninstallModal();
}

findTrustyAITimeoutError() {
return cy.findByTestId('trustyai-service-timeout-error');
}

findTrustyAIServiceError() {
return cy.findByTestId('trustyai-service-error');
}

findTrustyAISuccessAlert() {
return cy.findByTestId('trustyai-service-installed-alert');
}
}

class TrustyAIUninstallModal extends DeleteModal {
constructor() {
super('Warning alert: Uninstall TrustyAI');
}

findSubmitButton() {
return this.findFooter().findByRole('button', { name: 'Uninstall' });
}
}

export const projectListPage = new ProjectListPage();
Expand Down
Loading

0 comments on commit 0c15247

Please sign in to comment.