Skip to content

Commit

Permalink
Merge pull request #11587 from izaac/pagination_updates
Browse files Browse the repository at this point in the history
[Automation] - Reduce execution time of pagination tests
  • Loading branch information
izaac authored Aug 22, 2024
2 parents 3919017 + 92fc735 commit 866c642
Show file tree
Hide file tree
Showing 10 changed files with 850 additions and 396 deletions.
773 changes: 580 additions & 193 deletions cypress/e2e/blueprints/explorer/workloads/pods/pods-get.ts

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions cypress/e2e/po/pages/users-and-auth/roles.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import RoleListPo from '@/cypress/e2e/po/lists/role-list.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';
import ClusterPage from '@/cypress/e2e/po/pages/cluster-page.po';
import PaginationPo from '~/cypress/e2e/po/components/pagination.po';

export default class RolesPo extends ClusterPage {
static goTo(path: string): Cypress.Chainable<Cypress.AUTWindow> {
Expand Down Expand Up @@ -63,4 +64,8 @@ export default class RolesPo extends ClusterPage {
list(tabIdSelector: 'GLOBAL' | 'CLUSTER' | 'NAMESPACE') {
return new RoleListPo(`#${ tabIdSelector } [data-testid="sortable-table-list-container"]`);
}

paginatedTab(tabIdSelector: 'GLOBAL' | 'CLUSTER' | 'NAMESPACE') {
return new PaginationPo(`#${ tabIdSelector } div.paging`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
});

describe('List', { tags: ['@vai', '@adminUser'] }, () => {
before(() => {
cy.tableRowsPerPageAndNamespaceFilter(10, 'local', 'none', '{\"local\":[]}');
});

it('can create a crd and see it in list view', () => {
crdsPage.goTo();
crdsPage.waitForPage();
Expand All @@ -33,6 +37,7 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
.click();
cy.wait('@createCRD').its('response.statusCode').should('eq', 201);
crdsPage.waitForPage();
crdsPage.sortableTable().filter(crdName);
crdsPage.sortableTable().rowWithName(crdName)
.column(1)
.scrollIntoView()
Expand All @@ -46,9 +51,11 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
.each((el, i) => {
expect(el.text().trim()).to.eq(expectedHeaders[i]);
});
crdsPage.sortableTable().filter('{selectAll}{del}');
});

it('pagination is visible and user is able to navigate through crd data', () => {
HomePagePo.goTo();
// get crd count
cy.getRancherResource('v1', 'apiextensions.k8s.io.customresourcedefinitions').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;
Expand All @@ -67,15 +74,15 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'

// check text before navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } CustomResourceDefinitions`);
});

// navigate to next page - right button
crdsPage.sortableTable().pagination().rightButton().click();

// check text and buttons after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`11 - 20 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isEnabled();
crdsPage.sortableTable().pagination().leftButton().isEnabled();
Expand All @@ -85,7 +92,7 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'

// check text and buttons after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -95,15 +102,15 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'

// check text after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.contain(`${ count - (count % 10) + 1 } - ${ count } of ${ count } CustomResourceDefinitions`);
});

// navigate to first page - beginning button
crdsPage.sortableTable().pagination().beginningButton().click();

// check text and buttons after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -130,20 +137,21 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
crdsPage.waitForPage();
crdsPage.sortableTable().checkVisible();
crdsPage.sortableTable().checkNoRowsNotVisible();
crdsPage.sortableTable().filter('apps');

let indexBeforeSort: number;

crdsPage.sortableTable().rowNames().then((rows) => {
const sortedRows = rows.sort();

indexBeforeSort = sortedRows.indexOf(crdName);
indexBeforeSort = sortedRows.indexOf('apps.catalog.cattle.io');
});

// check table is sorted by `name` in ASC order by default
crdsPage.sortableTable().tableHeaderRow().checkSortOrder(2, 'down');

// crd name should be visible on first page (sorted in ASC order)
crdsPage.sortableTable().rowElementWithPartialName(crdName).scrollIntoView().should('be.visible');
crdsPage.sortableTable().rowElementWithPartialName('apps.catalog.cattle.io').scrollIntoView().should('be.visible');

// sort by name in DESC order
crdsPage.sortableTable().sort(2).click();
Expand All @@ -163,8 +171,8 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
generateCrdsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
CustomResourceDefinitionsPagePo.navTo();
crdsPage.waitForPage();
cy.wait('@crdsDataSmall');
crdsPage.waitForPage();

crdsPage.sortableTable().checkVisible();
crdsPage.sortableTable().checkLoadingIndicatorNotVisible();
Expand Down
73 changes: 40 additions & 33 deletions cypress/e2e/tests/pages/explorer/workloads/pods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
const podNamesList = [];
let nsName1: string;
let nsName2: string;
let initialCount: number;

before('set up', () => {
cy.updateNamespaceFilter('local', 'none', '{\"local\":[]}');
cy.tableRowsPerPageAndNamespaceFilter(10, 'local', 'none', '{\"local\":[]}');
cy.getRancherResource('v1', 'pods').then((resp: Cypress.Response<any>) => {
initialCount = resp.body.count;
});

cy.createE2EResourceName('ns1').then((ns1) => {
nsName1 = ns1;
Expand All @@ -29,10 +33,10 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
// create pods
let i = 0;

while (i < 100) {
while (i < 25) {
const podName = `e2e-${ Cypress._.uniqueId(Date.now().toString()) }`;

cy.createPod(nsName1, podName, 'nginx:latest', false).then(() => {
cy.createPod(nsName1, podName, 'nginx:alpine', false).then(() => {
podNamesList.push(`pod-${ podName }`);
});

Expand All @@ -47,15 +51,15 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
cy.createNamespace(nsName2);

// create unique pod for filtering/sorting test
cy.createPod(nsName2, uniquePod, 'nginx:latest');
cy.createPod(nsName2, uniquePod, 'nginx:alpine');
});
});

it('pagination is visible and user is able to navigate through pods data', () => {
// get pods count
cy.getRancherResource('v1', 'pods').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;
// check pods count
const count = initialCount + 26;

cy.waitForRancherResources('v1', 'pods', count).then((resp: Cypress.Response<any>) => {
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();

Expand All @@ -70,15 +74,15 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()

// check text before navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Pods`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});

// navigate to next page - right button
workloadsPodPage.sortableTable().pagination().rightButton().click();

// check text and buttons after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } Pods`);
expect(el.trim()).to.eq(`11 - 20 of ${ count } Pods`);
});
workloadsPodPage.sortableTable().pagination().beginningButton().isEnabled();
workloadsPodPage.sortableTable().pagination().leftButton().isEnabled();
Expand All @@ -88,7 +92,7 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()

// check text and buttons after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Pods`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
workloadsPodPage.sortableTable().pagination().beginningButton().isDisabled();
workloadsPodPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -98,43 +102,26 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()

// check text after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } Pods`);
expect(el.trim()).to.eq(`${ count - (count % 10) + 1 } - ${ count } of ${ count } Pods`);
});

// navigate to first page - beginning button
workloadsPodPage.sortableTable().pagination().beginningButton().click();

// check text and buttons after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Pods`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
workloadsPodPage.sortableTable().pagination().beginningButton().isDisabled();
workloadsPodPage.sortableTable().pagination().leftButton().isDisabled();
});
});

it('filter pods', () => {
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();

workloadsPodPage.sortableTable().checkVisible();
workloadsPodPage.sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.sortableTable().checkRowCount(false, 100);

// filter by name
workloadsPodPage.sortableTable().filter(podNamesList[0]);
workloadsPodPage.sortableTable().checkRowCount(false, 1);
workloadsPodPage.sortableTable().rowElementWithName(podNamesList[0]).should('be.visible');

// filter by namespace
workloadsPodPage.sortableTable().filter(nsName2);
workloadsPodPage.sortableTable().checkRowCount(false, 1);
workloadsPodPage.sortableTable().rowElementWithName(`pod-${ uniquePod }`).should('be.visible');
});

it('sorting changes the order of paginated pods data', () => {
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
// use filter to only show test data
workloadsPodPage.sortableTable().filter('e2e-');

// check table is sorted by name in ASC order by default
workloadsPodPage.sortableTable().tableHeaderRow().checkSortOrder(2, 'down');
Expand All @@ -156,13 +143,32 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
workloadsPodPage.sortableTable().rowElementWithName(podNamesList[0]).scrollIntoView().should('be.visible');
});

it('filter pods', () => {
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();

workloadsPodPage.sortableTable().checkVisible();
workloadsPodPage.sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.sortableTable().checkRowCount(false, 10);

// filter by name
workloadsPodPage.sortableTable().filter(podNamesList[0]);
workloadsPodPage.sortableTable().checkRowCount(false, 1);
workloadsPodPage.sortableTable().rowElementWithName(podNamesList[0]).should('be.visible');

// filter by namespace
workloadsPodPage.sortableTable().filter(nsName2);
workloadsPodPage.sortableTable().checkRowCount(false, 1);
workloadsPodPage.sortableTable().rowElementWithName(`pod-${ uniquePod }`).should('be.visible');
});

it('pagination is hidden', () => {
// generate small set of pods data
generatePodsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
cy.wait('@podsDataSmall');
workloadsPodPage.waitForPage();

workloadsPodPage.sortableTable().checkVisible();
workloadsPodPage.sortableTable().checkLoadingIndicatorNotVisible();
Expand All @@ -171,7 +177,8 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
});

after('clean up', () => {
cy.updateNamespaceFilter('local', 'none', '{"local":["all://user"]}');
// Ensure the default rows per page value is set after running the tests
cy.tableRowsPerPageAndNamespaceFilter(100, 'local', 'none', '{"local":["all://user"]}');

// delete namespace (this will also delete all pods in it)
cy.deleteRancherResource('v1', 'namespaces', nsName1);
Expand Down
Loading

0 comments on commit 866c642

Please sign in to comment.