1 import { PageHelper } from '../page-helper.po';
4 index: { url: '#/services', id: 'cd-services' },
5 create: { url: '#/services/(modal:create)', id: 'cd-service-form' }
8 export class ServicesPageHelper extends PageHelper {
19 serviceDetailColumnIndex = {
25 this.getTableCount('total').should('not.be.eq', 0);
28 private selectServiceType(serviceType: string) {
29 return this.selectOption('service_type', serviceType);
32 clickServiceTab(serviceName: string, tabName: string) {
33 this.getExpandCollapseElement(serviceName).click();
34 cy.get('cd-service-details').within(() => {
35 this.getTab(tabName).click();
44 snmpPrivProtocol?: boolean,
47 cy.get(`${this.pages.create.id}`).within(() => {
48 this.selectServiceType(serviceType);
49 switch (serviceType) {
51 cy.get('#service_id').type('foo');
52 unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(count);
57 cy.get('label[for=unmanaged]').click();
59 this.selectOption('backend_service', 'rgw.foo');
60 cy.get('#service_id').should('have.value', 'rgw.foo');
61 cy.get('#virtual_ip').type('192.168.100.1/24');
62 cy.get('#frontend_port').type('8081');
63 cy.get('#monitor_port').type('8082');
67 cy.get('#service_id').type('testnfs');
68 unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(count);
72 this.selectOption('snmp_version', snmpVersion);
73 cy.get('#snmp_destination').type('192.168.0.1:8443');
74 if (snmpVersion === 'V2c') {
75 cy.get('#snmp_community').type('public');
77 cy.get('#engine_id').type('800C53F00000');
78 this.selectOption('auth_protocol', 'SHA');
79 if (snmpPrivProtocol) {
80 this.selectOption('privacy_protocol', 'DES');
81 cy.get('#snmp_v3_priv_password').type('testencrypt');
85 cy.get('#snmp_v3_auth_username').type('test');
86 cy.get('#snmp_v3_auth_password').type('testpass');
91 cy.get('#service_id').type('test');
92 unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(count);
95 if (serviceType === 'snmp-gateway') {
96 cy.get('cd-submit-button').dblclick();
98 cy.get('cd-submit-button').click();
102 cy.get('#service_id').should('have.class', 'ng-invalid');
104 // back to service list
105 cy.get(`${this.pages.index.id}`);
109 editService(name: string, daemonCount: string) {
110 this.navigateEdit(name, true, false);
111 cy.get(`${this.pages.create.id}`).within(() => {
112 cy.get('#service_type').should('be.disabled');
113 cy.get('#service_id').should('be.disabled');
114 cy.get('#count').clear().type(daemonCount);
115 cy.get('cd-submit-button').click();
119 checkServiceStatus(daemon: string, expectedStatus = 'running') {
120 let daemonNameIndex = this.serviceDetailColumnIndex.daemonName;
121 let statusIndex = this.serviceDetailColumnIndex.status;
123 // since hostname row is hidden from the hosts details table,
124 // we'll need to manually override the indexes when this check is being
125 // done for the daemons in host details page. So we'll get the url and
126 // verify if the current page is not the services index page
127 cy.url().then((url) => {
128 if (!url.includes(pages.index.url)) {
133 cy.get('cd-service-daemon-list').within(() => {
134 this.getTableCell(daemonNameIndex, daemon, true)
136 .find(`datatable-body-cell:nth-child(${statusIndex}) .badge`)
138 const status = $ele.toArray().map((v) => v.innerText);
139 expect(status).to.include(expectedStatus);
145 expectPlacementCount(serviceName: string, expectedCount: string) {
146 this.getTableCell(this.columnIndex.service_name, serviceName)
148 .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`)
150 const running = $ele.text().split(';');
151 expect(running).to.include(`count:${expectedCount}`);
155 checkExist(serviceName: string, exist: boolean) {
156 this.getTableCell(this.columnIndex.service_name, serviceName).should(($elements) => {
157 const services = $elements.map((_, el) => el.textContent).get();
159 expect(services).to.include(serviceName);
161 expect(services).to.not.include(serviceName);
166 isUnmanaged(serviceName: string, unmanaged: boolean) {
167 this.getTableCell(this.columnIndex.service_name, serviceName)
169 .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`)
171 const placement = $ele.text().split(';');
173 ? expect(placement).to.include('unmanaged')
174 : expect(placement).to.not.include('unmanaged');
178 deleteService(serviceName: string) {
179 const getRow = this.getTableCell.bind(this, this.columnIndex.service_name);
180 getRow(serviceName).click();
182 // Clicks on table Delete button
183 this.clickActionButton('delete');
186 cy.get('cd-modal .custom-control-label').click();
187 cy.contains('cd-modal button', 'Delete').click();
189 // Wait for modal to close
190 cy.get('cd-modal').should('not.exist');
191 this.checkExist(serviceName, false);
194 daemonAction(daemon: string, action: string) {
195 cy.get('cd-service-daemon-list').within(() => {
196 this.getTableRow(daemon).click();
197 this.clickActionButton(action);
199 // unselect it to avoid colliding with any other selection
200 // in different steps
201 this.getTableRow(daemon).click();