Skip to content

Commit

Permalink
mgr/dashboard: migrate E2E mirroring to async/await
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/40693

Signed-off-by: Patrick Seidensal <[email protected]>
  • Loading branch information
p-se committed Aug 28, 2019
1 parent a348f88 commit cee3c69
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 107 deletions.
67 changes: 34 additions & 33 deletions src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
54 changes: 21 additions & 33 deletions src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/pybind/mgr/dashboard/frontend/e2e/helper.po.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -39,6 +40,7 @@ export class Helper {
crushMap: CrushMapPageHelper;
configuration: ConfigurationPageHelper;
alerts: AlertsPageHelper;
mirroring: MirroringPageHelper;

constructor() {
this.pools = new PoolPageHelper();
Expand All @@ -60,6 +62,7 @@ export class Helper {
this.crushMap = new CrushMapPageHelper();
this.configuration = new ConfigurationPageHelper();
this.alerts = new AlertsPageHelper();
this.mirroring = new MirroringPageHelper();
}

/**
Expand Down
69 changes: 28 additions & 41 deletions src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
async edit_pool_pg(name: string, new_pg: number): Promise<void> {
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)
Expand Down

0 comments on commit cee3c69

Please sign in to comment.