]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: refatoring E2E page helper test
authorPatrick Seidensal <pseidensal@suse.com>
Fri, 23 Aug 2019 23:54:54 +0000 (01:54 +0200)
committerPatrick Seidensal <pseidensal@suse.com>
Wed, 28 Aug 2019 07:38:49 +0000 (09:38 +0200)
Signed-off-by: Patrick Seidensal <pseidensal@suse.com>
src/pybind/mgr/dashboard/frontend/e2e/cluster/mgr-modules.po.ts
src/pybind/mgr/dashboard/frontend/e2e/cluster/monitors.e2e-spec.ts
src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts

index 56ac261292afb992e7b2620f826461dfe8644cce..03ece75d69c6decb90c772232f9061ec4e99d3de 100644 (file)
@@ -23,7 +23,7 @@ export class ManagerModulesPageHelper extends PageHelper {
 
     for (const entry of tuple) {
       // Clears fields and adds edits
-      await this.inputClear(element(by.id(entry[1])));
+      await this.clearInput(element(by.id(entry[1])));
       await element(by.id(entry[1])).sendKeys(entry[0]);
     }
 
@@ -47,7 +47,7 @@ export class ManagerModulesPageHelper extends PageHelper {
 
     // Clears the editable fields
     for (const entry of tuple) {
-      await this.inputClear(element(by.id(entry[1])));
+      await this.clearInput(element(by.id(entry[1])));
     }
 
     // Checks that clearing represents in details tab of module
@@ -95,7 +95,7 @@ export class ManagerModulesPageHelper extends PageHelper {
     for (let i = 0, devHealthTuple; (devHealthTuple = devHealthArray[i]); i++) {
       if (devHealthTuple[0] !== undefined) {
         // Clears and inputs edits
-        await this.inputClear(element(by.id(devHealthTuple[1])));
+        await this.clearInput(element(by.id(devHealthTuple[1])));
         await element(by.id(devHealthTuple[1])).sendKeys(devHealthTuple[0]);
       }
     }
@@ -129,22 +129,22 @@ export class ManagerModulesPageHelper extends PageHelper {
     ); // checks ansible
     await this.getTableCell('devicehealth').click();
     await element(by.cssContainingText('button', 'Edit')).click();
-    await this.inputClear(element(by.id('mark_out_threshold')));
+    await this.clearInput(element(by.id('mark_out_threshold')));
     await element(by.id('mark_out_threshold')).sendKeys('2419200');
 
-    await this.inputClear(element(by.id('pool_name')));
+    await this.clearInput(element(by.id('pool_name')));
     await element(by.id('pool_name')).sendKeys('device_health_metrics');
 
-    await this.inputClear(element(by.id('retention_period')));
+    await this.clearInput(element(by.id('retention_period')));
     await element(by.id('retention_period')).sendKeys('15552000');
 
-    await this.inputClear(element(by.id('scrape_frequency')));
+    await this.clearInput(element(by.id('scrape_frequency')));
     await element(by.id('scrape_frequency')).sendKeys('86400');
 
-    await this.inputClear(element(by.id('sleep_interval')));
+    await this.clearInput(element(by.id('sleep_interval')));
     await element(by.id('sleep_interval')).sendKeys('600');
 
-    await this.inputClear(element(by.id('warn_threshold')));
+    await this.clearInput(element(by.id('warn_threshold')));
     await element(by.id('warn_threshold')).sendKeys('7257600');
 
     // Checks that clearing represents in details tab of ansible
index 0b6686e059a599620aff6df5d684fe28b84c3b5d..f86fae2a613614db13314918a7298b885ea23c10 100644 (file)
@@ -37,13 +37,13 @@ describe('Monitors page', () => {
       ).toMatch('Status');
 
       // check for fields in table
-      expect(await monitors.getStatusTable().getText()).toMatch('Cluster ID');
-      expect(await monitors.getStatusTable().getText()).toMatch('monmap modified');
-      expect(await monitors.getStatusTable().getText()).toMatch('monmap epoch');
-      expect(await monitors.getStatusTable().getText()).toMatch('quorum con');
-      expect(await monitors.getStatusTable().getText()).toMatch('quorum mon');
-      expect(await monitors.getStatusTable().getText()).toMatch('required con');
-      expect(await monitors.getStatusTable().getText()).toMatch('required mon');
+      expect(await monitors.getStatusTables().getText()).toMatch('Cluster ID');
+      expect(await monitors.getStatusTables().getText()).toMatch('monmap modified');
+      expect(await monitors.getStatusTables().getText()).toMatch('monmap epoch');
+      expect(await monitors.getStatusTables().getText()).toMatch('quorum con');
+      expect(await monitors.getStatusTables().getText()).toMatch('quorum mon');
+      expect(await monitors.getStatusTables().getText()).toMatch('required con');
+      expect(await monitors.getStatusTables().getText()).toMatch('required mon');
     });
 
     it('should check In Quorum and Not In Quorum tables are present', async () => {
index b40b1c2f3001a32da03c9e8693f6abfde1d9f91e..64e7db0555d6cc2fbca40420a48c8a5450244bde 100644 (file)
@@ -20,10 +20,9 @@ export abstract class PageHelper {
   pages: Pages;
 
   /**
-   * Decorator to be used on Helper methods to restrict access to one
-   * particular URL.  This shall help developers to prevent and highlight
-   * mistakes.  It also reduces boilerplate code and by thus, increases
-   * readability.
+   * Decorator to be used on Helper methods to restrict access to one particular URL.  This shall
+   * help developers to prevent and highlight mistakes.  It also reduces boilerplate code and by
+   * thus, increases readability.
    */
   static restrictTo(page): Function {
     return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
@@ -83,9 +82,9 @@ export abstract class PageHelper {
     return $('.breadcrumb-item.active').getText();
   }
 
-  async getTabText(idx): Promise<string> {
+  async getTabText(index): Promise<string> {
     return $$('.nav.nav-tabs li')
-      .get(idx)
+      .get(index)
       .getText();
   }
 
@@ -98,16 +97,6 @@ export abstract class PageHelper {
     );
   }
 
-  // getTitleText() {
-  //   let title;
-  //   return browser
-  //     .wait(() => {
-  //       title = $('.panel-title');
-  //       return title.isPresent();
-  //     })
-  //     .then(() => title.getText());
-  // }
-  //
   getTableCell(content: string): ElementFinder {
     return element(by.cssContainingText('.datatable-body-cell-label', content));
   }
@@ -129,17 +118,13 @@ export abstract class PageHelper {
   }
 
   /**
-   * Used for instances where a modal container would receive the click rather
-   * than the desired element.
+   * Ceph Dashboards' <input type="checkbox"> tag is not visible. Instead of the real checkbox, a
+   * replacement is shown which is supposed to have an adapted style. The replacement checkbox shown
+   * is part of the label and is rendered in the "::before" pseudo element of the label, hence the
+   * label is always clicked when the user clicks the replacement checkbox.
    *
-   * Our <input type="checkbox"> tag is not visible. Instead of the real
-   * checkbox, a replacement is shown which is supposed to have an adapted
-   * style. The replacement checkbox shown is part of the label and is rendered
-   * in the "::before" pseudo element of the label, hence the label is always
-   * clicked when the user clicks the replacement checkbox.
-   *
-   * This method finds corresponding label to the given checkbox and clicks it
-   * instead of the (fake) checkbox, like it is the case with real users.
+   * This method finds corresponding label to the given checkbox and clicks it instead of the (fake)
+   * checkbox, like it is the case with real users.
    *
    * Alternatively, the checkbox' label can be passed.
    *
@@ -167,14 +152,12 @@ export abstract class PageHelper {
   }
 
   /**
-   * Returns the cell with the content given in `content`. Will not return a
-   * rejected Promise if the table cell hasn't been found. It behaves this way
-   * to enable to wait for visiblity/invisiblity/presence of the returned
-   * element.
+   * Returns the cell with the content given in `content`. Will not return a rejected Promise if the
+   * table cell hasn't been found. It behaves this way to enable to wait for
+   * visibility/invisibility/presence of the returned element.
    *
-   * It will return a rejected Promise if the result is ambigous, though. That
-   * means if the search for content has been completed, but more than a single
-   * row is shown in the data table.
+   * It will return a rejected Promise if the result is ambiguous, though. That means if the search
+   * for content has been completed, but more than a single row is shown in the data table.
    */
   async getTableCellByContent(content: string): Promise<ElementFinder> {
     const searchInput = $('#pool-list > div .search input');
@@ -188,7 +171,7 @@ export abstract class PageHelper {
 
     const count = Number(await footer.getAttribute('ng-reflect-row-count'));
     if (count !== 0 && count > 1) {
-      return Promise.reject('getTableCellByContent: Result is ambigous');
+      return Promise.reject('getTableCellByContent: Result is ambiguous');
     } else {
       return Promise.resolve(
         element(
@@ -198,10 +181,19 @@ export abstract class PageHelper {
     }
   }
 
-  // used when .clear() does not work on a text box, sends a Ctrl + a, BACKSPACE
-  async inputClear(elem) {
-    await elem.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'a'));
-    await elem.sendKeys(protractor.Key.BACK_SPACE);
+  /**
+   * Used when .clear() does not work on a text box, sends a Ctrl + a, BACKSPACE
+   */
+  async clearInput(elem: ElementFinder) {
+    const types = ['text', 'number'];
+    if ((await elem.getTagName()) === 'input' && types.includes(await elem.getAttribute('type'))) {
+      await elem.sendKeys(
+        protractor.Key.chord(protractor.Key.CONTROL, 'a'),
+        protractor.Key.BACK_SPACE
+      );
+    } else {
+      return Promise.reject(`Element ${elem} does not match the expected criteria.`);
+    }
   }
 
   @PageHelper.waitForTableData()
@@ -220,10 +212,17 @@ export abstract class PageHelper {
     return $$('cd-table');
   }
 
+  /**
+   * Gets column headers of table
+   */
+  getDataTableHeaders(): ElementArrayFinder {
+    return $$('.datatable-header');
+  }
+
   /**
    * Grabs striped tables
    */
-  getStatusTable(): ElementArrayFinder {
+  getStatusTables(): ElementArrayFinder {
     return $$('.table.table-striped');
   }
 
@@ -233,11 +232,4 @@ export abstract class PageHelper {
   getLegends(): ElementArrayFinder {
     return $$('legend');
   }
-
-  /**
-   * Gets column headers of table
-   */
-  getDataTableHeaders(): ElementArrayFinder {
-    return $$('.datatable-header');
-  }
 }