Skip to content

Commit

Permalink
Attempt to make pagination tests execution faster
Browse files Browse the repository at this point in the history
  • Loading branch information
izaac committed Aug 14, 2024
1 parent cb6adea commit 078b6c2
Show file tree
Hide file tree
Showing 10 changed files with 1,037 additions and 632 deletions.
775 changes: 581 additions & 194 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,11 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
});

describe('List', { tags: ['@vai', '@adminUser'] }, () => {
before(() => {
cy.tableRowsPerPage(10);
cy.reload();
});

it('can create a crd and see it in list view', () => {
crdsPage.goTo();
crdsPage.waitForPage();
Expand All @@ -33,6 +38,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 @@ -48,68 +54,6 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
});
});

it('pagination is visible and user is able to navigate through crd data', () => {
// get crd count
cy.getRancherResource('v1', 'apiextensions.k8s.io.customresourcedefinitions').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;

crdsPage.goTo(); // Remove any odd state from previous create (which can result in additional table row not from backend)
crdsPage.waitForPage();

// pagination is visible
crdsPage.sortableTable().pagination().checkVisible();

// basic checks on navigation buttons
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
crdsPage.sortableTable().pagination().rightButton().isEnabled();
crdsPage.sortableTable().pagination().endButton().isEnabled();

// check text before navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 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`);
});
crdsPage.sortableTable().pagination().beginningButton().isEnabled();
crdsPage.sortableTable().pagination().leftButton().isEnabled();

// navigate to first page - left button
crdsPage.sortableTable().pagination().leftButton().click();

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

// navigate to last page - end button
crdsPage.sortableTable().pagination().endButton().click();

// check text after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ 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`);
});
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
});
});

it('filter CRDs', () => {
CustomResourceDefinitionsPagePo.navTo();
crdsPage.waitForPage();
Expand All @@ -130,20 +74,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,15 +108,77 @@ 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();
crdsPage.sortableTable().checkRowCount(false, 2);
crdsPage.sortableTable().pagination().checkNotExists();
});

it('pagination is visible and user is able to navigate through crd data', () => {
// get crd count
cy.getRancherResource('v1', 'apiextensions.k8s.io.customresourcedefinitions').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;

crdsPage.goTo(); // Remove any odd state from previous create (which can result in additional table row not from backend)
crdsPage.waitForPage();

// pagination is visible
crdsPage.sortableTable().pagination().checkVisible();

// basic checks on navigation buttons
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
crdsPage.sortableTable().pagination().rightButton().isEnabled();
crdsPage.sortableTable().pagination().endButton().isEnabled();

// check text before navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
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(`11 - 20 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isEnabled();
crdsPage.sortableTable().pagination().leftButton().isEnabled();

// navigate to first page - left button
crdsPage.sortableTable().pagination().leftButton().click();

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

// navigate to last page - end button
crdsPage.sortableTable().pagination().endButton().click();

// check text after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
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 - 10 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
});
});

after('clean up', () => {
// delete crd
cy.deleteRancherResource('v1', 'apiextensions.k8s.io.customresourcedefinitions', crdName);
Expand Down
68 changes: 39 additions & 29 deletions cypress/e2e/tests/pages/explorer/workloads/pods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,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,14 +47,22 @@ 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');
});
cy.tableRowsPerPage(10);
cy.reload(true);
// The pods count returned just before the assertions are out of sync with the created pods during the setup
// Waiting seems to mitigate this sync issue. This behavior seems consistent/reproducible on HA Rancher
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(30000);
});

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;
// get the generated test data for the 'Only User Namespaces' UI filter
const namespacesFilter = /(e2e-test-\d{13}-ns\d|default)/;
const count = resp.body.data.filter((item: { metadata: { namespace: string; }; }) => namespacesFilter.test(item.metadata.namespace)).length;

WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
Expand All @@ -70,15 +78,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 +96,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 +106,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(`21 - ${ 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 +147,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 Down
Loading

0 comments on commit 078b6c2

Please sign in to comment.