]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / integration / cluster / hosts.po.ts
1 import { PageHelper } from '../page-helper.po';
2
3 const pages = {
4 index: { url: '#/hosts', id: 'cd-hosts' },
5 add: { url: '#/hosts/(modal:add)', id: 'cd-host-form' }
6 };
7
8 export class HostsPageHelper extends PageHelper {
9 pages = pages;
10
11 columnIndex = {
12 hostname: 2,
13 services: 3,
14 labels: 4,
15 status: 5
16 };
17
18 check_for_host() {
19 this.getTableCount('total').should('not.be.eq', 0);
20 }
21
22 // function that checks all services links work for first
23 // host in table
24 check_services_links() {
25 // check that text (links) is present in services box
26 let links_tested = 0;
27
28 cy.get('cd-hosts a.service-link')
29 .should('have.length.greaterThan', 0)
30 .then(($elems) => {
31 $elems.each((_i, $el) => {
32 // click link, check it worked by looking for changed breadcrumb,
33 // navigate back to hosts page, repeat until all links checked
34 cy.contains('a', $el.innerText).should('exist').click();
35 this.expectBreadcrumbText('Performance Counters');
36 this.navigateTo();
37 links_tested++;
38 });
39 // check if any links were actually tested
40 expect(links_tested).gt(0);
41 });
42 }
43
44 add(hostname: string, exist?: boolean, maintenance?: boolean, labels: string[] = []) {
45 cy.get(`${this.pages.add.id}`).within(() => {
46 cy.get('#hostname').type(hostname);
47 if (maintenance) {
48 cy.get('label[for=maintenance]').click();
49 }
50 if (exist) {
51 cy.get('#hostname').should('have.class', 'ng-invalid');
52 }
53 });
54
55 if (labels.length) {
56 this.selectPredefinedLabels(labels);
57 }
58
59 cy.get('cd-submit-button').click();
60 // back to host list
61 cy.get(`${this.pages.index.id}`);
62 }
63
64 selectPredefinedLabels(labels: string[]) {
65 cy.get('a[data-testid=select-menu-edit]').click();
66 for (const label of labels) {
67 cy.get('.popover-body div.select-menu-item-content').contains(label).click();
68 }
69 }
70
71 checkExist(hostname: string, exist: boolean) {
72 this.clearTableSearchInput();
73 this.getTableCell(this.columnIndex.hostname, hostname).should(($elements) => {
74 const hosts = $elements.map((_, el) => el.textContent).get();
75 if (exist) {
76 expect(hosts).to.include(hostname);
77 } else {
78 expect(hosts).to.not.include(hostname);
79 }
80 });
81 }
82
83 delete(hostname: string) {
84 super.delete(hostname, this.columnIndex.hostname, 'hosts');
85 }
86
87 // Add or remove labels on a host, then verify labels in the table
88 editLabels(hostname: string, labels: string[], add: boolean) {
89 this.getTableCell(this.columnIndex.hostname, hostname).click();
90 this.clickActionButton('edit');
91
92 // add or remove label badges
93 if (add) {
94 cy.get('cd-modal').find('.select-menu-edit').click();
95 for (const label of labels) {
96 cy.contains('cd-modal .badge', new RegExp(`^${label}$`)).should('not.exist');
97 cy.get('.popover-body input').type(`${label}{enter}`);
98 }
99 } else {
100 for (const label of labels) {
101 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
102 .find('.badge-remove')
103 .click();
104 }
105 }
106 cy.get('cd-modal cd-submit-button').click();
107 this.checkLabelExists(hostname, labels, add);
108 }
109
110 checkLabelExists(hostname: string, labels: string[], add: boolean) {
111 // Verify labels are added or removed from Labels column
112 // First find row with hostname, then find labels in the row
113 this.getTableCell(this.columnIndex.hostname, hostname)
114 .parent()
115 .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`)
116 .should(($ele) => {
117 const newLabels = $ele.toArray().map((v) => v.innerText);
118 for (const label of labels) {
119 if (add) {
120 expect(newLabels).to.include(label);
121 } else {
122 expect(newLabels).to.not.include(label);
123 }
124 }
125 });
126 }
127
128 @PageHelper.restrictTo(pages.index.url)
129 maintenance(hostname: string, exit = false, force = false) {
130 if (force) {
131 this.getTableCell(this.columnIndex.hostname, hostname).click();
132 this.clickActionButton('enter-maintenance');
133
134 cy.contains('cd-modal button', 'Continue').click();
135
136 this.getTableCell(this.columnIndex.hostname, hostname)
137 .parent()
138 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
139 .should(($ele) => {
140 const status = $ele.toArray().map((v) => v.innerText);
141 expect(status).to.include('maintenance');
142 });
143 }
144 if (exit) {
145 this.getTableCell(this.columnIndex.hostname, hostname)
146 .click()
147 .parent()
148 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
149 .then(($ele) => {
150 const status = $ele.toArray().map((v) => v.innerText);
151 if (status[0].includes('maintenance')) {
152 this.clickActionButton('exit-maintenance');
153 }
154 });
155
156 this.getTableCell(this.columnIndex.hostname, hostname)
157 .parent()
158 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
159 .should(($ele) => {
160 const status = $ele.toArray().map((v) => v.innerText);
161 expect(status).to.not.include('maintenance');
162 });
163 } else {
164 this.getTableCell(this.columnIndex.hostname, hostname).click();
165 this.clickActionButton('enter-maintenance');
166
167 this.getTableCell(this.columnIndex.hostname, hostname)
168 .parent()
169 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
170 .should(($ele) => {
171 const status = $ele.toArray().map((v) => v.innerText);
172 expect(status).to.include('maintenance');
173 });
174 }
175 }
176 }