]>
Commit | Line | Data |
---|---|---|
b3b6e05e TL |
1 | import { PageHelper } from '../page-helper.po'; |
2 | ||
3 | const pages = { | |
4 | index: { url: '#/services', id: 'cd-services' }, | |
a4b75251 | 5 | create: { url: '#/services/(modal:create)', id: 'cd-service-form' } |
b3b6e05e TL |
6 | }; |
7 | ||
8 | export class ServicesPageHelper extends PageHelper { | |
9 | pages = pages; | |
10 | ||
11 | columnIndex = { | |
12 | service_name: 2, | |
13 | placement: 3, | |
14 | running: 4, | |
15 | size: 5, | |
16 | last_refresh: 6 | |
17 | }; | |
18 | ||
a4b75251 | 19 | serviceDetailColumnIndex = { |
33c7a0ef TL |
20 | daemonName: 2, |
21 | status: 4 | |
a4b75251 TL |
22 | }; |
23 | ||
b3b6e05e TL |
24 | check_for_service() { |
25 | this.getTableCount('total').should('not.be.eq', 0); | |
26 | } | |
27 | ||
28 | private selectServiceType(serviceType: string) { | |
29 | return this.selectOption('service_type', serviceType); | |
30 | } | |
31 | ||
a4b75251 TL |
32 | clickServiceTab(serviceName: string, tabName: string) { |
33 | this.getExpandCollapseElement(serviceName).click(); | |
34 | cy.get('cd-service-details').within(() => { | |
35 | this.getTab(tabName).click(); | |
36 | }); | |
37 | } | |
38 | ||
20effc67 TL |
39 | addService( |
40 | serviceType: string, | |
41 | exist?: boolean, | |
39ae355f | 42 | count = 1, |
20effc67 | 43 | snmpVersion?: string, |
2a845540 TL |
44 | snmpPrivProtocol?: boolean, |
45 | unmanaged = false | |
20effc67 | 46 | ) { |
b3b6e05e TL |
47 | cy.get(`${this.pages.create.id}`).within(() => { |
48 | this.selectServiceType(serviceType); | |
a4b75251 TL |
49 | switch (serviceType) { |
50 | case 'rgw': | |
51 | cy.get('#service_id').type('foo'); | |
39ae355f | 52 | unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(String(count)); |
a4b75251 TL |
53 | break; |
54 | ||
55 | case 'ingress': | |
2a845540 TL |
56 | if (unmanaged) { |
57 | cy.get('label[for=unmanaged]').click(); | |
58 | } | |
a4b75251 TL |
59 | this.selectOption('backend_service', 'rgw.foo'); |
60 | cy.get('#service_id').should('have.value', 'rgw.foo'); | |
20effc67 | 61 | cy.get('#virtual_ip').type('192.168.100.1/24'); |
a4b75251 TL |
62 | cy.get('#frontend_port').type('8081'); |
63 | cy.get('#monitor_port').type('8082'); | |
64 | break; | |
65 | ||
66 | case 'nfs': | |
67 | cy.get('#service_id').type('testnfs'); | |
39ae355f | 68 | unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(String(count)); |
a4b75251 | 69 | break; |
b3b6e05e | 70 | |
20effc67 TL |
71 | case 'snmp-gateway': |
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'); | |
76 | } else { | |
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'); | |
82 | } | |
83 | ||
84 | // Credentials | |
85 | cy.get('#snmp_v3_auth_username').type('test'); | |
86 | cy.get('#snmp_v3_auth_password').type('testpass'); | |
87 | } | |
88 | break; | |
89 | ||
90 | default: | |
91 | cy.get('#service_id').type('test'); | |
39ae355f | 92 | unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(String(count)); |
20effc67 TL |
93 | break; |
94 | } | |
95 | if (serviceType === 'snmp-gateway') { | |
96 | cy.get('cd-submit-button').dblclick(); | |
97 | } else { | |
98 | cy.get('cd-submit-button').click(); | |
99 | } | |
b3b6e05e TL |
100 | }); |
101 | if (exist) { | |
102 | cy.get('#service_id').should('have.class', 'ng-invalid'); | |
103 | } else { | |
104 | // back to service list | |
105 | cy.get(`${this.pages.index.id}`); | |
106 | } | |
107 | } | |
108 | ||
20effc67 | 109 | editService(name: string, daemonCount: string) { |
a4b75251 TL |
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'); | |
20effc67 | 114 | cy.get('#count').clear().type(daemonCount); |
a4b75251 TL |
115 | cy.get('cd-submit-button').click(); |
116 | }); | |
117 | } | |
118 | ||
20effc67 | 119 | checkServiceStatus(daemon: string, expectedStatus = 'running') { |
33c7a0ef TL |
120 | let daemonNameIndex = this.serviceDetailColumnIndex.daemonName; |
121 | let statusIndex = this.serviceDetailColumnIndex.status; | |
122 | ||
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)) { | |
129 | daemonNameIndex = 1; | |
130 | statusIndex = 3; | |
131 | } | |
132 | ||
133 | cy.get('cd-service-daemon-list').within(() => { | |
134 | this.getTableCell(daemonNameIndex, daemon, true) | |
135 | .parent() | |
136 | .find(`datatable-body-cell:nth-child(${statusIndex}) .badge`) | |
137 | .should(($ele) => { | |
138 | const status = $ele.toArray().map((v) => v.innerText); | |
139 | expect(status).to.include(expectedStatus); | |
140 | }); | |
141 | }); | |
20effc67 | 142 | }); |
a4b75251 TL |
143 | } |
144 | ||
145 | expectPlacementCount(serviceName: string, expectedCount: string) { | |
146 | this.getTableCell(this.columnIndex.service_name, serviceName) | |
147 | .parent() | |
148 | .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`) | |
149 | .should(($ele) => { | |
150 | const running = $ele.text().split(';'); | |
151 | expect(running).to.include(`count:${expectedCount}`); | |
152 | }); | |
153 | } | |
154 | ||
b3b6e05e TL |
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(); | |
158 | if (exist) { | |
159 | expect(services).to.include(serviceName); | |
160 | } else { | |
161 | expect(services).to.not.include(serviceName); | |
162 | } | |
163 | }); | |
164 | } | |
165 | ||
2a845540 TL |
166 | isUnmanaged(serviceName: string, unmanaged: boolean) { |
167 | this.getTableCell(this.columnIndex.service_name, serviceName) | |
168 | .parent() | |
169 | .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`) | |
170 | .should(($ele) => { | |
171 | const placement = $ele.text().split(';'); | |
172 | unmanaged | |
173 | ? expect(placement).to.include('unmanaged') | |
174 | : expect(placement).to.not.include('unmanaged'); | |
175 | }); | |
176 | } | |
177 | ||
a4b75251 | 178 | deleteService(serviceName: string) { |
b3b6e05e TL |
179 | const getRow = this.getTableCell.bind(this, this.columnIndex.service_name); |
180 | getRow(serviceName).click(); | |
181 | ||
182 | // Clicks on table Delete button | |
183 | this.clickActionButton('delete'); | |
184 | ||
185 | // Confirms deletion | |
186 | cy.get('cd-modal .custom-control-label').click(); | |
187 | cy.contains('cd-modal button', 'Delete').click(); | |
188 | ||
189 | // Wait for modal to close | |
190 | cy.get('cd-modal').should('not.exist'); | |
b3b6e05e TL |
191 | this.checkExist(serviceName, false); |
192 | } | |
20effc67 TL |
193 | |
194 | daemonAction(daemon: string, action: string) { | |
195 | cy.get('cd-service-daemon-list').within(() => { | |
196 | this.getTableRow(daemon).click(); | |
197 | this.clickActionButton(action); | |
198 | }); | |
199 | } | |
b3b6e05e | 200 | } |