Skip to content

Commit

Permalink
Fix OLM tests so they run
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamilto committed Aug 23, 2023
1 parent e511a43 commit 73e7e38
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 123 deletions.
19 changes: 19 additions & 0 deletions frontend/packages/integration-tests-cypress/support/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { nav } from '../views/nav';

declare global {
namespace Cypress {
interface Chainable {
initAdmin(): Chainable<Element>;
}
}
}

// any command added below, must be added to global Cypress interface above

Cypress.Commands.add('initAdmin', () => {
cy.log('redirect to home');
cy.visit('/');
cy.log('ensure perspective switcher is set to Administrator');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './nav';
import './resources';
import './i18n';
import { a11yTestResults } from './a11y';
import './admin';

Cypress.Cookies.debug(true);

Expand Down
10 changes: 10 additions & 0 deletions frontend/packages/integration-tests-cypress/support/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ declare global {
namespace Cypress {
interface Chainable {
createProject(name: string): Chainable<Element>;
createProjectWithCLI(name: string): Chainable<Element>;
deleteProject(name: string): Chainable<Element>;
deleteProjectWithCLI(name: string): Chainable<Element>;
}
}
}
Expand All @@ -30,6 +32,10 @@ Cypress.Commands.add('createProject', (name: string, devConsole: boolean = false
}
});

Cypress.Commands.add('createProjectWithCLI', (name: string) => {
cy.exec(`oc new-project ${name}`);
});

Cypress.Commands.add('deleteProject', (name: string) => {
cy.log(`delete project`);
cy.visit(`/k8s/cluster/projects/${name}`);
Expand All @@ -44,3 +50,7 @@ Cypress.Commands.add('deleteProject', (name: string) => {
modal.shouldBeClosed();
listPage.titleShouldHaveText('Projects');
});

Cypress.Commands.add('deleteProjectWithCLI', (name: string) => {
cy.exec(`oc delete project ${name}`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ const managedCatalogSource = {
describe(`Interacting with CatalogSource page`, () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
create(testCatalogSource);
});

beforeEach(() => {
cy.initAdmin();
cy.log('navigate to Catalog Source page');
nav.sidenav.clickNavLink(['Administration', 'Cluster Settings']);
cy.byLegacyTestID('horizontal-link-Configuration').click();
Expand All @@ -38,7 +36,7 @@ describe(`Interacting with CatalogSource page`, () => {
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { nav } from '../../../integration-tests-cypress/views/nav';
describe('Create namespace from install operators', () => {
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
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as _ from 'lodash';
import { checkErrors, create, testName } from '../../../integration-tests-cypress/support';
import { nav } from '../../../integration-tests-cypress/views/nav';
import { testCR, testCRD, testCSV } from '../mocks';

describe('Using OLM descriptor components', () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
cy.createProjectWithCLI(testName);
create(testCRD);
create(testCSV);
});

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

afterEach(() => {
cy.visit('/');
cy.exec(`oc delete ${testCRD.spec.names.kind} ${testCR.metadata.name} -n ${testName}`);
Expand All @@ -23,7 +23,7 @@ describe('Using OLM descriptor components', () => {
after(() => {
cy.exec(`oc delete crd ${testCRD.metadata.name}`);
cy.exec(`oc delete -n ${testName} clusterserviceversion ${testCSV.metadata.name}`);
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand Down Expand Up @@ -55,20 +55,18 @@ describe('Using OLM descriptor components', () => {
const getOperandFormFieldLabel = (id) => cy.get(`[for=${id}]`);
const getOperandFormFieldInput = (id) => cy.get(`#${id}`);

const {
group,
names: { kind },
} = testCRD.spec;
const version = testCRD.spec.versions[0].name;
const URL = `/k8s/ns/${testName}/operators.coreos.com~v1alpha1~ClusterServiceVersion/${testCSV.metadata.name}/${group}~${version}~${kind}`;

it('displays list and detail views of an operand', () => {
create(testCR);
cy.visit(
`/k8s/ns/${testName}/operators.coreos.com~v1alpha1~ClusterServiceVersion/${testCSV.metadata.name}/${testCRD.spec.group}~${testCRD.spec.versions[0].name}~${testCRD.spec.names.kind}`,
);
cy.visit(URL);
cy.byTestOperandLink('olm-descriptors-test').should('exist');
const {
group,
names: { kind },
} = testCRD.spec;
const version = testCRD.spec.versions[0].name;
cy.visit(
`/k8s/ns/${testName}/operators.coreos.com~v1alpha1~ClusterServiceVersion/${testCSV.metadata.name}/${group}~${version}~${kind}/${testCR.metadata.name}`,
);
cy.visit(`${URL}/${testCR.metadata.name}`);
cy.byLegacyTestID('resource-title').should('have.text', `${testCR.metadata.name}`);
testCSV.spec.customresourcedefinitions.owned[0].specDescriptors.forEach((descriptor) => {
if (descriptor.path === 'hidden') {
Expand All @@ -90,9 +88,7 @@ describe('Using OLM descriptor components', () => {
});

it('creates an operand using the form', () => {
cy.visit(
`/k8s/ns/${testName}/operators.coreos.com~v1alpha1~ClusterServiceVersion/${testCSV.metadata.name}/${testCRD.spec.group}~${testCRD.spec.versions[0].name}~${testCRD.spec.names.kind}`,
);
cy.visit(URL);
// TODO figure out why this element is detaching
cy.byTestID('item-create').click({ force: true });
cy.byLegacyTestID('resource-title').should('have.text', 'Create App');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ describe('Create namespace from install operators', () => {
cy.login();
});

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

afterEach(() => {
checkErrors();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ import { nav } from '../../../integration-tests-cypress/views/nav';
describe('Interacting with OperatorHub', () => {
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();
});

it('displays OperatorHub tile view with expected available Operators', () => {
cy.log('navigate to OperatorHub');
nav.sidenav.clickNavLink(['Operators', 'OperatorHub']);
cy.url().should('include', `/operatorhub/ns/${testName}`);
cy.url().should('include', '/operatorhub/all-namespaces');
cy.log('more than one tile should be present');
cy.get('.catalog-tile-pf').its('length').should('be.gt', 0);
});

it('displays OperatorHub tiles filtered by "Source"', () => {
cy.log('enable the Red Hat filter');
cy.byTestID('catalogSourceDisplayName-red-hat').click();
cy.log('more than one tile should be present');
Expand All @@ -52,9 +51,8 @@ describe('Interacting with OperatorHub', () => {
.invoke('text')
.should('not.equal', origCatalogTitleTxt);
});
});

it('filters Operators by name', () => {
cy.log('filters Operators by name');
const operatorName = 'Datadog Operator';
cy.byTestID('search-operatorhub').type(operatorName);
cy.get('.catalog-tile-pf').its('length').should('be.gt', 0);
Expand All @@ -63,22 +61,19 @@ describe('Interacting with OperatorHub', () => {
.find('.catalog-tile-pf-title')
.should('have.text', operatorName);
cy.byTestID('search-operatorhub').clear();
});

it('displays "Clear All Filters" link when text filter removes all Operators from display', () => {
cy.log('displays "Clear All Filters" link when text filter removes all Operators from display');
cy.log('enter a search query that will return zero results');
cy.byTestID('search-operatorhub').type('NoOperatorsTest');
cy.get('.catalog-tile-pf').should('not.exist');
cy.byLegacyTestID('catalog-clear-filters').should('exist');
});

it('clears text filter when "Clear All Filters" link is clicked', () => {
cy.log('clears text filter when "Clear All Filters" link is clicked');
cy.byLegacyTestID('catalog-clear-filters').click();
cy.byTestID('search-operatorhub').get('input').should('be.empty');
cy.get('.catalog-tile-pf').its('length').should('be.gt', 0);
});

it('filters Operators by category', () => {
cy.log('filters Operators by category');
const filterLabel = 'AI/Machine Learning';
cy.log(`click the ${filterLabel} filter`);
cy.get(`[data-test="${filterLabel}"] > a`).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ import { nav } from '../../../integration-tests-cypress/views/nav';
import { operator, GlobalInstalledNamespace, TestOperandProps } from '../views/operator.view';

const testOperator = {
name: 'Service Binding Operator',
operatorHubCardTestID: 'rh-service-binding-operator-redhat-operators-openshift-marketplace',
name: 'Data Grid',
operatorHubCardTestID: 'datagrid-redhat-operators-openshift-marketplace',
};

const testOperand: TestOperandProps = {
name: 'ServiceBinding',
group: 'binding.operators.coreos.com',
version: 'v1alpha1',
kind: 'ServiceBinding',
createActionID:
'list-page-create-dropdown-item-binding.operators.coreos.com~v1alpha1~ServiceBinding',
exampleName: 'example-servicebinding',
name: 'Infinispan',
group: 'infinispan.org',
version: 'v1',
kind: 'Infinispan',
createActionID: 'list-page-create-dropdown-item-infinispan.org~v1~Infinispan',
exampleName: 'example-infinispan',
};

describe(`Globally installing "${testOperator.name}" operator in ${GlobalInstalledNamespace}`, () => {
before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
operator.install(testOperator.name, testOperator.operatorHubCardTestID);
});

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

afterEach(() => {
checkErrors();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@ import { nav } from '../../../integration-tests-cypress/views/nav';
import { GlobalInstalledNamespace, operator, TestOperandProps } from '../views/operator.view';

const testOperator = {
name: 'Red Hat Integration - 3scale',
operatorHubCardTestID: '3scale-operator-redhat-operators-openshift-marketplace',
name: 'Data Grid',
operatorHubCardTestID: 'datagrid-redhat-operators-openshift-marketplace',
installedNamespace: testName,
};

const testOperand: TestOperandProps = {
name: '3scale Backend',
group: 'capabilities.3scale.net',
version: 'v1beta1',
kind: 'Backend',
exampleName: `backend1-sample`,
name: 'Backup',
group: 'infinispan.org',
version: 'v1',
kind: 'Backup',
exampleName: 'example-backup',
};

describe(`Installing "${testOperator.name}" operator in test namespace`, () => {
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(() => {
operator.uninstall(testOperator.name, testOperator.installedNamespace);
operator.shouldNotExist(testOperator.name, testOperator.installedNamespace);
cy.deleteProject(testName);
cy.deleteProjectWithCLI(testName);
cy.logout();
});

Expand All @@ -44,7 +43,7 @@ describe(`Installing "${testOperator.name}" operator in test namespace`, () => {
testOperator.operatorHubCardTestID,
testOperator.installedNamespace,
);
operator.installedSucceeded(testOperator.name);
operator.installedSucceeded(testOperator.name, testName);

operator.navToDetailsPage(testOperator.name, testOperator.installedNamespace);
cy.byTestSectionHeading('Provided APIs').should('exist');
Expand All @@ -66,7 +65,7 @@ describe(`Installing "${testOperator.name}" operator in test namespace`, () => {
cy.byTestID('msg-box-title').should('contain', 'No Operators found');
} else {
// when running test on a shared cluster
listPage.filter.byName(testOperator.name);
operator.filterByName(testOperator.name);
listPage.rows.countShouldBe(0);
}
});
Expand All @@ -77,5 +76,8 @@ describe(`Installing "${testOperator.name}" operator in test namespace`, () => {

operator.deleteOperand(testOperator.name, testOperand, testOperator.installedNamespace);
operator.operandShouldNotExist(testOperator.name, testOperand, testOperator.installedNamespace);

operator.uninstall(testOperator.name, testOperator.installedNamespace);
operator.shouldNotExist(testOperator.name, testOperator.installedNamespace);
});
});

0 comments on commit 73e7e38

Please sign in to comment.