1 import { PageHelper } from '../page-helper.po';
4 index: { url: '#/rgw/bucket', id: 'cd-rgw-bucket-list' },
5 create: { url: '#/rgw/bucket/create', id: 'cd-rgw-bucket-form' }
8 export class BucketsPageHelper extends PageHelper {
9 static readonly USERS = ['dashboard', 'testid'];
13 versioningStateEnabled = 'Enabled';
14 versioningStateSuspended = 'Suspended';
16 private selectOwner(owner: string) {
17 return this.selectOption('owner', owner);
20 private selectPlacementTarget(placementTarget: string) {
21 return this.selectOption('placement-target', placementTarget);
24 private selectLockMode(lockMode: string) {
25 return this.selectOption('lock_mode', lockMode);
28 @PageHelper.restrictTo(pages.create.url)
29 create(name: string, owner: string, placementTarget: string, isLocking = false) {
30 // Enter in bucket name
31 cy.get('#bid').type(name);
33 // Select bucket owner
34 this.selectOwner(owner);
35 cy.get('#owner').should('have.class', 'ng-valid');
37 // Select bucket placement target:
38 this.selectPlacementTarget(placementTarget);
39 cy.get('#placement-target').should('have.class', 'ng-valid');
42 cy.get('#lock_enabled').click({ force: true });
44 this.selectLockMode('Compliance');
45 cy.get('#lock_mode').should('have.class', 'ng-valid');
46 cy.get('#lock_retention_period_days').type('3');
49 // Click the create button and wait for bucket to be made
50 cy.contains('button', 'Create Bucket').click();
52 this.getFirstTableCell(name).should('exist');
55 @PageHelper.restrictTo(pages.create.url)
56 checkForDefaultEncryption() {
57 cy.get("cd-helper[aria-label='toggle encryption helper']").click();
58 cy.get("a[aria-label='click here']").click();
59 cy.get('cd-modal').within(() => {
60 cy.get('input[id=s3Enabled]').should('be.checked');
64 @PageHelper.restrictTo(pages.index.url)
65 edit(name: string, new_owner: string, isLocking = false) {
66 this.navigateEdit(name);
68 cy.get('input[name=placement-target]').should('have.value', 'default-placement');
69 this.selectOwner(new_owner);
71 // If object locking is enabled versioning shouldn't be visible
73 cy.get('input[id=versioning]').should('be.disabled');
74 cy.contains('button', 'Edit Bucket').click();
76 // wait to be back on buckets page with table visible and click
77 this.getExpandCollapseElement(name).click();
79 // check its details table for edited owner field
80 cy.get('.table.table-striped.table-bordered')
82 .should('contains.text', new_owner)
83 .as('bucketDataTable');
85 // Check versioning enabled:
86 cy.get('@bucketDataTable').find('tr').its(2).find('td').last().should('have.text', new_owner);
87 cy.get('@bucketDataTable').find('tr').its(11).find('td').last().as('versioningValueCell');
89 return cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
92 cy.get('input[id=versioning]').should('not.be.checked');
93 cy.get('label[for=versioning]').click();
94 cy.get('input[id=versioning]').should('be.checked');
96 cy.contains('button', 'Edit Bucket').click();
98 // wait to be back on buckets page with table visible and click
99 this.getExpandCollapseElement(name).click();
101 // check its details table for edited owner field
102 cy.get('.table.table-striped.table-bordered')
104 .should('contains.text', new_owner)
105 .as('bucketDataTable');
107 // Check versioning enabled:
108 cy.get('@bucketDataTable').find('tr').its(2).find('td').last().should('have.text', new_owner);
109 cy.get('@bucketDataTable').find('tr').its(11).find('td').last().as('versioningValueCell');
111 cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
113 // Disable versioning:
114 this.navigateEdit(name);
116 cy.get('label[for=versioning]').click();
117 cy.get('input[id=versioning]').should('not.be.checked');
118 cy.contains('button', 'Edit Bucket').click();
120 // Check versioning suspended:
121 this.getExpandCollapseElement(name).click();
123 return cy.get('@versioningValueCell').should('have.text', this.versioningStateSuspended);
126 testInvalidCreate() {
127 this.navigateTo('create');
128 cy.get('#bid').as('nameInputField'); // Grabs name box field
130 // Gives an invalid name (too short), then waits for dashboard to determine validity
131 cy.get('@nameInputField').type('rq');
133 cy.contains('button', 'Create Bucket').click(); // To trigger a validation
135 // Waiting for website to decide if name is valid or not
136 // Check that name input field was marked invalid in the css
137 cy.get('@nameInputField')
138 .should('not.have.class', 'ng-pending')
139 .and('have.class', 'ng-invalid');
141 // Check that error message was printed under name input field
142 cy.get('#bid + .invalid-feedback').should(
144 'Bucket names must be 3 to 63 characters long.'
147 // Test invalid owner input
148 // select some valid option. The owner drop down error message will not appear unless a valid user was selected at
149 // one point before the invalid placeholder user is selected.
150 this.selectOwner(BucketsPageHelper.USERS[1]);
152 // select the first option, which is invalid because it is a placeholder
153 this.selectOwner('-- Select a user --');
155 cy.get('@nameInputField').click();
157 // Check that owner drop down field was marked invalid in the css
158 cy.get('#owner').should('have.class', 'ng-invalid');
160 // Check that error message was printed under owner drop down field
161 cy.get('#owner + .invalid-feedback').should('have.text', 'This field is required.');
163 // Check invalid placement target input
164 this.selectOwner(BucketsPageHelper.USERS[1]);
165 // The drop down error message will not appear unless a valid option is previsously selected.
166 this.selectPlacementTarget('default-placement');
167 this.selectPlacementTarget('-- Select a placement target --');
168 cy.get('@nameInputField').click(); // Trigger validation
169 cy.get('#placement-target').should('have.class', 'ng-invalid');
170 cy.get('#placement-target + .invalid-feedback').should('have.text', 'This field is required.');
172 // Clicks the Create Bucket button but the page doesn't move.
173 // Done by testing for the breadcrumb
174 cy.contains('button', 'Create Bucket').click(); // Clicks Create Bucket button
175 this.expectBreadcrumbText('Create');
176 // content in fields seems to subsist through tests if not cleared, so it is cleared
177 cy.get('@nameInputField').clear();
178 return cy.contains('button', 'Cancel').click();
181 testInvalidEdit(name: string) {
182 this.navigateEdit(name);
184 cy.get('input[id=versioning]').should('exist').and('not.be.checked');
186 // Chooses 'Select a user' rather than a valid owner on Edit Bucket page
187 // and checks if it's an invalid input
189 // select the first option, which is invalid because it is a placeholder
190 this.selectOwner('-- Select a user --');
192 cy.contains('button', 'Edit Bucket').click();
194 // Check that owner drop down field was marked invalid in the css
195 cy.get('#owner').should('have.class', 'ng-invalid');
197 // Check that error message was printed under owner drop down field
198 cy.get('#owner + .invalid-feedback').should('have.text', 'This field is required.');
200 this.expectBreadcrumbText('Edit');