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 6eaaa6a commit 784237f
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
19 changes: 19 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,19 @@
import BaseResourceList from '@/cypress/e2e/po/lists/base-resource-list.po';

export default class CisBenchmarkListPo extends BaseResourceList {
clickCreate() {
return cy.get('[data-testid="masthead-create"]').click();
}

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);
}
}
48 changes: 48 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,48 @@
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';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import ProductNavPo from '@/cypress/e2e/po/side-bars/product-side-nav.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));
}

static navTo(clusterId = 'local') {
const burgerMenu = new BurgerMenuPo();
const sideNav = new ProductNavPo();

burgerMenu.goToCluster(clusterId);
sideNav.navToSideMenuGroupByLabel('CIS Benchmark');
sideNav.navToSideMenuEntryByLabel('Scan');
}

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

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());
}

yamlEditor(): CodeMirrorPo {
return CodeMirrorPo.bySelector(this.self(), '[data-testid="yaml-editor-code-mirror"]');
}
}
89 changes: 89 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,89 @@
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 { 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 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();

CisBenchmarkPo.navTo();
cisBenchmark.list().clickCreate();
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 784237f

Please sign in to comment.