|
| 1 | +import { PageHelper } from '../page-helper.po'; |
| 2 | + |
| 3 | +const pages = { |
| 4 | + index: { url: '#/rgw/accounts', id: 'cd-rgw-user-accounts' }, |
| 5 | + create: { url: '#/rgw/accounts/create', id: 'cd-rgw-user-accounts-form' } |
| 6 | +}; |
| 7 | + |
| 8 | +export class AccountsPageHelper extends PageHelper { |
| 9 | + pages = pages; |
| 10 | + |
| 11 | + columnIndex = { |
| 12 | + tenant: 2, |
| 13 | + account_id: 3, |
| 14 | + email: 4, |
| 15 | + max_users: 5, |
| 16 | + max_roles: 6, |
| 17 | + max_groups: 7, |
| 18 | + max_buckets: 8, |
| 19 | + max_access_keys: 9 |
| 20 | + }; |
| 21 | + |
| 22 | + @PageHelper.restrictTo(pages.create.url) |
| 23 | + create(account: { name: string; email: string; tenant?: string }) { |
| 24 | + // Enter in account name |
| 25 | + cy.get('#acc_name').type(account.name); |
| 26 | + |
| 27 | + if (account.tenant) { |
| 28 | + // Enter tenant |
| 29 | + cy.get('#tenant').type(account.tenant); |
| 30 | + } |
| 31 | + |
| 32 | + // Enter email |
| 33 | + cy.get('#email').type(account.email); |
| 34 | + |
| 35 | + // Enter max buckets |
| 36 | + cy.get('input#max_buckets').should('exist').should('have.value', '1000'); |
| 37 | + |
| 38 | + cy.get('input#max_users').should('exist').should('have.value', '1000'); |
| 39 | + |
| 40 | + cy.get('input#max_roles').should('exist').should('have.value', '1000'); |
| 41 | + |
| 42 | + cy.get('input#max_groups').should('exist').should('have.value', '1000'); |
| 43 | + |
| 44 | + cy.get('input#max_access_keys').should('exist').should('have.value', '4'); |
| 45 | + |
| 46 | + // cy.find('cds-checkbox [type="checkbox"]') |
| 47 | + cy.get('input#bucket_checkbox_input').check({ force: true }); |
| 48 | + |
| 49 | + cy.get('input#account_checkbox_input').check({ force: true }); |
| 50 | + |
| 51 | + // Click the create button and wait for account to be made |
| 52 | + cy.contains('button', 'Create Account').click(); |
| 53 | + |
| 54 | + this.getFirstTableCell(account.name).should('have.text', account.name); |
| 55 | + this.getTableRow(account.name).within(() => { |
| 56 | + cy.get('td').eq(this.columnIndex.tenant).should('have.text', account.tenant); |
| 57 | + cy.get('td').eq(this.columnIndex.account_id).should('not.be.empty'); |
| 58 | + cy.get('td').eq(this.columnIndex.email).should('have.text', account.email); |
| 59 | + cy.get('td').eq(this.columnIndex.max_users).should('have.text', 1000); |
| 60 | + cy.get('td').eq(this.columnIndex.max_roles).should('have.text', 1000); |
| 61 | + cy.get('td').eq(this.columnIndex.max_groups).should('have.text', 1000); |
| 62 | + cy.get('td').eq(this.columnIndex.max_buckets).should('have.text', 1000); |
| 63 | + cy.get('td').eq(this.columnIndex.max_access_keys).should('have.text', 4); |
| 64 | + }); |
| 65 | + |
| 66 | + this.getExpandCollapseElement(account.name).click().wait(1000); |
| 67 | + |
| 68 | + cy.get('[data-testid="datatable-row-detail"]').first().as('accountDetailsTable'); |
| 69 | + cy.get('@accountDetailsTable').find('legend').its(0).as('accountQuota'); |
| 70 | + cy.get('@accountQuota').should('have.text', 'Account quota'); |
| 71 | + cy.get('@accountDetailsTable').find('cd-table-key-value').its(0).as('accountQuotaTable'); |
| 72 | + cy.get('@accountQuotaTable') |
| 73 | + .find('tbody tr') |
| 74 | + .first() |
| 75 | + .find('td') |
| 76 | + .last() |
| 77 | + .should('have.text', 'Yes'); |
| 78 | + |
| 79 | + cy.get('@accountDetailsTable').find('legend').its(1).as('bucketQuota'); |
| 80 | + cy.get('@bucketQuota').should('have.text', 'Bucket quota'); |
| 81 | + cy.get('@accountDetailsTable').find('cd-table-key-value').its(1).as('bucketQuotaTable'); |
| 82 | + cy.get('@bucketQuotaTable') |
| 83 | + .find('tbody tr') |
| 84 | + .first() |
| 85 | + .find('td') |
| 86 | + .last() |
| 87 | + .should('have.text', 'Yes'); |
| 88 | + } |
| 89 | + |
| 90 | + @PageHelper.restrictTo(pages.create.url) |
| 91 | + edit(account: { |
| 92 | + name: string; |
| 93 | + tenant: string; |
| 94 | + email: string; |
| 95 | + max_buckets: string; |
| 96 | + max_groups: string; |
| 97 | + max_access_keys: string; |
| 98 | + }) { |
| 99 | + this.navigateEdit(account.name, false, false, null); |
| 100 | + // Enter in account name |
| 101 | + cy.get('#acc_name').clear().type(account.name); |
| 102 | + // Enter tenant |
| 103 | + cy.get('#tenant').should('be.disabled'); |
| 104 | + // Enter email |
| 105 | + cy.get('#email').clear().type(account.email); |
| 106 | + |
| 107 | + // Enter max buckets |
| 108 | + this.selectOption('max_buckets_mode', 'Custom'); |
| 109 | + cy.get('input#max_buckets').click().clear().type(account.max_buckets); |
| 110 | + |
| 111 | + this.selectOption('max_users_mode', 'Unlimited'); |
| 112 | + |
| 113 | + this.selectOption('max_roles_mode', 'Disabled'); |
| 114 | + |
| 115 | + cy.get('input#max_groups').click().clear().type(account.max_groups); |
| 116 | + |
| 117 | + cy.get('input#max_access_keys').click().clear().type(account.max_access_keys); |
| 118 | + |
| 119 | + cy.get('input#bucket_checkbox_input').should('be.checked'); |
| 120 | + cy.get('input#bucket_quota_max_size').clear().type('1234'); |
| 121 | + cy.get('input#bucketunlimitedObjects_checkbox_input').uncheck({ force: true }); |
| 122 | + cy.get('input#bucket_quota_max_objects').clear().type('200'); |
| 123 | + |
| 124 | + cy.get('input#account_checkbox_input').should('be.checked'); |
| 125 | + cy.get('input#account_quota_max_size').clear().type('1234'); |
| 126 | + cy.get('input#accountunlimitedObjects_checkbox_input').uncheck({ force: true }); |
| 127 | + cy.get('input#account_quota_max_objects').clear().type('200'); |
| 128 | + |
| 129 | + // Click the create button and wait for account to be made |
| 130 | + cy.contains('button', 'Edit Account').click(); |
| 131 | + |
| 132 | + this.getTableRow(account.name).within(() => { |
| 133 | + cy.get('td').eq(this.columnIndex.tenant).should('have.text', account.tenant); |
| 134 | + cy.get('td').eq(this.columnIndex.account_id).should('not.be.empty'); |
| 135 | + cy.get('td').eq(this.columnIndex.email).should('have.text', account.email); |
| 136 | + cy.get('td').eq(this.columnIndex.max_users).should('have.text', 'Unlimited'); |
| 137 | + cy.get('td').eq(this.columnIndex.max_roles).should('have.text', 'Disabled'); |
| 138 | + cy.get('td').eq(this.columnIndex.max_groups).should('have.text', account.max_groups); |
| 139 | + cy.get('td').eq(this.columnIndex.max_buckets).should('have.text', account.max_buckets); |
| 140 | + cy.get('td') |
| 141 | + .eq(this.columnIndex.max_access_keys) |
| 142 | + .should('have.text', account.max_access_keys); |
| 143 | + }); |
| 144 | + this.getExpandCollapseElement(account.name).click().wait(1000); |
| 145 | + |
| 146 | + cy.get('[data-testid="datatable-row-detail"]').first().as('accountDetailsTable'); |
| 147 | + cy.get('@accountDetailsTable').find('legend').eq(0).as('accountQuota'); |
| 148 | + cy.get('@accountQuota').should('have.text', 'Account quota'); |
| 149 | + cy.get('@accountDetailsTable').find('cd-table-key-value').eq(0).as('accountQuotaTable'); |
| 150 | + cy.get('@accountQuotaTable').find('tbody tr').should('have.length', 3); |
| 151 | + cy.get('@accountQuotaTable') |
| 152 | + .find('tbody tr') |
| 153 | + .first() |
| 154 | + .find('td') |
| 155 | + .last() |
| 156 | + .should('have.text', 'Yes'); |
| 157 | + |
| 158 | + cy.get('@accountQuotaTable') |
| 159 | + .find('tbody tr') |
| 160 | + .eq(1) |
| 161 | + .within(() => { |
| 162 | + cy.get('td').first().should('have.text', 'Maximum objects'); |
| 163 | + cy.get('td').last().should('have.text', '200'); |
| 164 | + }); |
| 165 | + |
| 166 | + cy.get('@accountQuotaTable') |
| 167 | + .find('tbody tr') |
| 168 | + .eq(2) |
| 169 | + .within(() => { |
| 170 | + cy.get('td').first().should('have.text', 'Maximum size'); |
| 171 | + cy.get('td').last().should('have.text', '1.2 GiB'); |
| 172 | + }); |
| 173 | + |
| 174 | + cy.get('@accountDetailsTable').find('legend').eq(1).as('bucketQuota'); |
| 175 | + cy.get('@bucketQuota').should('have.text', 'Bucket quota'); |
| 176 | + cy.get('@accountDetailsTable').find('cd-table-key-value').eq(1).as('bucketQuotaTable'); |
| 177 | + cy.get('@bucketQuotaTable') |
| 178 | + .find('tbody tr') |
| 179 | + .first() |
| 180 | + .find('td') |
| 181 | + .last() |
| 182 | + .should('have.text', 'Yes'); |
| 183 | + |
| 184 | + cy.get('@bucketQuotaTable') |
| 185 | + .find('tbody tr') |
| 186 | + .eq(1) |
| 187 | + .within(() => { |
| 188 | + cy.get('td').first().should('have.text', 'Maximum objects'); |
| 189 | + cy.get('td').last().should('have.text', 200); |
| 190 | + }); |
| 191 | + |
| 192 | + cy.get('@bucketQuotaTable') |
| 193 | + .find('tbody tr') |
| 194 | + .eq(2) |
| 195 | + .within(() => { |
| 196 | + cy.get('td').first().should('have.text', 'Maximum size'); |
| 197 | + cy.get('td').last().should('have.text', '1.2 GiB'); |
| 198 | + }); |
| 199 | + } |
| 200 | + |
| 201 | + invalidCreate() { |
| 202 | + // Enter in account name |
| 203 | + cy.get('#acc_name').type('testAccName'); |
| 204 | + |
| 205 | + // Enter email |
| 206 | + cy.get('#email') |
| 207 | + .type('@test') |
| 208 | + .blur() |
| 209 | + .should('not.have.class', 'ng-pending') |
| 210 | + .should('have.class', 'ng-invalid'); |
| 211 | + |
| 212 | + cy.get('cds-text-label[for=email]') |
| 213 | + .find('.cds--form-requirement') |
| 214 | + .should('have.text', ' Please enter a valid email '); |
| 215 | + |
| 216 | + cy.get('input#max_buckets').click().clear().type('0').blur(); |
| 217 | + |
| 218 | + cy.get('label[for=max_buckets]') |
| 219 | + .parent() |
| 220 | + .parent() |
| 221 | + .should('not.have.class', 'ng-pending') |
| 222 | + .should('have.class', 'ng-invalid'); |
| 223 | + |
| 224 | + cy.get('label[for=max_buckets]') |
| 225 | + .parent() |
| 226 | + .parent() |
| 227 | + .find('.cds--form-requirement') |
| 228 | + .should('have.text', 'Enter number greater than 0'); |
| 229 | + |
| 230 | + cy.get('input#bucket_checkbox_input').check({ force: true }); |
| 231 | + cy.get('input#bucketunlimitedObjects_checkbox_input').uncheck({ force: true }); |
| 232 | + cy.get('input#bucket_quota_max_objects').clear().type('-1').blur({ force: true }); |
| 233 | + cy.get('input#bucket_quota_max_objects') |
| 234 | + .should('not.have.class', 'ng-pending') |
| 235 | + .should('have.class', 'ng-invalid'); |
| 236 | + } |
| 237 | + |
| 238 | + invalidEdit() { |
| 239 | + this.create({ name: 'test', tenant: 'new', email: 'test@test' }); |
| 240 | + this.navigateEdit('test', false, false, null); |
| 241 | + cy.get('#tenant').should('be.disabled'); |
| 242 | + // Enter email |
| 243 | + cy.get('#email') |
| 244 | + .type('@test') |
| 245 | + .blur() |
| 246 | + .should('not.have.class', 'ng-pending') |
| 247 | + .should('have.class', 'ng-invalid'); |
| 248 | + |
| 249 | + cy.get('cds-text-label[for=email]') |
| 250 | + .find('.cds--form-requirement') |
| 251 | + .should('have.text', ' Please enter a valid email '); |
| 252 | + |
| 253 | + cy.get('input#max_buckets').click().clear().type('0').blur(); |
| 254 | + |
| 255 | + cy.get('label[for=max_buckets]') |
| 256 | + .parent() |
| 257 | + .parent() |
| 258 | + .should('not.have.class', 'ng-pending') |
| 259 | + .should('have.class', 'ng-invalid'); |
| 260 | + |
| 261 | + cy.get('label[for=max_buckets]') |
| 262 | + .parent() |
| 263 | + .parent() |
| 264 | + .find('.cds--form-requirement') |
| 265 | + .should('have.text', 'Enter number greater than 0'); |
| 266 | + |
| 267 | + cy.get('input#bucket_checkbox_input').should('be.checked'); |
| 268 | + cy.get('input#bucket_quota_max_size').clear().type('0').blur(); |
| 269 | + cy.get('label[for=bucket_quota_max_size]') |
| 270 | + .parent() |
| 271 | + .parent() |
| 272 | + .find('.cds--form-requirement') |
| 273 | + .should('have.text', 'Enter a valid value.'); |
| 274 | + |
| 275 | + this.navigateTo(); |
| 276 | + this.delete('test', null, null, true, false, false, false); |
| 277 | + } |
| 278 | + |
| 279 | + // happens when users are linked to account, fn() called from users-e2e |
| 280 | + invalidDelete(account_name: string, action: string) { |
| 281 | + cy.intercept('DELETE', `/api/rgw/accounts/*`, { |
| 282 | + statusCode: 500, |
| 283 | + body: { error: 'Internal Server Error' } |
| 284 | + }).as('apiRequest'); |
| 285 | + |
| 286 | + const actionUpperCase = action.charAt(0).toUpperCase() + action.slice(1); |
| 287 | + this.clickRowActionButton(account_name, action); |
| 288 | + cy.get('[aria-label="confirmation"]').click({ force: true }); |
| 289 | + cy.get('cds-modal button').contains(actionUpperCase).click({ force: true }); |
| 290 | + cy.wait('@apiRequest').then((interception: any) => { |
| 291 | + cy.log('Intercepted request:', interception); |
| 292 | + }); |
| 293 | + // modal should not close as API should be failing |
| 294 | + cy.get('cds-modal').should('exist'); |
| 295 | + cy.get('@apiRequest').its('response.statusCode').should('eq', 500); |
| 296 | + } |
| 297 | +} |
0 commit comments