Skip to content

Commit

Permalink
Adding CIS chart UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izaac committed Jan 29, 2025
1 parent c987984 commit a76221d
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cypress/e2e/po/other-products/cis-benchmark-list.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import BaseResourceList from '@/cypress/e2e/po/lists/base-resource-list.po';

export default class CisBenchmarkListPo extends BaseResourceList {
openBulkActionDropdown() {
return this.resourceTable().sortableTable().bulkActionDropDownOpen();
}

bulkActionButton(name: string) {
return this.resourceTable().sortableTable().bulkActionDropDownButton(name);
}

details(name: string, index: number) {
return this.resourceTable().sortableTable().rowWithName(name).column(index);
}
}
45 changes: 45 additions & 0 deletions cypress/e2e/po/other-products/cis-benchmark.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import PagePo from '@/cypress/e2e/po/pages/page.po';
import ResourceTablePo from '@/cypress/e2e/po/components/resource-table.po';
import CodeMirrorPo from '@/cypress/e2e/po/components/code-mirror.po';
import CisBenchmarkListPo from '@/cypress/e2e/po/other-products/cis-benchmark-list.po';
import ResourceDetailPo from '@/cypress/e2e/po/edit/resource-detail.po';

export default class CisBenchmarkPo extends PagePo {
static createPath(clusterId: string) {
return `/c/${ clusterId }/cis/cis.cattle.io.clusterscan/create`;
}

static goTo(clusterId: string): Cypress.Chainable<Cypress.AUTWindow> {
return super.goTo(CisBenchmarkPo.createPath(clusterId));
}

constructor(clusterId = 'local') {
super(CisBenchmarkPo.createPath(clusterId));
}

create(): Cypress.Chainable {
return this.list().masthead().actions().contains('Create');
}

createFromYaml(): Cypress.Chainable {
return this.list().masthead().actions().contains('Create from YAML');
}

goToDetailsPage(elemName: string) {
const resourceTable = new ResourceTablePo(this.self());

return resourceTable.sortableTable().detailsPageLinkWithName(elemName).click();
}

list(): CisBenchmarkListPo {
return new CisBenchmarkListPo('[data-testid="sortable-table-list-container"]');
}

resourceDetail() {
return new ResourceDetailPo(this.self())

Check warning on line 39 in cypress/e2e/po/other-products/cis-benchmark.po.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
}

yamlEditor(): CodeMirrorPo {
return CodeMirrorPo.bySelector(this.self(), '[data-testid="yaml-editor-code-mirror"]');
}
}
93 changes: 93 additions & 0 deletions cypress/e2e/tests/pages/charts/cis-benchmark.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { ChartPage } from '@/cypress/e2e/po/pages/explorer/charts/chart.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import { InstallChartPage } from '@/cypress/e2e/po/pages/explorer/charts/install-charts.po';
import ProductNavPo from '@/cypress/e2e/po/side-bars/product-side-nav.po';
import { MEDIUM_TIMEOUT_OPT, LONG_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';
import Kubectl from '@/cypress/e2e/po/components/kubectl.po';
import CisBenchmarkPo from '@/cypress/e2e/po/other-products/cis-benchmark.po';

describe('Charts', { testIsolation: 'off', tags: ['@charts', '@adminUser'] }, () => {
before(() => {
cy.login();
HomePagePo.goTo();
});

describe('CIS Benchmark install', () => {
const installChartPage = new InstallChartPage();
const chartPage = new ChartPage();

describe('YAML view', () => {
beforeEach(() => {
ChartPage.navTo(null, 'CIS Benchmark');
chartPage.waitForChartHeader('CIS Benchmark', MEDIUM_TIMEOUT_OPT);
chartPage.goToInstall();
installChartPage.nextPage().editYaml();
});

describe('UI Elements', () => {
it('Footer controls should sticky to bottom', () => {
cy.get('#wizard-footer-controls').should('be.visible');

cy.get('#wizard-footer-controls').then(($el) => {
const elementRect = $el[0].getBoundingClientRect();
const viewportHeight = Cypress.config('viewportHeight');
const pageHeight = Cypress.$(cy.state('window')).height();

expect(elementRect.bottom).to.eq(pageHeight);
expect(elementRect.bottom).to.eq(viewportHeight);
});
});
});
});

describe('CIS Chart setup', () => {
it('Complete install and a Scan is created', () => {
cy.updateNamespaceFilter('local', 'none', '{"local":[]}');
const kubectl = new Kubectl();
const sideNav = new ProductNavPo();
const cisBenchmark = new CisBenchmarkPo();

ChartPage.navTo(null, 'CIS Benchmark');
chartPage.waitForChartHeader('CIS Benchmark', MEDIUM_TIMEOUT_OPT);
chartPage.goToInstall();

installChartPage.nextPage();

cy.intercept('POST', 'v1/catalog.cattle.io.clusterrepos/rancher-charts?action=install').as('chartInstall');
installChartPage.installChart();
cy.wait('@chartInstall').its('response.statusCode').should('eq', 201);
cy.contains('Disconnected');

kubectl.closeTerminal();

sideNav.navToSideMenuGroupByLabel('CIS Benchmark');
sideNav.navToSideMenuEntryByLabel('Scan');

cisBenchmark.create().click();
cisBenchmark.waitForPage();
cisBenchmark.resourceDetail().cruResource().saveAndWaitForRequests('POST', 'v1/cis.cattle.io.clusterscans')
.then(({ response }) => {
expect(response?.statusCode).to.eq(201);
expect(response?.body).to.have.property('type', 'cis.cattle.io.clusterscan');
expect(response?.body.metadata).to.have.property('name');
expect(response?.body.metadata).to.have.property('generateName', 'scan-');
});
cisBenchmark.list().checkVisible();
const column = cisBenchmark.list().resourceTable().sortableTable().row(0)
.column(1);

column.get('.bg-success', LONG_TIMEOUT_OPT).should('exist');
});

after('clean up', () => {
const chartNamespace = 'cis-operator-system';
const chartApp = 'rancher-cis-benchmark';
const chartCrd = 'rancher-cis-benchmark-crd';

cy.createRancherResource('v1', `catalog.cattle.io.apps/${ chartNamespace }/${ chartApp }?action=uninstall`, '{}');
cy.createRancherResource('v1', `catalog.cattle.io.apps/${ chartNamespace }/${ chartCrd }?action=uninstall`, '{}');
cy.updateNamespaceFilter('local', 'none', '{"local":["all://user"]}');
});
});
});
});

0 comments on commit a76221d

Please sign in to comment.