]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: PageHelper.selectOption
authorStephan Müller <smueller@suse.com>
Tue, 14 Jan 2020 13:31:52 +0000 (14:31 +0100)
committerStephan Müller <smueller@suse.com>
Wed, 15 Jan 2020 08:40:59 +0000 (09:40 +0100)
This helper method selects an option inside a select element.
It will also expect that the option was set.

Fixes: https://tracker.ceph.com/issues/43594
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/e2e/block/images.po.ts
src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts
src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts
src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts
src/pybind/mgr/dashboard/frontend/e2e/rgw/buckets.po.ts

index 1d3dce134918638d5fcb94dfe7c4662c5b8597fe..1390ae6d41e1fb420a9de4d1eb276c274f91e102 100644 (file)
@@ -18,8 +18,7 @@ export class ImagesPageHelper extends PageHelper {
     await element(by.id('name')).sendKeys(name); // Enter in image name
 
     // Select image pool
-    await element(by.id('pool')).click();
-    await element(by.cssContainingText('select[name=pool] option', pool)).click();
+    await this.selectOption('pool', pool);
     await $(getPoolName).click();
     await expect(element(by.id('pool')).getAttribute('class')).toContain('ng-valid'); // check if selected
 
index 1cb31168425ac4e7442a2d0c199a91bfb0d29216..22de6dcb8864d13984192ebb0eb12d03fc9c4441 100644 (file)
@@ -20,8 +20,7 @@ export class MirroringPageHelper extends PageHelper {
     await this.waitClickableAndClick(editModeButton);
     // Clicks the drop down in the edit pop-up, then clicks the Update button
     await this.waitVisibility($('.modal-content'));
-    await element(by.id('mirrorMode')).click(); // Mode select box
-    await element(by.cssContainingText('select[name=mirrorMode] option', option)).click();
+    await this.selectOption('mirrorMode', option);
 
     // Clicks update button and checks if the mode has been changed
     await element(by.cssContainingText('button', 'Update')).click();
index e142d869e122eac9e08c5cd99ccdf5c53f6035fc..464d61ed78a96fb75d9c98a3cd1e989ca1ba4f3f 100644 (file)
@@ -143,6 +143,24 @@ export abstract class PageHelper {
     return this.waitClickableAndClick(label);
   }
 
+  /**
+   * Helper method to select an option inside a select element.
+   * This method will also expect that the option was set.
+   */
+  async selectOption(selectionName: string, option: string) {
+    await element(by.cssContainingText(`select[name=${selectionName}] option`, option)).click();
+    return this.expectSelectOption(selectionName, option);
+  }
+
+  /**
+   * Helper method to expect a set option inside a select element.
+   */
+  async expectSelectOption(selectionName: string, option: string) {
+    return expect(
+      element(by.css(`select[name=${selectionName}] option:checked`)).getText()
+    ).toContain(option);
+  }
+
   /**
    * 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
index 81883d2d1bee8a58bcb6ee269d7c0ead4f05bab6..66072b0243d90a62dbf0a4b9e6b617e54e5543a2 100644 (file)
@@ -36,11 +36,8 @@ export class PoolPageHelper extends PageHelper {
       return Promise.reject(`Placement groups ${placement_groups} are not a power of 2`);
     }
     await nameInput.sendKeys(name);
-    await element(by.cssContainingText('select[name=poolType] option', 'replicated')).click();
+    await this.selectOption('poolType', 'replicated');
 
-    await expect(element(by.css('select[name=poolType] option:checked')).getText()).toBe(
-      ' replicated '
-    );
     await $('input[name=pgNum]').sendKeys(
       protractor.Key.CONTROL,
       'a',
index cf3f604560363668915db092c3b5c64adf783458..13be04baefcb527f1b8a77c53f02946618ad9606 100644 (file)
@@ -11,6 +11,14 @@ export class BucketsPageHelper extends PageHelper {
   versioningStateEnabled = 'Enabled';
   versioningStateSuspended = 'Suspended';
 
+  private async selectOwner(owner: string) {
+    return this.selectOption('owner', owner);
+  }
+
+  private async selectPlacementTarget(placementTarget: string) {
+    return this.selectOption('placement-target', placementTarget);
+  }
+
   /**
    * TODO add check to verify the existance of the bucket!
    * TODO let it print a meaningful error message (for devs) if it does not exist!
@@ -21,15 +29,11 @@ export class BucketsPageHelper extends PageHelper {
     await element(by.id('bid')).sendKeys(name);
 
     // Select bucket owner
-    await element(by.id('owner')).click();
-    await element(by.cssContainingText('select[name=owner] option', owner)).click();
+    await this.selectOwner(owner);
     await expect(element(by.id('owner')).getAttribute('class')).toContain('ng-valid');
 
     // Select bucket placement target:
-    await element(by.id('owner')).click();
-    await element(
-      by.cssContainingText('select[name=placement-target] option', placementTarget)
-    ).click();
+    await this.selectPlacementTarget(placementTarget);
     await expect(element(by.id('placement-target')).getAttribute('class')).toContain('ng-valid');
 
     // Click the create button and wait for bucket to be made
@@ -50,8 +54,7 @@ export class BucketsPageHelper extends PageHelper {
     await expect(element(by.css('input[name=placement-target]')).getAttribute('value')).toBe(
       'default-placement'
     );
-    await element(by.id('owner')).click(); // click owner dropdown menu
-    await element(by.cssContainingText('select[name=owner] option', new_owner)).click(); // select the new user
+    await this.selectOwner(new_owner);
 
     // Enable versioning
     await expect(element(by.css('input[name=versioning]:checked')).getAttribute('value')).toBe(
@@ -116,12 +119,11 @@ export class BucketsPageHelper extends PageHelper {
   async testInvalidCreate() {
     await this.navigateTo('create');
     const nameInputField = element(by.id('bid')); // Grabs name box field
-    const ownerDropDown = element(by.id('owner')); // Grab owner field
 
     // Gives an invalid name (too short), then waits for dashboard to determine validity
     await nameInputField.sendKeys('rq');
 
-    await ownerDropDown.click(); // To trigger a validation
+    await element(by.id('owner')).click(); // To trigger a validation
 
     await this.waitFn(async () => {
       // Waiting for website to decide if name is valid or not
@@ -138,14 +140,12 @@ export class BucketsPageHelper extends PageHelper {
     );
 
     // Test invalid owner input
-    await ownerDropDown.click(); // Clicks the Owner drop down on the Create Bucket page
     // select some valid option. The owner drop down error message will not appear unless a valid user was selected at
     // one point before the invalid placeholder user is selected.
-    await element(by.cssContainingText('select[name=owner] option', 'dev')).click();
+    await this.selectOwner('dev');
 
-    await ownerDropDown.click();
     // select the first option, which is invalid because it is a placeholder
-    await element(by.cssContainingText('select[name=owner] option', 'Select a user')).click();
+    await this.selectOwner('Select a user');
 
     await nameInputField.click();
 
@@ -158,15 +158,10 @@ export class BucketsPageHelper extends PageHelper {
     );
 
     // Check invalid placement target input
-    await ownerDropDown.click();
-    await element(by.cssContainingText('select[name=owner] option', 'dev')).click();
+    await this.selectOwner('dev');
     // The drop down error message will not appear unless a valid option is previsously selected.
-    await element(
-      by.cssContainingText('select[name=placement-target] option', 'default-placement')
-    ).click();
-    await element(
-      by.cssContainingText('select[name=placement-target] option', 'Select a placement target')
-    ).click();
+    await this.selectPlacementTarget('default-placement');
+    await this.selectPlacementTarget('Select a placement target');
     await nameInputField.click(); // Trigger validation
     await expect(element(by.id('placement-target')).getAttribute('class')).toContain('ng-invalid');
     await expect(element(by.css('#placement-target + .invalid-feedback')).getText()).toMatch(
@@ -196,11 +191,9 @@ export class BucketsPageHelper extends PageHelper {
 
     // Chooses 'Select a user' rather than a valid owner on Edit Bucket page
     // and checks if it's an invalid input
-    const ownerDropDown = element(by.id('owner'));
-    await this.waitClickableAndClick(ownerDropDown);
 
     // select the first option, which is invalid because it is a placeholder
-    await element(by.cssContainingText('select[name=owner] option', 'Select a user')).click();
+    await this.selectOwner('Select a user');
 
     // Changes when updated to bootstrap 4 -> Error message takes a long time to appear unless another field
     // is clicked on. For that reason, I'm having the test click on the edit button before checking for errors