Skip to content

Commit

Permalink
migrate playwright tests to cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
christianvogt committed Dec 8, 2023
1 parent bdb92ab commit 8eea2be
Show file tree
Hide file tree
Showing 26 changed files with 2,027 additions and 101 deletions.
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/playwright-report/
/playwright/.cache/
/storybook-static/
/public-cypress

# production
/public
Expand Down
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"cypress:run:mock": "MOCK=1 npm run cypress:run",
"cypress:open:record": "RECORD=1 npm run cypress:open",
"cypress:run:record": "RECORD=1 npm run cypress:run",
"cypress:server": "serve ./public -p 9001 -s",
"cypress:server:build": "ODH_DIST_DIR=./public-cypress POLL_INTERVAL=9999999 FAST_POLL_INTERVAL=9999999 npm run build",
"cypress:server": "serve ./public-cypress -p 9001 -s",
"cypress:format": "prettier --write src/__tests__/**/*.snap.json"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { mockClusterSettings } from '~/__mocks__/mockClusterSettings';
import { mockDashboardConfig } from '~/__mocks__/mockDashboardConfig';
import { mockDscStatus } from '~/__mocks__/mockDscStatus';
import { mockStatus } from '~/__mocks__/mockStatus';
import {
clusterSettings,
cullerSettings,
modelServingSettings,
notebookTolerationSettings,
pvcSizeSettings,
telemetrySettings,
} from '~/__tests__/cypress/cypress/pages/clusterSettings';
import { be } from '~/__tests__/cypress/cypress/utils/should';
import { StackComponent } from '~/concepts/areas/types';

it('Cluster Settings', () => {
cy.intercept(
'/api/dsc/status',
mockDscStatus({
installedComponents: { [StackComponent.K_SERVE]: true, [StackComponent.MODEL_MESH]: true },
}),
);
cy.intercept('/api/status', mockStatus());
cy.intercept('/api/config', mockDashboardConfig({}));
cy.intercept('/api/cluster-settings', mockClusterSettings({}));

clusterSettings.visit();

// check serving platform field
modelServingSettings.findSinglePlatformCheckbox().should('be.checked');
modelServingSettings.findMultiPlatformCheckbox().should('be.checked');
modelServingSettings.findSubmitButton().should('be.disabled');
modelServingSettings.findMultiPlatformCheckbox().uncheck();
modelServingSettings.findAlert().should(be.info);
modelServingSettings.findSubmitButton().should('be.enabled');
modelServingSettings.findSinglePlatformCheckbox().uncheck();
modelServingSettings.findAlert().should(be.warning);
modelServingSettings.findMultiPlatformCheckbox().check();
modelServingSettings.findAlert().should(be.info);
modelServingSettings.findSinglePlatformCheckbox().check();
modelServingSettings.findAlert().should('not.exist');
modelServingSettings.findSubmitButton().should('be.disabled');

// check PVC size field
pvcSizeSettings.findInput().clear();
pvcSizeSettings.findInput().type('10');
pvcSizeSettings.findSubmitButton().should('be.enabled');
pvcSizeSettings.findInput().clear();
pvcSizeSettings.findSubmitButton().should('be.disabled');
pvcSizeSettings.findHint().should(be.error);
pvcSizeSettings.findRestoreDefaultsButton().click();
pvcSizeSettings.findHint().should(be.indeterminate);

// // check culler field
cullerSettings.findLimitedOption().click();
cullerSettings.findSubmitButton().should('be.enabled');
cullerSettings.findHoursInput().clear();
cullerSettings.findSubmitButton().should('be.disabled');
cullerSettings.findHint().should(be.error);
cullerSettings.findMinutesInput().type('20');
cullerSettings.findSubmitButton().should('be.enabled');
cullerSettings.findHint().should(be.indeterminate);
cullerSettings.findUnlimitedOption().click();
cullerSettings.findSubmitButton().should('be.disabled');

// check user tracking field
telemetrySettings.findEnabledCheckbox().click();
telemetrySettings.findSubmitButton().should('be.enabled');
telemetrySettings.findEnabledCheckbox().click();
telemetrySettings.findSubmitButton().should('be.disabled');

// check notebook toleration field
notebookTolerationSettings.findKeyError().should('not.exist');
notebookTolerationSettings.findKeyInput().clear();
notebookTolerationSettings.findKeyError().should('exist');
notebookTolerationSettings.findSubmitButton().should('be.disabled');
notebookTolerationSettings.findKeyInput().type('NotebooksOnlyChange');
notebookTolerationSettings.findKeyError().should('not.exist');
notebookTolerationSettings.findEnabledCheckbox().click();
notebookTolerationSettings.findSubmitButton().should('be.enabled');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { mockDashboardConfig } from '~/__mocks__/mockDashboardConfig';
import { mockK8sResourceList } from '~/__mocks__/mockK8sResourceList';
import { mockProjectK8sResource } from '~/__mocks__/mockProjectK8sResource';
import { mockServingRuntimeTemplateK8sResource } from '~/__mocks__/mockServingRuntimeTemplateK8sResource';
import { mockStatus } from '~/__mocks__/mockStatus';
import { servingRuntimes } from '~/__tests__/cypress/cypress/pages/servingRuntimes';
import { ServingRuntimePlatform } from '~/types';

it('Custom serving runtimes', () => {
cy.intercept('/api/status', mockStatus());
cy.intercept('/api/config', mockDashboardConfig({}));
cy.intercept('/api/dashboardConfig/opendatahub/odh-dashboard-config', mockDashboardConfig({}));
cy.intercept(
{ pathname: '/api/templates/opendatahub' },
mockK8sResourceList([
mockServingRuntimeTemplateK8sResource({
name: 'template-1',
displayName: 'Multi Platform',
platforms: [ServingRuntimePlatform.SINGLE, ServingRuntimePlatform.MULTI],
}),
mockServingRuntimeTemplateK8sResource({
name: 'template-2',
displayName: 'Caikit',
platforms: [ServingRuntimePlatform.SINGLE],
}),
mockServingRuntimeTemplateK8sResource({
name: 'template-3',
displayName: 'OVMS',
platforms: [ServingRuntimePlatform.MULTI],
}),
mockServingRuntimeTemplateK8sResource({
name: 'template-4',
displayName: 'Serving Runtime with No Annotations',
}),
]),
);
cy.intercept(
'/api/k8s/apis/project.openshift.io/v1/projects',
mockK8sResourceList([mockProjectK8sResource({})]),
);

servingRuntimes.visit();

// check the platform setting labels in the header
servingRuntimes.shouldBeSingleModel(true).shouldBeMultiModel(true);

// check the platform labels in the table row
servingRuntimes.getRowById('template-1').shouldBeSingleModel(true).shouldBeMultiModel(true);
servingRuntimes.getRowById('template-2').shouldBeSingleModel(true).shouldBeMultiModel(false);
servingRuntimes.getRowById('template-3').shouldBeSingleModel(false).shouldBeMultiModel(true);
servingRuntimes.getRowById('template-4').shouldBeSingleModel(false).shouldBeMultiModel(true);
});
Loading

0 comments on commit 8eea2be

Please sign in to comment.