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.index.url)
56 edit(name: string, new_owner: string, isLocking = false) {
57 this.navigateEdit(name);
59 cy.get('input[name=placement-target]').should('have.value', 'default-placement');
60 this.selectOwner(new_owner);
62 // If object locking is enabled versioning shouldn't be visible
64 cy.get('input[id=versioning]').should('be.disabled');
65 cy.contains('button', 'Edit Bucket').click();
67 // wait to be back on buckets page with table visible and click
68 this.getExpandCollapseElement(name).click();
70 // check its details table for edited owner field
71 cy.get('.table.table-striped.table-bordered')
73 .should('contains.text', new_owner)
74 .as('bucketDataTable');
76 // Check versioning enabled:
77 cy.get('@bucketDataTable').find('tr').its(2).find('td').last().should('have.text', new_owner);
78 cy.get('@bucketDataTable').find('tr').its(11).find('td').last().as('versioningValueCell');
80 return cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
83 cy.get('input[id=versioning]').should('not.be.checked');
84 cy.get('label[for=versioning]').click();
85 cy.get('input[id=versioning]').should('be.checked');
87 cy.contains('button', 'Edit Bucket').click();
89 // wait to be back on buckets page with table visible and click
90 this.getExpandCollapseElement(name).click();
92 // check its details table for edited owner field
93 cy.get('.table.table-striped.table-bordered')
95 .should('contains.text', new_owner)
96 .as('bucketDataTable');
98 // Check versioning enabled:
99 cy.get('@bucketDataTable').find('tr').its(2).find('td').last().should('have.text', new_owner);
100 cy.get('@bucketDataTable').find('tr').its(11).find('td').last().as('versioningValueCell');
102 cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
104 // Disable versioning:
105 this.navigateEdit(name);
107 cy.get('label[for=versioning]').click();
108 cy.get('input[id=versioning]').should('not.be.checked');
109 cy.contains('button', 'Edit Bucket').click();
111 // Check versioning suspended:
112 this.getExpandCollapseElement(name).click();
114 return cy.get('@versioningValueCell').should('have.text', this.versioningStateSuspended);
117 testInvalidCreate() {
118 this.navigateTo('create');
119 cy.get('#bid').as('nameInputField'); // Grabs name box field
121 // Gives an invalid name (too short), then waits for dashboard to determine validity
122 cy.get('@nameInputField').type('rq');
124 cy.contains('button', 'Create Bucket').click(); // To trigger a validation
126 // Waiting for website to decide if name is valid or not
127 // Check that name input field was marked invalid in the css
128 cy.get('@nameInputField')
129 .should('not.have.class', 'ng-pending')
130 .and('have.class', 'ng-invalid');
132 // Check that error message was printed under name input field
133 cy.get('#bid + .invalid-feedback').should(
135 'Bucket names must be 3 to 63 characters long.'
138 // Test invalid owner input
139 // select some valid option. The owner drop down error message will not appear unless a valid user was selected at
140 // one point before the invalid placeholder user is selected.
141 this.selectOwner(BucketsPageHelper.USERS[1]);
143 // select the first option, which is invalid because it is a placeholder
144 this.selectOwner('-- Select a user --');
146 cy.get('@nameInputField').click();
148 // Check that owner drop down field was marked invalid in the css
149 cy.get('#owner').should('have.class', 'ng-invalid');
151 // Check that error message was printed under owner drop down field
152 cy.get('#owner + .invalid-feedback').should('have.text', 'This field is required.');
154 // Check invalid placement target input
155 this.selectOwner(BucketsPageHelper.USERS[1]);
156 // The drop down error message will not appear unless a valid option is previsously selected.
157 this.selectPlacementTarget('default-placement');
158 this.selectPlacementTarget('-- Select a placement target --');
159 cy.get('@nameInputField').click(); // Trigger validation
160 cy.get('#placement-target').should('have.class', 'ng-invalid');
161 cy.get('#placement-target + .invalid-feedback').should('have.text', 'This field is required.');
163 // Clicks the Create Bucket button but the page doesn't move.
164 // Done by testing for the breadcrumb
165 cy.contains('button', 'Create Bucket').click(); // Clicks Create Bucket button
166 this.expectBreadcrumbText('Create');
167 // content in fields seems to subsist through tests if not cleared, so it is cleared
168 cy.get('@nameInputField').clear();
169 return cy.contains('button', 'Cancel').click();
172 testInvalidEdit(name: string) {
173 this.navigateEdit(name);
175 cy.get('input[id=versioning]').should('exist').and('not.be.checked');
177 // Chooses 'Select a user' rather than a valid owner on Edit Bucket page
178 // and checks if it's an invalid input
180 // select the first option, which is invalid because it is a placeholder
181 this.selectOwner('-- Select a user --');
183 cy.contains('button', 'Edit Bucket').click();
185 // Check that owner drop down field was marked invalid in the css
186 cy.get('#owner').should('have.class', 'ng-invalid');
188 // Check that error message was printed under owner drop down field
189 cy.get('#owner + .invalid-feedback').should('have.text', 'This field is required.');
191 this.expectBreadcrumbText('Edit');