From ec45e2faa0d6e0d7ea9da1aaa9be1d7dab4a9523 Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Wed, 22 Apr 2020 13:46:49 +0000 Subject: [PATCH] mgr/dashboard: E2E: Add navigateEdit method This method should be use to navigate to the edit page. Signed-off-by: Tiago Melo --- .../cypress/integration/block/images.po.ts | 7 +------ .../integration/cluster/configuration.po.ts | 20 ++++--------------- .../integration/cluster/mgr-modules.po.ts | 13 +++++------- .../cypress/integration/page-helper.po.ts | 12 +++++++++++ .../cypress/integration/pools/pools.po.ts | 5 ++--- .../cypress/integration/rgw/buckets.po.ts | 16 +++++---------- .../cypress/integration/rgw/users.po.ts | 13 ++---------- .../cypress/integration/ui/role-mgmt.po.ts | 9 +++++++-- .../cypress/integration/ui/user-mgmt.po.ts | 3 +-- .../frontend/src/app/app-routing.module.ts | 2 +- 10 files changed, 40 insertions(+), 60 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/block/images.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/block/images.po.ts index f6cc1b9873917..c43b838e3f08e 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/block/images.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/block/images.po.ts @@ -27,12 +27,7 @@ export class ImagesPageHelper extends PageHelper { } editImage(name: string, pool: string, newName: string, newSize: string) { - const base_url = '#/block/rbd/edit/'; - const editURL = base_url - .concat(encodeURIComponent(pool)) - .concat('%2F') - .concat(encodeURIComponent(name)); - cy.visit(editURL); + this.navigateEdit(name); // Wait until data is loaded cy.get('#pool').should('contain.value', pool); diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/configuration.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/configuration.po.ts index 131ad2708a2a0..eb160b052e11f 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/configuration.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/configuration.po.ts @@ -10,17 +10,10 @@ export class ConfigurationPageHelper extends PageHelper { * Does not work for configs with checkbox only, possible future PR */ configClear(name: string) { - this.navigateTo(); const valList = ['global', 'mon', 'mgr', 'osd', 'mds', 'client']; // Editable values - // Enter config setting name into filter box - this.seachTable(name); - - // Selects config that we want to clear - this.getFirstTableCell(name).click(); // waits for config to be clickable and click - cy.contains('button', 'Edit').click(); // clicks button to edit - - // Wait for the data to load + this.navigateEdit(name); + // Waits for the data to load cy.contains('.card-header', `Edit ${name}`); for (const i of valList) { @@ -52,14 +45,9 @@ export class ConfigurationPageHelper extends PageHelper { * Ex: [global, '2'] is the global value with an input of 2 */ edit(name: string, ...values: [string, string][]) { + this.navigateEdit(name); - // Enter config setting name into filter box - this.seachTable(name); - - // Selects config that we want to edit - this.getFirstTableCell(name).click(); // waits for config to be clickable and click - cy.contains('button', 'Edit').click(); // clicks button to edit - + // Waits for data to load cy.contains('.card-header', `Edit ${name}`); values.forEach((valtuple) => { diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/mgr-modules.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/mgr-modules.po.ts index eaf93f9465fef..bee538e47c50d 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/mgr-modules.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/mgr-modules.po.ts @@ -9,8 +9,7 @@ export class ManagerModulesPageHelper extends PageHelper { * DOES NOT WORK FOR ALL MGR MODULES, for example, Device health */ editMgrModule(name: string, tuple: string[][]) { - this.getFirstTableCell(name).click(); - cy.contains('button', 'Edit').click(); + this.navigateEdit(name); for (const entry of tuple) { // Clears fields and adds edits @@ -25,8 +24,7 @@ export class ManagerModulesPageHelper extends PageHelper { } // Clear mgr module of all edits made to it - this.getFirstTableCell(name).click(); - cy.contains('button', 'Edit').click(); + this.navigateEdit(name); // Clears the editable fields for (const entry of tuple) { @@ -64,8 +62,7 @@ export class ManagerModulesPageHelper extends PageHelper { [warn, 'warn_threshold'] ]; - this.getFirstTableCell('devicehealth').click(); - cy.contains('button', 'Edit').click(); + this.navigateEdit('devicehealth'); for (let i = 0, devHealthTuple; (devHealthTuple = devHealthArray[i]); i++) { if (devHealthTuple[0] !== undefined) { // Clears and inputs edits @@ -89,8 +86,8 @@ export class ManagerModulesPageHelper extends PageHelper { // to be made when the values are cleared. Therefore, I restored them to their original values // (on my local run of ceph-dev, this is subject to change i would assume). // I'd imagine there is a better way of doing this. - this.getFirstTableCell('devicehealth').click(); - cy.contains('button', 'Edit').click(); + this.navigateEdit('devicehealth'); + cy.get('#mark_out_threshold').clear().type('2419200'); cy.get('#pool_name').clear().type('device_health_metrics'); diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/page-helper.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/page-helper.po.ts index cff33a7441371..2aaf901bd5300 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/page-helper.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/page-helper.po.ts @@ -49,6 +49,18 @@ export abstract class PageHelper { }); } + /** + * Navigates to the edit page + */ + navigateEdit(name: string, select = true) { + if (select) { + this.navigateTo(); + this.getFirstTableCell(name).click(); + } + cy.contains('button', 'Edit').click(); + this.expectBreadcrumbText('Edit'); + } + /** * Checks the active breadcrumb value. */ diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/pools/pools.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/pools/pools.po.ts index 24f4d4244bf85..31d1698ba1d96 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/pools/pools.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/pools/pools.po.ts @@ -36,9 +36,8 @@ export class PoolPageHelper extends PageHelper { edit_pool_pg(name: string, new_pg: number, wait = true) { this.isPowerOf2(new_pg); - this.getFirstTableCell(name).click(); // select pool from the table - cy.contains('button', 'Edit').click(); // click edit button - this.expectBreadcrumbText('Edit'); // verify we are now on edit page + this.navigateEdit(name); + cy.get('input[name=pgNum]').clear().type(`${new_pg}`); cy.get('cd-submit-button').click(); const str = `${new_pg} active+clean`; diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/buckets.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/buckets.po.ts index 7d1f6e55d065e..0cb1f76fef185 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/buckets.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/buckets.po.ts @@ -40,9 +40,8 @@ export class BucketsPageHelper extends PageHelper { @PageHelper.restrictTo(pages.index.url) edit(name: string, new_owner: string) { - this.getFirstTableCell(name).click(); // wait for table to load and click - cy.contains('button', 'Edit').click(); // click button to move to edit page - this.expectBreadcrumbText('Edit'); + this.navigateEdit(name); + cy.get('input[name=placement-target]').should('have.value', 'default-placement'); this.selectOwner(new_owner); @@ -69,8 +68,8 @@ export class BucketsPageHelper extends PageHelper { cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled); // Disable versioning: - cy.contains('button', 'Edit').click(); // click button to move to edit page - this.expectBreadcrumbText('Edit'); + this.navigateEdit(name, false); + cy.get('label[for=versioning]').click(); cy.get('input[id=versioning]').should('not.be.checked'); cy.contains('button', 'Edit Bucket').click(); @@ -134,12 +133,7 @@ export class BucketsPageHelper extends PageHelper { } testInvalidEdit(name: string) { - this.navigateTo(); - - this.getFirstTableCell(name).click(); // wait for table to load and click - cy.contains('button', 'Edit').click(); // click button to move to edit page - - this.expectBreadcrumbText('Edit'); + this.navigateEdit(name); cy.get('input[id=versioning]').should('exist').and('not.be.checked'); diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/users.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/users.po.ts index 66cff75dc289f..f65464537ac43 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/users.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/users.po.ts @@ -30,10 +30,7 @@ export class UsersPageHelper extends PageHelper { @PageHelper.restrictTo(pages.index.url) edit(name: string, new_fullname: string, new_email: string, new_maxbuckets: string) { - this.getFirstTableCell(name).click(); // wait for table to load and click - cy.contains('button', 'Edit').click(); // click button to move to edit page - - this.expectBreadcrumbText('Edit'); + this.navigateEdit(name); // Change the full name field cy.get('#display_name').click().clear().type(new_fullname); @@ -107,13 +104,7 @@ export class UsersPageHelper extends PageHelper { this.navigateTo('create'); this.create(uname, 'xxx', 'xxx@xxx', '1'); - this.navigateTo(); - - // wait for table to load and click on the bucket you want to edit in the table - this.getFirstTableCell(uname).click(); - cy.contains('button', 'Edit').click(); // click button to move to edit page - - this.expectBreadcrumbText('Edit'); + this.navigateEdit(name); // put invalid email to make field invalid cy.get('#email') diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/role-mgmt.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/role-mgmt.po.ts index b90da23738022..1f9c7616b8cb2 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/role-mgmt.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/role-mgmt.po.ts @@ -8,6 +8,8 @@ export class RoleMgmtPageHelper extends PageHelper { create(name: string, description: string) { this.navigateTo('create'); + // Waits for data to load + cy.contains('grafana'); // fill in fields cy.get('#name').type(name); @@ -15,19 +17,22 @@ export class RoleMgmtPageHelper extends PageHelper { // Click the create button and wait for role to be made cy.contains('button', 'Create Role').click(); + cy.get('.breadcrumb-item.active').should('not.have.text', name); this.getFirstTableCell(name).should('exist'); } edit(name: string, description: string) { - this.getFirstTableCell(name).click(); // select role from table - cy.contains('button', 'Edit').click(); // click button to move to edit page + this.navigateEdit(name); + // Waits for data to load + cy.contains('grafana'); // fill in fields with new values cy.get('#description').clear().type(description); // Click the edit button and check new values are present in table cy.contains('button', 'Edit Role').click(); + cy.get('.breadcrumb-item.active').should('not.have.text', name); this.getFirstTableCell(name).should('exist'); this.getFirstTableCell(description).should('exist'); diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/user-mgmt.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/user-mgmt.po.ts index 904cc6ed0bc10..5afcdf37ca528 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/user-mgmt.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/ui/user-mgmt.po.ts @@ -22,8 +22,7 @@ export class UserMgmtPageHelper extends PageHelper { } edit(username: string, password: string, name: string, email: string) { - this.getFirstTableCell(username).click(); // select user from table - cy.contains('button', 'Edit').click(); // click button to move to edit page + this.navigateEdit(username); // fill in fields with new values cy.get('#password').clear().type(password); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts index 99208d37c6fa6..cbdef74b61da2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts @@ -67,7 +67,7 @@ export class StartCaseBreadcrumbsResolver extends BreadcrumbsResolver { resolve(route: ActivatedRouteSnapshot) { const path = route.params.name; const text = _.startCase(path); - return [{ text: text, path: path }]; + return [{ text: `${text}/Edit`, path: path }]; } } -- 2.39.5