Skip to content

Commit

Permalink
Fix Console tests so they run
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamilto committed Aug 24, 2023
1 parent 73e7e38 commit 2d5d9b3
Show file tree
Hide file tree
Showing 31 changed files with 147 additions and 122 deletions.
Expand Up @@ -13,6 +13,7 @@ declare global {
Cypress.Commands.add('initAdmin', () => {
cy.log('redirect to home');
cy.visit('/');
cy.byTestID('loading-indicator').should('not.exist');
cy.log('ensure perspective switcher is set to Administrator');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
Expand Down
Expand Up @@ -51,6 +51,6 @@ Cypress.Commands.add('deleteProject', (name: string) => {
listPage.titleShouldHaveText('Projects');
});

Cypress.Commands.add('deleteProjectWithCLI', (name: string) => {
cy.exec(`oc delete project ${name}`);
Cypress.Commands.add('deleteProjectWithCLI', (name: string, timeout?: number) => {
cy.exec(`oc delete project ${name}`, { timeout });
});
Expand Up @@ -31,25 +31,20 @@ spec:
describe('Debug pod', () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
checkErrors();
});

after(() => {
cy.visit(`/k8s/ns/${testName}/pods`);
listPage.rows.shouldBeLoaded();
listPage.filter.byName(POD_NAME);
listPage.rows.clickKebabAction(POD_NAME, 'Delete Pod');
modal.shouldBeOpened();
modal.submit();
modal.shouldBeClosed();
cy.deleteProject(testName);
cy.visit('/');
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand Down
Expand Up @@ -21,19 +21,14 @@ const CHECK_UPDATES_ALIAS = 'checkUpdates';
2a. build the plugin locally, and run the server
2b. using bridge running with the plugin arguments that point to the local dynamic plugin server and i18n namespace
e.g., ./bin/bridge -plugins=console-demo-plugin=http://localhost:9001 -i18n-namespaces=plugin__console-demo-plugin
2c. will intercept the check update call to mock a toast notification that a plugin has been enabled
2d. will not use all workload definitions defined in the yaml (not using the env variable for pull spec)
2c. will not use all workload definitions defined in the yaml (not using the env variable for pull spec)
3. run on ci:
3a. ci will build the dynamic plugin and provide the pullspec in the env var: CYPRESS_PLUGIN_PULL_SPEC
3b. that pull spec will be used to create the deployment on the cluster
3c. intercepting the check-updates call will not occur as the toast will appear when the plugin is enabled
4. the scaffolding should remain the same except modifying the constants above
*/

const enableDemoPlugin = (enable: boolean) => {
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
// find console demo plugin and enable it
cy.visit('k8s/cluster/operator.openshift.io~v1~Console/cluster/console-plugins');
cy.url().should(
Expand All @@ -58,17 +53,7 @@ const enableDemoPlugin = (enable: boolean) => {
.within(() => {
cy.byTestID('edit-console-plugin').contains(enable ? 'Enabled' : 'Disabled');
});
if (isLocalDevEnvironment) {
// for local dev env trigger a change by removing the plugin to activate the toast
cy.intercept('/api/check-updates', {
consoleCommit: '',
plugins: [],
}).as(CHECK_UPDATES_ALIAS);
cy.wait(`@${CHECK_UPDATES_ALIAS}`, { requestTimeout: CHECK_UPDATE_WAIT });
cy.log('Running plugin test locally using bridge.');
} else {
cy.log(`Running plugin test on ci using PLUGIN_PULL_SPEC: ${PLUGIN_PULL_SPEC}`);
}
cy.log(`Running plugin test on ci using PLUGIN_PULL_SPEC: ${PLUGIN_PULL_SPEC}`);
cy.byTestID(refreshWebConsoleLink, { timeout: CHECK_UPDATE_WAIT })
.should('exist')
.then(() => {
Expand Down Expand Up @@ -101,9 +86,7 @@ if (!Cypress.env('OPENSHIFT_CI') || Cypress.env('PLUGIN_PULL_SPEC')) {
describe('Demo dynamic plugin test', () => {
before(() => {
cy.login();
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(PLUGIN_NAME);
cy.createProjectWithCLI(PLUGIN_NAME);
cy.readFile(`${PLUGIN_PATH}/oc-manifest.yaml`).then((textManifest) => {
const yamlManifest = safeLoadAll(textManifest);
const deployment = yamlManifest.find(({ kind }) => kind === 'Deployment');
Expand Down Expand Up @@ -150,7 +133,9 @@ if (!Cypress.env('OPENSHIFT_CI') || Cypress.env('PLUGIN_PULL_SPEC')) {
listPage.rows.shouldBeLoaded();
listPage.filter.byName(PLUGIN_NAME);
listPage.rows.shouldExist(PLUGIN_NAME);
enableDemoPlugin(true);
if (!isLocalDevEnvironment && PLUGIN_PULL_SPEC) {
enableDemoPlugin(true);
}
});
});
});
Expand All @@ -160,8 +145,10 @@ if (!Cypress.env('OPENSHIFT_CI') || Cypress.env('PLUGIN_PULL_SPEC')) {
});

after(() => {
enableDemoPlugin(false);
cy.deleteProject(PLUGIN_NAME);
if (!isLocalDevEnvironment && PLUGIN_PULL_SPEC) {
enableDemoPlugin(false);
}
cy.deleteProjectWithCLI(PLUGIN_NAME);
cy.logout();
});

Expand Down
Expand Up @@ -14,10 +14,8 @@ const WORKLOAD_LABEL = `lbl-filter=${testName}`;
describe('Filtering and Searching', () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.initAdmin();
cy.createProjectWithCLI(testName);
cy.visit(`/k8s/ns/${testName}/deployments`);
listPage.clickCreateYAMLbutton();
cy.byTestID('yaml-view-input').click();
Expand All @@ -36,6 +34,10 @@ describe('Filtering and Searching', () => {
});
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
checkErrors();
});
Expand All @@ -48,7 +50,7 @@ describe('Filtering and Searching', () => {
modal.shouldBeOpened();
modal.submit();
modal.shouldBeClosed();
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand Down
Expand Up @@ -5,7 +5,10 @@ import { listPage } from '../../views/list-page';
describe('Node terminal', () => {
before(() => {
cy.login();
cy.visit('/');
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
Expand Down
Expand Up @@ -25,10 +25,7 @@ const overviewResources = ImmutableSet([
describe('Visiting Overview page', () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
});

afterEach(() => {
Expand All @@ -40,6 +37,7 @@ describe('Visiting Overview page', () => {
const resourceName = `${testName}-${kindModel.kind.toLowerCase()}`;

before(() => {
cy.initAdmin();
cy.visit(`k8s/ns/${testName}/${kindModel.plural}/~new`);
masthead.username.shouldBeVisible();
yamlEditor.isLoaded();
Expand All @@ -57,6 +55,10 @@ describe('Visiting Overview page', () => {
});
});

beforeEach(() => {
cy.initAdmin();
});

it(`displays a ${kindModel.id} in the overview list page`, () => {
cy.visit(`/k8s/cluster/projects/${testName}/workloads?view=list`);
overviewPage.projectOverviewShouldBeVisible();
Expand Down
Expand Up @@ -100,6 +100,7 @@ describe('PollConsoleUpdates Test', () => {
cy.wait(`@${CHECK_UPDATES_ALIAS}`, WAIT_OPTIONS);
cy.intercept(PLUGIN_MANIFEST_URL2, { forceNetworkError: true }).as(CHECK_MANIFEST_ALIAS2);
cy.wait(`@${CHECK_MANIFEST_ALIAS2}`, WAIT_OPTIONS);
// cy.wait(`@${CHECK_MANIFEST_ALIAS2}`, WAIT_OPTIONS).should('have.property', 'error');
cy.byTestID('loading-indicator').should('not.exist');
cy.get(refreshWebConsoleLink).should('not.exist');
cy.intercept(PLUGIN_MANIFEST_URL2, PLUGIN_MANIFEST_DEFAULT2).as(CHECK_MANIFEST_ALIAS2);
Expand Down
Expand Up @@ -29,8 +29,10 @@ describe(`${crd} CRD`, () => {

before(() => {
cy.login();
cy.visit('/');
cy.byLegacyTestID('resource-title').contains('Overview');
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
Expand Down
Expand Up @@ -19,18 +19,19 @@ describe(`${crd} CRD`, () => {

before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
checkErrors();
});

after(() => {
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand Down
Expand Up @@ -30,7 +30,10 @@ describe(`${crd} CRD`, () => {

before(() => {
cy.login();
cy.visit('/');
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
Expand Down
Expand Up @@ -20,7 +20,10 @@ describe(`${crd} CRD`, () => {

before(() => {
cy.login();
cy.visit('/');
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
Expand Down
Expand Up @@ -20,7 +20,11 @@ const resourceObjs =
describe('Add storage is applicable for all workloads', () => {
before(() => {
cy.login();
cy.createProject(testName);
cy.createProjectWithCLI(testName);
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
Expand All @@ -37,7 +41,7 @@ describe('Add storage is applicable for all workloads', () => {
console.error(`Failed to delete ${resourceType} example:\n${error}`);
}
});
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName, 300000); // increase timeout to allow cascading deletes above to complete
cy.logout();
});

Expand Down
Expand Up @@ -7,10 +7,14 @@ import { listPage } from '../../views/list-page';
import { modal } from '../../views/modal';
import { nav } from '../../views/nav';
import * as yamlEditor from '../../views/yaml-editor';
import { projectDropdown } from '../../views/common';

const createExampleConfigMapInstance = () => {
cy.initAdmin();
nav.sidenav.clickNavLink(['Workloads', 'ConfigMaps']);
cy.byLegacyTestID('resource-title').should('have.text', 'ConfigMaps');
projectDropdown.selectProject(testName);
projectDropdown.shouldContain(testName);
listPage.clickCreateYAMLbutton();
cy.byTestID('yaml-view-input').click();
cy.byTestID('resource-sidebar').should('exist');
Expand Down Expand Up @@ -66,10 +70,7 @@ const nameValueEquals = (row: JQuery<HTMLElement>, name: string, value: string)
describe('Annotations', () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
createExampleConfigMapInstance();
});

Expand All @@ -79,7 +80,7 @@ describe('Annotations', () => {

after(() => {
deleteExampleConfigMapInstance();
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand Down
Expand Up @@ -75,18 +75,19 @@ stringData:

before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(namespace);
cy.createProjectWithCLI(namespace);
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
checkErrors();
});

after(() => {
cy.deleteProject(namespace);
cy.deleteProjectWithCLI(namespace);
cy.logout();
});

Expand Down
Expand Up @@ -73,18 +73,19 @@ describe('CustomResourceDefinitions', () => {

before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
});

beforeEach(() => {
cy.initAdmin();
});

afterEach(() => {
checkErrors();
});

after(() => {
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand Down

0 comments on commit 2d5d9b3

Please sign in to comment.