]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: migrate E2E pools to async/await
authorPatrick Seidensal <pseidensal@suse.com>
Fri, 16 Aug 2019 12:38:54 +0000 (14:38 +0200)
committerPatrick Seidensal <pseidensal@suse.com>
Wed, 28 Aug 2019 07:38:48 +0000 (09:38 +0200)
Fixes: https://tracker.ceph.com/issues/40693
Signed-off-by: Patrick Seidensal <pseidensal@suse.com>
src/pybind/mgr/dashboard/frontend/e2e/pools/pools.e2e-spec.ts
src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts

index b56ca7ee5cf297450c89b8eaca609e10c3eff894..d90fdcd317d4901ed1cad269ae06c7ae748c2060 100644 (file)
@@ -4,55 +4,51 @@ describe('Pools page', () => {
   let pools: Helper['pools'];
   const poolName = 'pool_e2e_pool_test';
 
-  beforeAll(() => {
+  beforeAll(async () => {
     pools = new Helper().pools;
-    pools.navigateTo();
+    await pools.navigateTo();
   });
 
-  afterEach(() => {
-    Helper.checkConsole();
+  afterEach(async () => {
+    await Helper.checkConsole();
   });
 
   describe('breadcrumb and tab tests', () => {
-    it('should open and show breadcrumb', () => {
-      expect(pools.getBreadcrumbText()).toEqual('Pools');
+    it('should open and show breadcrumb', async () => {
+      expect(await pools.getBreadcrumbText()).toEqual('Pools');
     });
 
-    it('should show two tabs', () => {
-      expect(pools.getTabsCount()).toEqual(2);
+    it('should show two tabs', async () => {
+      expect(await pools.getTabsCount()).toEqual(2);
     });
 
-    it('should show pools list tab at first', () => {
-      expect(pools.getTabText(0)).toEqual('Pools List');
+    it('should show pools list tab at first', async () => {
+      expect(await pools.getTabText(0)).toEqual('Pools List');
     });
 
-    it('should show overall performance as a second tab', () => {
-      expect(pools.getTabText(1)).toEqual('Overall Performance');
+    it('should show overall performance as a second tab', async () => {
+      expect(await pools.getTabText(1)).toEqual('Overall Performance');
     });
   });
 
-  it('should create a pool', () => {
-    pools.exist(poolName, false).then(() => {
-      pools.navigateTo('create');
-      pools.create(poolName, 8).then(() => {
-        pools.navigateTo();
-        pools.exist(poolName, true);
-      });
-    });
+  it('should create a pool', async () => {
+    await pools.exist(poolName, false);
+    await pools.navigateTo('create');
+    await pools.create(poolName, 8);
+    await pools.navigateTo();
+    await pools.exist(poolName, true);
   });
 
-  it('should edit a pools placement group', () => {
-    pools.exist(poolName, true).then(() => {
-      pools.navigateTo();
-      pools.edit_pool_pg(poolName, 32);
-    });
+  it('should edit a pools placement group', async () => {
+    await pools.exist(poolName, true);
+    await pools.navigateTo();
+    await pools.edit_pool_pg(poolName, 32);
   });
 
-  it('should delete a pool', () => {
-    pools.exist(poolName);
-    pools.delete(poolName).then(() => {
-      pools.navigateTo();
-      pools.exist(poolName, false);
-    });
+  it('should delete a pool', async () => {
+    await pools.exist(poolName);
+    await pools.delete(poolName);
+    await pools.navigateTo();
+    await pools.exist(poolName, false);
   });
 });
index 55f1a43b10d0b106904e6272845c9a7150495aae..022e667a6138930e94d89d5efc911fa8f92ad87b 100644 (file)
@@ -1,4 +1,4 @@
-import { $, browser, by, element, ElementFinder, promise, protractor } from 'protractor';
+import { $, browser, by, element, protractor } from 'protractor';
 import { Helper } from '../helper.po';
 import { PageHelper } from '../page-helper.po';
 
@@ -17,39 +17,42 @@ export class PoolPageHelper extends PageHelper {
   }
 
   @PageHelper.restrictTo(pages.index)
-  exist(name: string, oughtToBePresent = true): promise.Promise<any> {
-    return this.getTableCellByContent(name).then((elem) => {
-      const waitFn = oughtToBePresent ? EC.visibilityOf(elem) : EC.invisibilityOf(elem);
-      return browser.wait(waitFn, Helper.TIMEOUT).catch(() => {
-        const visibility = oughtToBePresent ? 'invisible' : 'visible';
-        const msg = `Pool "${name}" is ${visibility}, but should not be. Waiting for a change timed out`;
-        return promise.Promise.reject(msg);
-      });
-    });
+  async exist(name: string, oughtToBePresent = true) {
+    const tableCell = await this.getTableCellByContent(name);
+    const waitFn = oughtToBePresent ? EC.visibilityOf(tableCell) : EC.invisibilityOf(tableCell);
+    try {
+      await browser.wait(waitFn, Helper.TIMEOUT);
+    } catch (e) {
+      const visibility = oughtToBePresent ? 'invisible' : 'visible';
+      const msg = `Pool "${name}" is ${visibility}, but should not be. Waiting for a change timed out`;
+      return Promise.reject(msg);
+    }
+    return Promise.resolve();
   }
 
   @PageHelper.restrictTo(pages.create)
-  create(name: string, placement_groups: number, ...apps: string[]): promise.Promise<any> {
+  async create(name: string, placement_groups: number, ...apps: string[]): Promise<any> {
     const nameInput = $('input[name=name]');
-    nameInput.clear();
+    await nameInput.clear();
     if (!this.isPowerOf2(placement_groups)) {
       return Promise.reject(`Placement groups ${placement_groups} are not a power of 2`);
     }
-    return nameInput.sendKeys(name).then(() => {
-      element(by.cssContainingText('select[name=poolType] option', 'replicated'))
-        .click()
-        .then(() => {
-          expect(element(by.css('select[name=poolType] option:checked')).getText()).toBe(
-            ' replicated '
-          );
-          $('input[name=pgNum]')
-            .sendKeys(protractor.Key.CONTROL, 'a', protractor.Key.NULL, placement_groups)
-            .then(() => {
-              this.setApplications(apps);
-              return element(by.css('cd-submit-button')).click();
-            });
-        });
-    });
+    await nameInput.sendKeys(name);
+    await element(by.cssContainingText('select[name=poolType] option', 'replicated')).click();
+
+    expect(await element(by.css('select[name=poolType] option:checked')).getText()).toBe(
+      ' replicated '
+    );
+    await $('input[name=pgNum]').sendKeys(
+      protractor.Key.CONTROL,
+      'a',
+      protractor.Key.NULL,
+      placement_groups
+    );
+    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> {
@@ -103,30 +106,16 @@ export class PoolPageHelper extends PageHelper {
   }
 
   @PageHelper.restrictTo(pages.index)
-  delete(name: string): promise.Promise<any> {
-    return this.getTableCellByContent(name).then((tableCell: ElementFinder) => {
-      return tableCell.click().then(() => {
-        return $('.table-actions button.dropdown-toggle') // open submenu
-          .click()
-          .then(() => {
-            return $('li.delete a') // click on "delete" menu item
-              .click()
-              .then(() => {
-                browser
-                  .wait(Helper.EC.visibilityOf($('.custom-control-label')), Helper.TIMEOUT)
-                  .then(() => {
-                    const getConfirmationCheckbox = () => $('.custom-control-label');
-                    browser
-                      .wait(Helper.EC.visibilityOf(getConfirmationCheckbox()), Helper.TIMEOUT)
-                      .then(() => {
-                        this.moveClick(getConfirmationCheckbox()).then(() => {
-                          return element(by.cssContainingText('button', 'Delete Pool')).click(); // Click Delete item
-                        });
-                      });
-                  });
-              });
-          });
-      });
-    });
+  async delete(name: string): Promise<any> {
+    const tableCell = await this.getTableCellByContent(name);
+    await tableCell.click();
+    await $('.table-actions button.dropdown-toggle').click(); // open submenu
+    await $('li.delete a').click(); // click on "delete" menu item
+    const confirmationInput = () => $('#confirmation');
+    await browser.wait(() => EC.visibilityOf(confirmationInput()), Helper.TIMEOUT);
+    await this.clickCheckbox(confirmationInput());
+    await element(by.cssContainingText('button', 'Delete Pool')).click(); // Click Delete item
+
+    return Promise.resolve();
   }
 }