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
46 cy.get(`${this.pages.create.id}`).within(() => {
47 this.selectServiceType(serviceType);
48 switch (serviceType) {
50 cy.get('#service_id').type('foo');
51 cy.get('#count').type(count);
55 this.selectOption('backend_service', 'rgw.foo');
56 cy.get('#service_id').should('have.value', 'rgw.foo');
57 cy.get('#virtual_ip').type('192.168.100.1/24');
58 cy.get('#frontend_port').type('8081');
59 cy.get('#monitor_port').type('8082');
63 cy.get('#service_id').type('testnfs');
64 cy.get('#count').type(count);
68 this.selectOption('snmp_version', snmpVersion);
69 cy.get('#snmp_destination').type('192.168.0.1:8443');
70 if (snmpVersion === 'V2c') {
71 cy.get('#snmp_community').type('public');
73 cy.get('#engine_id').type('800C53F00000');
74 this.selectOption('auth_protocol', 'SHA');
75 if (snmpPrivProtocol) {
76 this.selectOption('privacy_protocol', 'DES');
77 cy.get('#snmp_v3_priv_password').type('testencrypt');
81 cy.get('#snmp_v3_auth_username').type('test');
82 cy.get('#snmp_v3_auth_password').type('testpass');
87 cy.get('#service_id').type('test');
88 cy.get('#count').type(count);
91 if (serviceType === 'snmp-gateway') {
92 cy.get('cd-submit-button').dblclick();
94 cy.get('cd-submit-button').click();
98 cy.get('#service_id').should('have.class', 'ng-invalid');
100 // back to service list
101 cy.get(`${this.pages.index.id}`);
105 editService(name: string, daemonCount: string) {
106 this.navigateEdit(name, true, false);
107 cy.get(`${this.pages.create.id}`).within(() => {
108 cy.get('#service_type').should('be.disabled');
109 cy.get('#service_id').should('be.disabled');
110 cy.get('#count').clear().type(daemonCount);
111 cy.get('cd-submit-button').click();
115 checkServiceStatus(daemon: string, expectedStatus = 'running') {
116 let daemonNameIndex = this.serviceDetailColumnIndex.daemonName;
117 let statusIndex = this.serviceDetailColumnIndex.status;
119 // since hostname row is hidden from the hosts details table,
120 // we'll need to manually override the indexes when this check is being
121 // done for the daemons in host details page. So we'll get the url and
122 // verify if the current page is not the services index page
123 cy.url().then((url) => {
124 if (!url.includes(pages.index.url)) {
129 cy.get('cd-service-daemon-list').within(() => {
130 this.getTableCell(daemonNameIndex, daemon, true)
132 .find(`datatable-body-cell:nth-child(${statusIndex}) .badge`)
134 const status = $ele.toArray().map((v) => v.innerText);
135 expect(status).to.include(expectedStatus);
141 expectPlacementCount(serviceName: string, expectedCount: string) {
142 this.getTableCell(this.columnIndex.service_name, serviceName)
144 .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`)
146 const running = $ele.text().split(';');
147 expect(running).to.include(`count:${expectedCount}`);
151 checkExist(serviceName: string, exist: boolean) {
152 this.getTableCell(this.columnIndex.service_name, serviceName).should(($elements) => {
153 const services = $elements.map((_, el) => el.textContent).get();
155 expect(services).to.include(serviceName);
157 expect(services).to.not.include(serviceName);
162 deleteService(serviceName: string) {
163 const getRow = this.getTableCell.bind(this, this.columnIndex.service_name);
164 getRow(serviceName).click();
166 // Clicks on table Delete button
167 this.clickActionButton('delete');
170 cy.get('cd-modal .custom-control-label').click();
171 cy.contains('cd-modal button', 'Delete').click();
173 // Wait for modal to close
174 cy.get('cd-modal').should('not.exist');
175 this.checkExist(serviceName, false);
178 daemonAction(daemon: string, action: string) {
179 cy.get('cd-service-daemon-list').within(() => {
180 this.getTableRow(daemon).click();
181 this.clickActionButton(action);
183 // unselect it to avoid colliding with any other selection
184 // in different steps
185 this.getTableRow(daemon).click();