Skip to content

Commit

Permalink
Add Cypress descriptors test
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamilto committed Nov 19, 2020
1 parent 0a84df9 commit a21200f
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 363 deletions.
4 changes: 0 additions & 4 deletions frontend/integration-tests/protractor.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ const testSuites = {
crudBasic: suite(['tests/crud.scenario.ts']),
monitoring: suite(['tests/monitoring.scenario.ts']),
newApp: suite(['tests/overview/overview.scenario.ts', 'tests/deploy-image.scenario.ts']),
olmFull: suite([
'../packages/operator-lifecycle-manager/integration-tests/scenarios/descriptors.scenario.ts',
]),
performance: suite(['tests/performance.scenario.ts']),
serviceCatalog: suite([
'tests/service-catalog/service-catalog.scenario.ts',
Expand Down Expand Up @@ -119,7 +116,6 @@ const testSuites = {
'tests/overview/overview.scenario.ts',
'tests/secrets.scenario.ts',
'tests/storage.scenario.ts',
'tests/olm/**/*.scenario.ts',
'tests/service-catalog/**/*.scenario.ts',
'tests/filter.scenario.ts',
'tests/modal-annotations.scenario.ts',
Expand Down
10 changes: 10 additions & 0 deletions frontend/packages/integration-tests-cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ export const editKind = (kind: string, humanizeKind: boolean) =>
actionOnKind(actions.edit, kind, humanizeKind);
export const deleteKind = (kind: string, humanizeKind: boolean) =>
actionOnKind(actions.delete, kind, humanizeKind);

export const create = (obj) => {
const filename = [
Cypress.config('screenshotsFolder'),
`${obj.metadata.name}.${obj.kind.toLowerCase()}.json`,
].join('/');
cy.writeFile(filename, JSON.stringify(obj));
cy.exec(`kubectl create -f ${filename}`);
cy.exec(`rm ${filename}`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ declare global {
byTestDropDownMenu(selector: string): Chainable<Element>;
byTestOperatorRow(selector: string): Chainable<Element>;
byTestSectionHeading(selector: string): Chainable<Element>;
byTestDropdownMenu(selector: string): Chainable<Element>;
byTestOperandLink(selector: string): Chainable<Element>;
}
}
Expand Down Expand Up @@ -54,10 +53,6 @@ Cypress.Commands.add('byTestSectionHeading', (selector: string) =>
cy.get(`[data-test-section-heading="${selector}"]`),
);

Cypress.Commands.add('byTestDropdownMenu', (selector: string) =>
cy.get(`[data-test-dropdown-menu="${selector}"]`),
);

Cypress.Commands.add('byTestOperandLink', (selector: string) =>
cy.get(`[data-test-operand-link="${selector}"]`),
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testName } from '@console/internal-integration-tests/protractor.conf';
import { SpecCapability, StatusCapability } from '../src/components/descriptors/types';
import { testName } from '../../../integration-tests-cypress/support';
import { SpecCapability, StatusCapability } from '../../src/components/descriptors/types';

const defaultValueFor = <C extends SpecCapability | StatusCapability>(capability: C) => {
switch (capability) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import * as _ from 'lodash';
import { checkErrors, create, testName } from '../../../integration-tests-cypress/support';
import { modal } from '../../../integration-tests-cypress/views/modal';
import { testCR, testCRD, testCSV } from '../mocks';

describe('Using OLM descriptor components', () => {
before(() => {
cy.login();
cy.createProject(testName);
create(testCRD);
create(testCSV);
create(testCR);
});

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

after(() => {
cy.exec(`kubectl delete crd ${testCRD.metadata.name}`);
cy.exec(`kubectl delete -n ${testName} clusterserviceversion ${testCSV.metadata.name}`);
cy.logout();
});

const ARRAY_FIELD_GROUP_ID = 'root_spec_arrayFieldGroup';
const FIELD_GROUP_ID = 'root_spec_fieldGroup';
const LABELS_FIELD_ID = 'root_metadata_labels';
const NAME_FIELD_ID = 'root_metadata_name';
const NUMBER_FIELD_ID = 'root_spec_number';
const PASSWORD_FIELD_ID = 'root_spec_password';
const SELECT_FIELD_ID = 'root_spec_select';
const atomicFields = [
{
label: 'Name',
path: 'metadata.name',
id: NAME_FIELD_ID,
},
{
label: 'Password',
path: 'spec.password',
id: PASSWORD_FIELD_ID,
},
{
label: 'Number',
path: 'spec.number',
id: NUMBER_FIELD_ID,
},
];
const getOperandFormFieldElement = (id) => cy.get(`#${id}_field`);
const getOperandFormFieldLabel = (id) => cy.get(`[for=${id}]`);
const getOperandFormFieldInput = (id) => cy.get(`#${id}`);

it('displays list containing operands', () => {
cy.visit(
`/ns/${testName}/clusterserviceversions/${testCSV.metadata.name}/${testCRD.spec.group}~${testCRD.spec.version}~${testCRD.spec.names.kind}`,
);
cy.byTestOperandLink('olm-descriptors-test').should('exist');
});

it('displays detail view for operand', () => {
const {
group,
version,
names: { kind },
} = testCRD.spec;
cy.visit(
`/ns/${testName}/clusterserviceversions/${testCSV.metadata.name}/${group}~${version}~${kind}/${testCR.metadata.name}`,
);
cy.byLegacyTestID('resource-title')
.invoke('text')
.should('be', `${testCR.metadata.name}`);
});

testCSV.spec.customresourcedefinitions.owned[0].specDescriptors.forEach((descriptor) => {
if (descriptor.path === 'hidden') {
it(`does not display spec descriptor for ${descriptor.displayName}`, () => {
cy.byTestSelector(`details-item-label__${descriptor.displayName}`).should('not.exist');
});
} else {
it(`displays spec descriptor for ${descriptor.displayName}`, () => {
cy.byTestSelector(`details-item-label__${descriptor.displayName}`).should('exist');
});
}
});

testCSV.spec.customresourcedefinitions.owned[0].statusDescriptors
// exclude Conditions since they are included in their own section
.filter((descriptor) => descriptor.path !== 'conditions')
.forEach((descriptor) => {
if (descriptor.path === 'hidden') {
it(`does not display status descriptor for ${descriptor.displayName}`, () => {
cy.byTestSelector(`details-item-label__${descriptor.displayName}`).should('not.exist');
});
} else {
it(`displays status descriptor for ${descriptor.displayName}`, () => {
cy.byTestSelector(`details-item-label__${descriptor.displayName}`).should('exist');
});
}
});

it('deletes operand', () => {
cy.log(
'Delete operand instance created in prior steps. Fixes a failure when trying to create a duplicate operand in the "successfully creates operand using form" step.',
);
cy.visit(
`/ns/${testName}/clusterserviceversions/${testCSV.metadata.name}/${testCRD.spec.group}~${testCRD.spec.version}~${testCRD.spec.names.kind}`,
);
cy.byTestOperandLink('olm-descriptors-test').should('exist');
cy.byLegacyTestID('kebab-button').click();
cy.byTestActionID(`Delete ${testCRD.spec.names.kind}`).click();
modal.shouldBeOpened();
modal.submit();
modal.shouldBeClosed();
});

it('displays form for creating operand', () => {
cy.visit(
`/ns/${testName}/clusterserviceversions/${testCSV.metadata.name}/${testCRD.spec.group}~${testCRD.spec.version}~${testCRD.spec.names.kind}`,
);
cy.byTestID('yaml-create').click();
cy.byLegacyTestID('resource-title').should('have.text', 'Create App');
});

// TODO: implement tests for more descriptor-based form fields and widgets as well as data syncing.
atomicFields.forEach(({ label, id, path }) => {
it(`pre-populates ${label} field`, () => {
getOperandFormFieldElement(id).should('exist');
getOperandFormFieldLabel(id).should('have.text', label);
getOperandFormFieldInput(id).should('have.value', _.get(testCR, path).toString());
});
});

it('pre-populates Select field', () => {
getOperandFormFieldElement(SELECT_FIELD_ID).should('exist');
getOperandFormFieldLabel(SELECT_FIELD_ID).should('have.text', 'Select');
cy.get(`#${SELECT_FIELD_ID} .pf-c-dropdown__toggle-text`).should(
'have.text',
testCR?.spec?.select.toString(),
);
});

it('pre-populates Labels field', () => {
getOperandFormFieldElement(LABELS_FIELD_ID).should('exist');
getOperandFormFieldLabel(LABELS_FIELD_ID).should('have.text', 'Labels');
cy.get(`#${LABELS_FIELD_ID}_field .tag-item__content`).should(
'have.text',
`automatedTestName=${testName}`,
);
});

it('pre-populates Field Group', () => {
cy.get(`#${FIELD_GROUP_ID}_field-group`).should('exist');
cy.get(`#${FIELD_GROUP_ID}_accordion-toggle`)
.should('exist')
.click();
cy.get(`[for="${FIELD_GROUP_ID}_itemOne"]`).should('have.text', 'Item One');
cy.get(`#${FIELD_GROUP_ID}_itemOne`).should('have.value', testCR.spec.fieldGroup.itemOne);
cy.get(`[for="${FIELD_GROUP_ID}_itemTwo"]`).should('have.text', 'Item Two');
cy.get(`#${FIELD_GROUP_ID}_itemTwo`).should('have.value', testCR.spec.fieldGroup.itemTwo);
});

it('pre-populates Array Field Group', () => {
cy.get(`#${ARRAY_FIELD_GROUP_ID}_field-group`).should('exist');
cy.get(`#${ARRAY_FIELD_GROUP_ID}_accordion-toggle`)
.should('exist')
.click();
cy.get(`[for="${ARRAY_FIELD_GROUP_ID}_0_itemOne"]`).should('have.text', 'Item One');
cy.get(`#${ARRAY_FIELD_GROUP_ID}_0_itemOne`).should(
'have.value',
testCR.spec.arrayFieldGroup[0].itemOne,
);
cy.get(`[for="${ARRAY_FIELD_GROUP_ID}_0_itemTwo"]`).should('have.text', 'Item Two');
cy.get(`#${ARRAY_FIELD_GROUP_ID}_0_itemTwo`).should(
'have.value',
testCR.spec.arrayFieldGroup[0].itemTwo,
);
});

it('does not render hidden field group', () => {
cy.get('#root_spec_hiddenFieldGroup_field-group').should('not.exist');
});

it('successfully creates operand using form', () => {
cy.byTestID('create-dynamic-form').click();
cy.byTestOperandLink('olm-descriptors-test')
.should('exist')
.click();
cy.get('.co-operand-details__section--info').should('exist');
});
});

0 comments on commit a21200f

Please sign in to comment.