From cee3c694e84aa2fab0820998d8d750edb640f8c8 Mon Sep 17 00:00:00 2001 From: Patrick Seidensal Date: Mon, 19 Aug 2019 14:05:09 +0200 Subject: [PATCH] mgr/dashboard: migrate E2E mirroring to async/await Fixes: https://tracker.ceph.com/issues/40693 Signed-off-by: Patrick Seidensal --- .../frontend/e2e/block/mirroring.e2e-spec.ts | 67 +++++++++--------- .../frontend/e2e/block/mirroring.po.ts | 54 ++++++--------- .../mgr/dashboard/frontend/e2e/helper.po.ts | 3 + .../dashboard/frontend/e2e/pools/pools.po.ts | 69 ++++++++----------- 4 files changed, 86 insertions(+), 107 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.e2e-spec.ts b/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.e2e-spec.ts index 9b1695517dd7b..091537518d553 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.e2e-spec.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.e2e-spec.ts @@ -9,57 +9,58 @@ describe('Mirroring page', () => { pools = new Helper().pools; }); - afterEach(() => { - Helper.checkConsole(); + afterEach(async () => { + await Helper.checkConsole(); }); describe('breadcrumb and tab tests', () => { - beforeAll(() => { - mirroring.navigateTo(); + beforeAll(async () => { + await mirroring.navigateTo(); }); - it('should open and show breadcrumb', () => { - expect(mirroring.getBreadcrumbText()).toEqual('Mirroring'); + it('should open and show breadcrumb', async () => { + expect(await mirroring.getBreadcrumbText()).toEqual('Mirroring'); }); - it('should show three tabs', () => { - expect(mirroring.getTabsCount()).toEqual(3); + it('should show three tabs', async () => { + expect(await mirroring.getTabsCount()).toEqual(3); }); - it('should show text for all tabs', () => { - expect(mirroring.getTabText(0)).toEqual('Issues'); - expect(mirroring.getTabText(1)).toEqual('Syncing'); - expect(mirroring.getTabText(2)).toEqual('Ready'); + it('should show text for all tabs', async () => { + expect(await mirroring.getTabText(0)).toEqual('Issues'); + expect(await mirroring.getTabText(1)).toEqual('Syncing'); + expect(await mirroring.getTabText(2)).toEqual('Ready'); }); }); - describe('checks that edit mode functionality shows in the pools table', () => { + describe('checks that edit mode functionality shows in the pools table', async () => { const poolName = 'mirrorpoolrq'; - beforeAll(() => { - pools.navigateTo('create'); // Need pool for mirroring testing - pools.create(poolName, 8, 'rbd').then(() => { - pools.navigateTo(); - pools.exist(poolName, true); - }); + beforeAll(async () => { + await pools.navigateTo('create'); // Need pool for mirroring testing + await pools.create(poolName, 8, 'rbd'); + // console.log(`before second navigateTo()`); + await pools.navigateTo(); + // console.log(`before pools.exist(${poolName})`); + await pools.exist(poolName, true); + // console.log(`beforeAll done`); }); - it('tests editing mode for pools', () => { - mirroring.navigateTo(); - expect(mirroring.editMirror(poolName, 'Pool')); - expect(mirroring.getFirstTableCellWithText('pool').isPresent()).toBe(true); - expect(mirroring.editMirror(poolName, 'Image')); - expect(mirroring.getFirstTableCellWithText('image').isPresent()).toBe(true); - expect(mirroring.editMirror(poolName, 'Disabled')); - expect(mirroring.getFirstTableCellWithText('disabled').isPresent()).toBe(true); + it('tests editing mode for pools', async () => { + await mirroring.navigateTo(); + expect(await mirroring.editMirror(poolName, 'Pool')); + expect(await mirroring.getFirstTableCellWithText('pool').isPresent()).toBe(true); + expect(await mirroring.editMirror(poolName, 'Image')); + expect(await mirroring.getFirstTableCellWithText('image').isPresent()).toBe(true); + expect(await mirroring.editMirror(poolName, 'Disabled')); + expect(await mirroring.getFirstTableCellWithText('disabled').isPresent()).toBe(true); }); - afterAll(() => { - pools.navigateTo(); // Deletes mirroring test pool - pools.delete(poolName).then(() => { - pools.navigateTo(); - pools.exist(poolName, false); - }); + afterAll(async () => { + await pools.navigateTo(); // Deletes mirroring test pool + await pools.delete(poolName); + await pools.navigateTo(); + await pools.exist(poolName, false); }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts index b9d778044589f..a95fa4225866a 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts @@ -7,44 +7,32 @@ export class MirroringPageHelper extends PageHelper { // Goes to the mirroring page and edits a pool in the Pool table. Clicks on the // pool and chooses a option (either pool, image, or disabled) - editMirror(name, option) { - this.navigateTo(); + async editMirror(name, option) { // Clicks the pool in the table - browser - .wait(Helper.EC.elementToBeClickable(this.getFirstTableCellWithText(name)), Helper.TIMEOUT) - .then(() => { - this.getFirstTableCellWithText(name).click(); - }); + await browser.wait( + Helper.EC.elementToBeClickable(this.getFirstTableCellWithText(name)), + Helper.TIMEOUT + ); + await this.getFirstTableCellWithText(name).click(); // Clicks the Edit Mode button const editModeButton = element(by.cssContainingText('button', 'Edit Mode')); - browser.wait(Helper.EC.elementToBeClickable(editModeButton), Helper.TIMEOUT).then(() => { - editModeButton.click(); - }); + await browser.wait(Helper.EC.elementToBeClickable(editModeButton), Helper.TIMEOUT); + await editModeButton.click(); // Clicks the drop down in the edit pop-up, then clicks the Update button - browser.wait(Helper.EC.visibilityOf($('.modal-content')), Helper.TIMEOUT).then(() => { - const mirrorDrop = element(by.id('mirrorMode')); - this.moveClick(mirrorDrop); - element(by.cssContainingText('select[name=mirrorMode] option', option)).click(); - }); + await browser.wait(Helper.EC.visibilityOf($('.modal-content')), Helper.TIMEOUT); + await element(by.id('mirrorMode')).click(); // Mode select box + await element(by.cssContainingText('select[name=mirrorMode] option', option)).click(); + // Clicks update button and checks if the mode has been changed - element(by.cssContainingText('button', 'Update')) - .click() - .then(() => { - browser - .wait( - Helper.EC.stalenessOf( - element(by.cssContainingText('.modal-dialog', 'Edit pool mirror mode')) - ), - Helper.TIMEOUT - ) - .then(() => { - const val = option.toLowerCase(); // used since entries in table are lower case - browser.wait( - Helper.EC.visibilityOf(this.getFirstTableCellWithText(val)), - Helper.TIMEOUT - ); - }); - }); + await element(by.cssContainingText('button', 'Update')).click(); + await browser.wait( + Helper.EC.stalenessOf( + element(by.cssContainingText('.modal-dialog', 'Edit pool mirror mode')) + ), + Helper.TIMEOUT + ); + const val = option.toLowerCase(); // used since entries in table are lower case + await browser.wait(Helper.EC.visibilityOf(this.getFirstTableCellWithText(val)), Helper.TIMEOUT); } } diff --git a/src/pybind/mgr/dashboard/frontend/e2e/helper.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/helper.po.ts index de4165247a73a..6ca09022f418f 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/helper.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/helper.po.ts @@ -1,5 +1,6 @@ import { browser } from 'protractor'; import { ImagesPageHelper } from './block/images.po'; +import { MirroringPageHelper } from './block/mirroring.po'; import { AlertsPageHelper } from './cluster/alerts.po'; import { ConfigurationPageHelper } from './cluster/configuration.po'; import { CrushMapPageHelper } from './cluster/crush-map.po'; @@ -39,6 +40,7 @@ export class Helper { crushMap: CrushMapPageHelper; configuration: ConfigurationPageHelper; alerts: AlertsPageHelper; + mirroring: MirroringPageHelper; constructor() { this.pools = new PoolPageHelper(); @@ -60,6 +62,7 @@ export class Helper { this.crushMap = new CrushMapPageHelper(); this.configuration = new ConfigurationPageHelper(); this.alerts = new AlertsPageHelper(); + this.mirroring = new MirroringPageHelper(); } /** diff --git a/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts index 022e667a61389..95b437eff5a9a 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts @@ -49,60 +49,47 @@ export class PoolPageHelper extends PageHelper { protractor.Key.NULL, placement_groups ); - this.setApplications(apps); + await this.setApplications(apps); await element(by.css('cd-submit-button')).click(); return Promise.resolve(); } - edit_pool_pg(name: string, new_pg: number): promise.Promise { + async edit_pool_pg(name: string, new_pg: number): Promise { if (!this.isPowerOf2(new_pg)) { return Promise.reject(`Placement groups ${new_pg} are not a power of 2`); } - return this.getTableCellByContent(name).then((elem) => { - elem.click(); // select pool from the table - element(by.cssContainingText('button', 'Edit')).click(); // click edit button - expect(this.getBreadcrumbText()).toEqual('Edit'); // verify we are now on edit page - $('input[name=pgNum]') - .sendKeys(protractor.Key.CONTROL, 'a', protractor.Key.NULL, new_pg) - .then(() => { - element(by.css('cd-submit-button')).click(); - const str = `${new_pg} active+clean`; - browser - .wait( - EC.visibilityOf(this.getTableRow(name)), - Helper.TIMEOUT, - 'Timed out waiting for table row to load' - ) - .then(() => { - return browser.wait( - EC.textToBePresentInElement(this.getTableRow(name), str), - Helper.TIMEOUT, - 'Timed out waiting for placement group to be updated' - ); - }); - }); - }); + const elem = await this.getTableCellByContent(name); + await elem.click(); // select pool from the table + await element(by.cssContainingText('button', 'Edit')).click(); // click edit button + expect(await this.getBreadcrumbText()).toEqual('Edit'); // verify we are now on edit page + await $('input[name=pgNum]').sendKeys(protractor.Key.CONTROL, 'a', protractor.Key.NULL, new_pg); + await element(by.css('cd-submit-button')).click(); + const str = `${new_pg} active+clean`; + await browser.wait( + EC.visibilityOf(this.getTableRow(name)), + Helper.TIMEOUT, + 'Timed out waiting for table row to load' + ); + await browser.wait( + EC.textToBePresentInElement(this.getTableRow(name), str), + Helper.TIMEOUT, + 'Timed out waiting for placement group to be updated' + ); } - private setApplications(apps: string[]) { + private async setApplications(apps: string[]) { if (!apps || apps.length === 0) { return; } - element(by.css('.float-left.mr-2.select-menu-edit')) - .click() - .then(() => { - browser - .wait( - Helper.EC.visibilityOf(element(by.css('.popover-content.popover-body'))), - Helper.TIMEOUT - ) - .then(() => - apps.forEach((app) => - element(by.cssContainingText('.select-menu-item-content', app)).click() - ) - ); - }); + await element(by.css('.float-left.mr-2.select-menu-edit')).click(); + await browser.wait( + Helper.EC.visibilityOf(element(by.css('.popover-content.popover-body'))), + Helper.TIMEOUT + ); + apps.forEach( + async (app) => await element(by.cssContainingText('.select-menu-item-content', app)).click() + ); } @PageHelper.restrictTo(pages.index)