From 7b89a85fea6178da0e387ffdc7b392e0fe8eafeb Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Mon, 9 Dec 2024 15:09:12 +0000 Subject: [PATCH] More e2e fixes --- .../e2e/po/components/namespace-filter.po.ts | 5 +++ .../po/pages/explorer/cluster-dashboard.po.ts | 36 ++++++++++++++++++- .../api/custom-resource-definitions.spec.ts | 10 ++++-- .../pages/explorer2/workloads/pods.spec.ts | 9 +---- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/po/components/namespace-filter.po.ts b/cypress/e2e/po/components/namespace-filter.po.ts index cd9f5dfb67b..f56b8570d4a 100644 --- a/cypress/e2e/po/components/namespace-filter.po.ts +++ b/cypress/e2e/po/components/namespace-filter.po.ts @@ -1,4 +1,5 @@ import ComponentPo from '@/cypress/e2e/po/components/component.po'; + export class NamespaceFilterPo extends ComponentPo { constructor() { super('[data-testid="namespaces-filter"]'); @@ -52,6 +53,10 @@ export class NamespaceFilterPo extends ComponentPo { return this.namespaceDropdown().find('[data-testid="namespaces-values"]'); } + allSelected() { + return this.self().find('[data-testid="namespaces-values-none"]').should('exist'); + } + moreOptionsSelected() { return this.namespaceDropdown().find('.ns-more'); } diff --git a/cypress/e2e/po/pages/explorer/cluster-dashboard.po.ts b/cypress/e2e/po/pages/explorer/cluster-dashboard.po.ts index 3f1daaf5eaf..243bfc22994 100644 --- a/cypress/e2e/po/pages/explorer/cluster-dashboard.po.ts +++ b/cypress/e2e/po/pages/explorer/cluster-dashboard.po.ts @@ -4,7 +4,8 @@ import CustomBadgeDialogPo from '@/cypress/e2e/po/components/custom-badge-dialog import EventsListPo from '@/cypress/e2e/po/lists/events-list.po'; import TabbedPo from '@/cypress/e2e/po/components/tabbed.po'; import CertificatesPo from '@/cypress/e2e/po/components/certificates.po'; -import { HeaderPo } from '~/cypress/e2e/po/components/header.po'; +import { HeaderPo } from '@/cypress/e2e/po/components/header.po'; +import { NamespaceFilterPo } from '@/cypress/e2e/po/components/namespace-filter.po'; export default class ClusterDashboardPagePo extends PagePo { private static createPath(clusterId: string) { @@ -82,4 +83,37 @@ export default class ClusterDashboardPagePo extends PagePo { controllerManagerStatus() { return cy.get('[data-testid="k8s-service-controller-manager"]'); } + + /** + * Confirm that the ns filter is set correctly before navigating to a page that will use it + * 1. nav to cluster dashboard + * 2. check ns filter values + */ + static goToAndConfirmNsValues(cluster: string, { + nsProject, + all + }: { + nsProject?: { + values: string[] + }, + all?: { + is: boolean, + } + }) { + const instance = new ClusterDashboardPagePo(cluster); + const nsfilter = new NamespaceFilterPo(); + + instance.goTo(cluster); + instance.waitForPage(); + + if (nsProject) { + for (let i = 0; i < nsProject.values.length; i++) { + nsfilter.selectedValues().contains(nsProject.values[i]); + } + } else if (all) { + nsfilter.allSelected(); + } else { + throw new Error('Bad Config'); + } + } } diff --git a/cypress/e2e/tests/pages/explorer/more-resources/api/custom-resource-definitions.spec.ts b/cypress/e2e/tests/pages/explorer/more-resources/api/custom-resource-definitions.spec.ts index c3da910c863..a7f067c819a 100644 --- a/cypress/e2e/tests/pages/explorer/more-resources/api/custom-resource-definitions.spec.ts +++ b/cypress/e2e/tests/pages/explorer/more-resources/api/custom-resource-definitions.spec.ts @@ -2,8 +2,10 @@ import { CustomResourceDefinitionsPagePo } from '@/cypress/e2e/po/pages/explorer import { generateCrdsDataSmall } from '@/cypress/e2e/blueprints/explorer/more-resources/api/custom-resource-definition-get'; import * as jsyaml from 'js-yaml'; import HomePagePo from '@/cypress/e2e/po/pages/home.po'; +import ClusterDashboardPagePo from '@/cypress/e2e/po/pages/explorer/cluster-dashboard.po'; -const crdsPage = new CustomResourceDefinitionsPagePo('local'); +const cluster = 'local'; +const crdsPage = new CustomResourceDefinitionsPagePo(cluster); const crdName = `e2etests.${ +new Date() }.example.com`; const crdGroup = `${ +new Date() }.example.com`; @@ -14,11 +16,13 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer' describe('List', { tags: ['@vai', '@adminUser'] }, () => { before(() => { - cy.tableRowsPerPageAndNamespaceFilter(10, 'local', 'none', '{\"local\":[]}'); + cy.tableRowsPerPageAndNamespaceFilter(10, cluster, 'none', '{\"local\":[]}'); }); it('can create a crd and see it in list view', () => { - crdsPage.goTo(); + ClusterDashboardPagePo.goToAndConfirmNsValues(cluster, { all: { is: true } } ); + + CustomResourceDefinitionsPagePo.navTo(); crdsPage.waitForPage(); crdsPage.create(); diff --git a/cypress/e2e/tests/pages/explorer2/workloads/pods.spec.ts b/cypress/e2e/tests/pages/explorer2/workloads/pods.spec.ts index 77ddf167ef6..348c9a1c072 100644 --- a/cypress/e2e/tests/pages/explorer2/workloads/pods.spec.ts +++ b/cypress/e2e/tests/pages/explorer2/workloads/pods.spec.ts @@ -6,15 +6,12 @@ import PodPo from '@/cypress/e2e/po/components/workloads/pod.po'; import HomePagePo from '@/cypress/e2e/po/pages/home.po'; import { generatePodsDataSmall } from '@/cypress/e2e/blueprints/explorer/workloads/pods/pods-get'; import SortableTablePo from '@/cypress/e2e/po/components/sortable-table.po'; -import { NamespaceFilterPo } from '@/cypress/e2e/po/components/namespace-filter.po'; import ClusterDashboardPagePo from '@/cypress/e2e/po/pages/explorer/cluster-dashboard.po'; const cluster = 'local'; describe('Pods', { testIsolation: 'off', tags: ['@explorer2', '@adminUser'] }, () => { const workloadsPodPage = new WorkloadsPodsListPagePo(cluster); - const clusterDashboard = new ClusterDashboardPagePo(cluster); - const nsFilter = new NamespaceFilterPo(); before(() => { cy.login(); @@ -67,11 +64,7 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer2', '@adminUser'] }, ( }); it('pagination is visible and user is able to navigate through pods data', () => { - // Confirm that the ns filter is set correctly before navigating to a page that will use it - clusterDashboard.goTo(); - clusterDashboard.waitForPage(); - nsFilter.selectedValues().contains(nsName1); - nsFilter.selectedValues().contains(nsName2); + ClusterDashboardPagePo.goToAndConfirmNsValues(cluster, { nsProject: { values: [nsName1, nsName2] } }); WorkloadsPodsListPagePo.navTo(); workloadsPodPage.waitForPage();