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 // function that checks all services links work for first
24 check_services_links() {
25 // check that text (links) is present in services box
28 cy.get('cd-hosts a.service-link')
29 .should('have.length.greaterThan', 0)
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');
39 // check if any links were actually tested
40 expect(links_tested).gt(0);
44 add(hostname: string, exist?: boolean, maintenance?: boolean, labels: string[] = []) {
45 cy.get(`${this.pages.add.id}`).within(() => {
46 cy.get('#hostname').type(hostname);
48 cy.get('label[for=maintenance]').click();
51 cy.get('#hostname').should('have.class', 'ng-invalid');
56 this.selectPredefinedLabels(labels);
59 cy.get('cd-submit-button').click();
61 cy.get(`${this.pages.index.id}`);
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();
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();
76 expect(hosts).to.include(hostname);
78 expect(hosts).to.not.include(hostname);
83 delete(hostname: string) {
84 super.delete(hostname, this.columnIndex.hostname, 'hosts');
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');
92 // add or remove label badges
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}`);
100 for (const label of labels) {
101 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
102 .find('.badge-remove')
106 cy.get('cd-modal cd-submit-button').click();
107 this.checkLabelExists(hostname, labels, add);
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)
115 .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`)
117 const newLabels = $ele.toArray().map((v) => v.innerText);
118 for (const label of labels) {
120 expect(newLabels).to.include(label);
122 expect(newLabels).to.not.include(label);
128 @PageHelper.restrictTo(pages.index.url)
129 maintenance(hostname: string, exit = false, force = false) {
131 this.getTableCell(this.columnIndex.hostname, hostname).click();
132 this.clickActionButton('enter-maintenance');
134 cy.contains('cd-modal button', 'Continue').click();
136 this.getTableCell(this.columnIndex.hostname, hostname)
138 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
140 const status = $ele.toArray().map((v) => v.innerText);
141 expect(status).to.include('maintenance');
145 this.getTableCell(this.columnIndex.hostname, hostname)
148 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
150 const status = $ele.toArray().map((v) => v.innerText);
151 if (status[0].includes('maintenance')) {
152 this.clickActionButton('exit-maintenance');
156 this.getTableCell(this.columnIndex.hostname, hostname)
158 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
160 const status = $ele.toArray().map((v) => v.innerText);
161 expect(status).to.not.include('maintenance');
164 this.getTableCell(this.columnIndex.hostname, hostname).click();
165 this.clickActionButton('enter-maintenance');
167 this.getTableCell(this.columnIndex.hostname, hostname)
169 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
171 const status = $ele.toArray().map((v) => v.innerText);
172 expect(status).to.include('maintenance');