]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / integration / cluster / hosts.po.ts
index d3e75400bba5a8799f0afd74e83fe7619d537c3c..0785f5107274fe1140c5a54fcf21d85106a2560f 100644 (file)
@@ -1,10 +1,22 @@
 import { PageHelper } from '../page-helper.po';
 
+const pages = {
+  index: { url: '#/hosts', id: 'cd-hosts' },
+  create: { url: '#/hosts/create', id: 'cd-host-form' }
+};
+
 export class HostsPageHelper extends PageHelper {
-  pages = { index: { url: '#/hosts', id: 'cd-hosts' } };
+  pages = pages;
+
+  columnIndex = {
+    hostname: 2,
+    services: 3,
+    labels: 4,
+    status: 5
+  };
 
   check_for_host() {
-    this.getTableTotalCount().should('not.be.eq', 0);
+    this.getTableCount('total').should('not.be.eq', 0);
   }
 
   // function that checks all services links work for first
@@ -28,4 +40,121 @@ export class HostsPageHelper extends PageHelper {
         expect(links_tested).gt(0);
       });
   }
+
+  @PageHelper.restrictTo(pages.index.url)
+  clickHostTab(hostname: string, tabName: string) {
+    this.getExpandCollapseElement(hostname).click();
+    cy.get('cd-host-details').within(() => {
+      this.getTab(tabName).click();
+    });
+  }
+
+  @PageHelper.restrictTo(pages.create.url)
+  add(hostname: string, exist?: boolean) {
+    cy.get(`${this.pages.create.id}`).within(() => {
+      cy.get('#hostname').type(hostname);
+      cy.get('cd-submit-button').click();
+    });
+    if (exist) {
+      cy.get('#hostname').should('have.class', 'ng-invalid');
+    } else {
+      // back to host list
+      cy.get(`${this.pages.index.id}`);
+    }
+  }
+
+  @PageHelper.restrictTo(pages.index.url)
+  checkExist(hostname: string, exist: boolean) {
+    this.getTableCell(this.columnIndex.hostname, hostname).should(($elements) => {
+      const hosts = $elements.map((_, el) => el.textContent).get();
+      if (exist) {
+        expect(hosts).to.include(hostname);
+      } else {
+        expect(hosts).to.not.include(hostname);
+      }
+    });
+  }
+
+  @PageHelper.restrictTo(pages.index.url)
+  delete(hostname: string) {
+    super.delete(hostname, this.columnIndex.hostname);
+  }
+
+  // Add or remove labels on a host, then verify labels in the table
+  @PageHelper.restrictTo(pages.index.url)
+  editLabels(hostname: string, labels: string[], add: boolean) {
+    this.getTableCell(this.columnIndex.hostname, hostname).click();
+    this.clickActionButton('edit');
+
+    // add or remove label badges
+    if (add) {
+      cy.get('cd-modal').find('.select-menu-edit').click();
+      for (const label of labels) {
+        cy.contains('cd-modal .badge', new RegExp(`^${label}$`)).should('not.exist');
+        cy.get('.popover-body input').type(`${label}{enter}`);
+      }
+    } else {
+      for (const label of labels) {
+        cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
+          .find('.badge-remove')
+          .click();
+      }
+    }
+    cy.get('cd-modal cd-submit-button').click();
+
+    // Verify labels are added or removed from Labels column
+    // First find row with hostname, then find labels in the row
+    this.getTableCell(this.columnIndex.hostname, hostname)
+      .parent()
+      .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`)
+      .should(($ele) => {
+        const newLabels = $ele.toArray().map((v) => v.innerText);
+        for (const label of labels) {
+          if (add) {
+            expect(newLabels).to.include(label);
+          } else {
+            expect(newLabels).to.not.include(label);
+          }
+        }
+      });
+  }
+
+  @PageHelper.restrictTo(pages.index.url)
+  maintenance(hostname: string, exit = false) {
+    let services: string[];
+    let runTest = false;
+    this.getTableCell(this.columnIndex.hostname, hostname)
+      .parent()
+      .find(`datatable-body-cell:nth-child(${this.columnIndex.services}) a`)
+      .should(($el) => {
+        services = $el.text().split(', ');
+        if (services.length < 2 && services[0].includes('osd')) {
+          runTest = true;
+        }
+      });
+    if (runTest) {
+      this.getTableCell(this.columnIndex.hostname, hostname).click();
+      if (exit) {
+        this.clickActionButton('exit-maintenance');
+
+        this.getTableCell(this.columnIndex.hostname, hostname)
+          .parent()
+          .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
+          .should(($ele) => {
+            const status = $ele.toArray().map((v) => v.innerText);
+            expect(status).to.not.include('maintenance');
+          });
+      } else {
+        this.clickActionButton('enter-maintenance');
+
+        this.getTableCell(this.columnIndex.hostname, hostname)
+          .parent()
+          .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
+          .should(($ele) => {
+            const status = $ele.toArray().map((v) => v.innerText);
+            expect(status).to.include('maintenance');
+          });
+      }
+    }
+  }
 }