]>
Commit | Line | Data |
---|---|---|
e306af50 TL |
1 | import { PageHelper } from '../page-helper.po'; |
2 | ||
f67539c2 TL |
3 | const pages = { |
4 | index: { url: '#/hosts', id: 'cd-hosts' }, | |
a4b75251 | 5 | add: { url: '#/hosts/(modal:add)', id: 'cd-host-form' } |
f67539c2 TL |
6 | }; |
7 | ||
e306af50 | 8 | export class HostsPageHelper extends PageHelper { |
f67539c2 TL |
9 | pages = pages; |
10 | ||
11 | columnIndex = { | |
12 | hostname: 2, | |
13 | services: 3, | |
14 | labels: 4, | |
15 | status: 5 | |
16 | }; | |
e306af50 TL |
17 | |
18 | check_for_host() { | |
f67539c2 | 19 | this.getTableCount('total').should('not.be.eq', 0); |
e306af50 TL |
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 | } | |
f67539c2 | 43 | |
a4b75251 TL |
44 | add(hostname: string, exist?: boolean, maintenance?: boolean, labels: string[] = []) { |
45 | cy.get(`${this.pages.add.id}`).within(() => { | |
f67539c2 | 46 | cy.get('#hostname').type(hostname); |
b3b6e05e TL |
47 | if (maintenance) { |
48 | cy.get('label[for=maintenance]').click(); | |
49 | } | |
a4b75251 TL |
50 | if (exist) { |
51 | cy.get('#hostname').should('have.class', 'ng-invalid'); | |
52 | } | |
f67539c2 | 53 | }); |
a4b75251 TL |
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(); | |
f67539c2 TL |
68 | } |
69 | } | |
70 | ||
f67539c2 TL |
71 | checkExist(hostname: string, exist: boolean) { |
72 | this.getTableCell(this.columnIndex.hostname, hostname).should(($elements) => { | |
73 | const hosts = $elements.map((_, el) => el.textContent).get(); | |
74 | if (exist) { | |
75 | expect(hosts).to.include(hostname); | |
76 | } else { | |
77 | expect(hosts).to.not.include(hostname); | |
78 | } | |
79 | }); | |
80 | } | |
81 | ||
20effc67 | 82 | remove(hostname: string) { |
a4b75251 | 83 | super.delete(hostname, this.columnIndex.hostname, 'hosts'); |
f67539c2 TL |
84 | } |
85 | ||
86 | // Add or remove labels on a host, then verify labels in the table | |
f67539c2 TL |
87 | editLabels(hostname: string, labels: string[], add: boolean) { |
88 | this.getTableCell(this.columnIndex.hostname, hostname).click(); | |
89 | this.clickActionButton('edit'); | |
90 | ||
91 | // add or remove label badges | |
92 | if (add) { | |
93 | cy.get('cd-modal').find('.select-menu-edit').click(); | |
94 | for (const label of labels) { | |
95 | cy.contains('cd-modal .badge', new RegExp(`^${label}$`)).should('not.exist'); | |
96 | cy.get('.popover-body input').type(`${label}{enter}`); | |
97 | } | |
98 | } else { | |
99 | for (const label of labels) { | |
100 | cy.contains('cd-modal .badge', new RegExp(`^${label}$`)) | |
101 | .find('.badge-remove') | |
102 | .click(); | |
103 | } | |
104 | } | |
105 | cy.get('cd-modal cd-submit-button').click(); | |
a4b75251 TL |
106 | this.checkLabelExists(hostname, labels, add); |
107 | } | |
f67539c2 | 108 | |
a4b75251 | 109 | checkLabelExists(hostname: string, labels: string[], add: boolean) { |
f67539c2 TL |
110 | // Verify labels are added or removed from Labels column |
111 | // First find row with hostname, then find labels in the row | |
112 | this.getTableCell(this.columnIndex.hostname, hostname) | |
113 | .parent() | |
114 | .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`) | |
115 | .should(($ele) => { | |
116 | const newLabels = $ele.toArray().map((v) => v.innerText); | |
117 | for (const label of labels) { | |
118 | if (add) { | |
119 | expect(newLabels).to.include(label); | |
120 | } else { | |
121 | expect(newLabels).to.not.include(label); | |
122 | } | |
123 | } | |
124 | }); | |
125 | } | |
126 | ||
127 | @PageHelper.restrictTo(pages.index.url) | |
b3b6e05e | 128 | maintenance(hostname: string, exit = false, force = false) { |
20effc67 | 129 | this.clearTableSearchInput(); |
b3b6e05e | 130 | if (force) { |
f67539c2 | 131 | this.getTableCell(this.columnIndex.hostname, hostname).click(); |
b3b6e05e TL |
132 | this.clickActionButton('enter-maintenance'); |
133 | ||
20effc67 TL |
134 | cy.get('cd-modal').within(() => { |
135 | cy.contains('button', 'Continue').click(); | |
136 | }); | |
b3b6e05e TL |
137 | |
138 | this.getTableCell(this.columnIndex.hostname, hostname) | |
139 | .parent() | |
140 | .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`) | |
141 | .should(($ele) => { | |
142 | const status = $ele.toArray().map((v) => v.innerText); | |
143 | expect(status).to.include('maintenance'); | |
144 | }); | |
145 | } | |
146 | if (exit) { | |
147 | this.getTableCell(this.columnIndex.hostname, hostname) | |
148 | .click() | |
149 | .parent() | |
150 | .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`) | |
151 | .then(($ele) => { | |
152 | const status = $ele.toArray().map((v) => v.innerText); | |
153 | if (status[0].includes('maintenance')) { | |
154 | this.clickActionButton('exit-maintenance'); | |
155 | } | |
156 | }); | |
157 | ||
158 | this.getTableCell(this.columnIndex.hostname, hostname) | |
159 | .parent() | |
160 | .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`) | |
161 | .should(($ele) => { | |
162 | const status = $ele.toArray().map((v) => v.innerText); | |
163 | expect(status).to.not.include('maintenance'); | |
164 | }); | |
165 | } else { | |
166 | this.getTableCell(this.columnIndex.hostname, hostname).click(); | |
167 | this.clickActionButton('enter-maintenance'); | |
168 | ||
169 | this.getTableCell(this.columnIndex.hostname, hostname) | |
170 | .parent() | |
171 | .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`) | |
172 | .should(($ele) => { | |
173 | const status = $ele.toArray().map((v) => v.innerText); | |
174 | expect(status).to.include('maintenance'); | |
175 | }); | |
f67539c2 TL |
176 | } |
177 | } | |
20effc67 TL |
178 | |
179 | @PageHelper.restrictTo(pages.index.url) | |
180 | drain(hostname: string) { | |
181 | this.getTableCell(this.columnIndex.hostname, hostname).click(); | |
182 | this.clickActionButton('start-drain'); | |
183 | this.checkLabelExists(hostname, ['_no_schedule'], true); | |
184 | ||
185 | this.clickTab('cd-host-details', hostname, 'Daemons'); | |
186 | cy.get('cd-host-details').within(() => { | |
187 | cy.wait(20000); | |
188 | this.expectTableCount('total', 0); | |
189 | }); | |
190 | } | |
e306af50 | 191 | } |