]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/buckets.po.ts
buildsys: change download over to reef release
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / integration / rgw / buckets.po.ts
1 import { PageHelper } from '../page-helper.po';
2
3 const pages = {
4 index: { url: '#/rgw/bucket', id: 'cd-rgw-bucket-list' },
5 create: { url: '#/rgw/bucket/create', id: 'cd-rgw-bucket-form' }
6 };
7
8 export class BucketsPageHelper extends PageHelper {
9 static readonly USERS = ['dashboard', 'testid'];
10
11 pages = pages;
12
13 versioningStateEnabled = 'Enabled';
14 versioningStateSuspended = 'Suspended';
15
16 private selectOwner(owner: string) {
17 return this.selectOption('owner', owner);
18 }
19
20 private selectPlacementTarget(placementTarget: string) {
21 return this.selectOption('placement-target', placementTarget);
22 }
23
24 private selectLockMode(lockMode: string) {
25 return this.selectOption('lock_mode', lockMode);
26 }
27
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);
32
33 // Select bucket owner
34 this.selectOwner(owner);
35 cy.get('#owner').should('have.class', 'ng-valid');
36
37 // Select bucket placement target:
38 this.selectPlacementTarget(placementTarget);
39 cy.get('#placement-target').should('have.class', 'ng-valid');
40
41 if (isLocking) {
42 cy.get('#lock_enabled').click({ force: true });
43 // Select lock mode:
44 this.selectLockMode('Compliance');
45 cy.get('#lock_mode').should('have.class', 'ng-valid');
46 cy.get('#lock_retention_period_days').type('3');
47 }
48
49 // Click the create button and wait for bucket to be made
50 cy.contains('button', 'Create Bucket').click();
51
52 this.getFirstTableCell(name).should('exist');
53 }
54
55 @PageHelper.restrictTo(pages.index.url)
56 edit(name: string, new_owner: string, isLocking = false) {
57 this.navigateEdit(name);
58
59 cy.get('input[name=placement-target]').should('have.value', 'default-placement');
60 this.selectOwner(new_owner);
61
62 // If object locking is enabled versioning shouldn't be visible
63 if (isLocking) {
64 cy.get('input[id=versioning]').should('be.disabled');
65 cy.contains('button', 'Edit Bucket').click();
66
67 // wait to be back on buckets page with table visible and click
68 this.getExpandCollapseElement(name).click();
69
70 // check its details table for edited owner field
71 cy.get('.table.table-striped.table-bordered')
72 .first()
73 .should('contains.text', new_owner)
74 .as('bucketDataTable');
75
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');
79
80 return cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
81 }
82 // Enable versioning
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');
86
87 cy.contains('button', 'Edit Bucket').click();
88
89 // wait to be back on buckets page with table visible and click
90 this.getExpandCollapseElement(name).click();
91
92 // check its details table for edited owner field
93 cy.get('.table.table-striped.table-bordered')
94 .first()
95 .should('contains.text', new_owner)
96 .as('bucketDataTable');
97
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');
101
102 cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
103
104 // Disable versioning:
105 this.navigateEdit(name);
106
107 cy.get('label[for=versioning]').click();
108 cy.get('input[id=versioning]').should('not.be.checked');
109 cy.contains('button', 'Edit Bucket').click();
110
111 // Check versioning suspended:
112 this.getExpandCollapseElement(name).click();
113
114 return cy.get('@versioningValueCell').should('have.text', this.versioningStateSuspended);
115 }
116
117 testInvalidCreate() {
118 this.navigateTo('create');
119 cy.get('#bid').as('nameInputField'); // Grabs name box field
120
121 // Gives an invalid name (too short), then waits for dashboard to determine validity
122 cy.get('@nameInputField').type('rq');
123
124 cy.contains('button', 'Create Bucket').click(); // To trigger a validation
125
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');
131
132 // Check that error message was printed under name input field
133 cy.get('#bid + .invalid-feedback').should(
134 'have.text',
135 'Bucket names must be 3 to 63 characters long.'
136 );
137
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]);
142
143 // select the first option, which is invalid because it is a placeholder
144 this.selectOwner('-- Select a user --');
145
146 cy.get('@nameInputField').click();
147
148 // Check that owner drop down field was marked invalid in the css
149 cy.get('#owner').should('have.class', 'ng-invalid');
150
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.');
153
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.');
162
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();
170 }
171
172 testInvalidEdit(name: string) {
173 this.navigateEdit(name);
174
175 cy.get('input[id=versioning]').should('exist').and('not.be.checked');
176
177 // Chooses 'Select a user' rather than a valid owner on Edit Bucket page
178 // and checks if it's an invalid input
179
180 // select the first option, which is invalid because it is a placeholder
181 this.selectOwner('-- Select a user --');
182
183 cy.contains('button', 'Edit Bucket').click();
184
185 // Check that owner drop down field was marked invalid in the css
186 cy.get('#owner').should('have.class', 'ng-invalid');
187
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.');
190
191 this.expectBreadcrumbText('Edit');
192 }
193 }