1 import { PageHelper } from '../page-helper.po';
4 index: { url: '#/hosts', id: 'cd-hosts' },
5 add: { url: '#/hosts/(modal:add)', id: 'cd-host-form' }
8 export class HostsPageHelper extends PageHelper {
19 this.getTableCount('total').should('not.be.eq', 0);
22 add(hostname: string, exist?: boolean, maintenance?: boolean, labels: string[] = []) {
23 cy.get(`${this.pages.add.id}`).within(() => {
24 cy.get('#hostname').type(hostname);
26 cy.get('label[for=maintenance]').click();
29 cy.get('#hostname').should('have.class', 'ng-invalid');
34 this.selectPredefinedLabels(labels);
37 cy.get('cd-submit-button').click();
39 cy.get(`${this.pages.index.id}`);
42 selectPredefinedLabels(labels: string[]) {
43 cy.get('a[data-testid=select-menu-edit]').click();
44 for (const label of labels) {
45 cy.get('.popover-body div.select-menu-item-content').contains(label).click();
49 checkExist(hostname: string, exist: boolean) {
50 this.getTableCell(this.columnIndex.hostname, hostname).should(($elements) => {
51 const hosts = $elements.map((_, el) => el.textContent).get();
53 expect(hosts).to.include(hostname);
55 expect(hosts).to.not.include(hostname);
60 remove(hostname: string) {
61 super.delete(hostname, this.columnIndex.hostname, 'hosts');
64 // Add or remove labels on a host, then verify labels in the table
65 editLabels(hostname: string, labels: string[], add: boolean) {
66 this.getTableCell(this.columnIndex.hostname, hostname).click();
67 this.clickActionButton('edit');
69 // add or remove label badges
71 cy.get('cd-modal').find('.select-menu-edit').click();
72 for (const label of labels) {
73 cy.contains('cd-modal .badge', new RegExp(`^${label}$`)).should('not.exist');
74 cy.get('.popover-body input').type(`${label}{enter}`);
77 for (const label of labels) {
78 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
79 .find('.badge-remove')
83 cy.get('cd-modal cd-submit-button').click();
84 this.checkLabelExists(hostname, labels, add);
87 checkLabelExists(hostname: string, labels: string[], add: boolean) {
88 // Verify labels are added or removed from Labels column
89 // First find row with hostname, then find labels in the row
90 this.getTableCell(this.columnIndex.hostname, hostname)
93 .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`)
95 const newLabels = $ele.toArray().map((v) => v.innerText);
96 for (const label of labels) {
98 expect(newLabels).to.include(label);
100 expect(newLabels).to.not.include(label);
106 @PageHelper.restrictTo(pages.index.url)
107 maintenance(hostname: string, exit = false, force = false) {
108 this.clearTableSearchInput();
110 this.getTableCell(this.columnIndex.hostname, hostname).click();
111 this.clickActionButton('enter-maintenance');
113 cy.get('cd-modal').within(() => {
114 cy.contains('button', 'Continue').click();
117 this.getTableCell(this.columnIndex.hostname, hostname)
119 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
121 const status = $ele.toArray().map((v) => v.innerText);
122 expect(status).to.include('maintenance');
126 this.getTableCell(this.columnIndex.hostname, hostname)
129 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
131 const status = $ele.toArray().map((v) => v.innerText);
132 if (status[0].includes('maintenance')) {
133 this.clickActionButton('exit-maintenance');
137 this.getTableCell(this.columnIndex.hostname, hostname)
139 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
141 const status = $ele.toArray().map((v) => v.innerText);
142 expect(status).to.not.include('maintenance');
145 this.getTableCell(this.columnIndex.hostname, hostname).click();
146 this.clickActionButton('enter-maintenance');
148 this.getTableCell(this.columnIndex.hostname, hostname)
150 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
152 const status = $ele.toArray().map((v) => v.innerText);
153 expect(status).to.include('maintenance');
158 @PageHelper.restrictTo(pages.index.url)
159 drain(hostname: string) {
160 this.getTableCell(this.columnIndex.hostname, hostname).click();
161 this.clickActionButton('start-drain');
162 this.checkLabelExists(hostname, ['_no_schedule'], true);
164 this.clickTab('cd-host-details', hostname, 'Daemons');
165 cy.get('cd-host-details').within(() => {
167 this.expectTableCount('total', 0);
171 checkServiceInstancesExist(hostname: string, instances: string[]) {
172 this.getTableCell(this.columnIndex.hostname, hostname)
174 .find(`datatable-body-cell:nth-child(${this.columnIndex.services}) .badge`)
176 const serviceInstances = $ele.toArray().map((v) => v.innerText);
177 for (const instance of instances) {
178 expect(serviceInstances).to.include(instance);