]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/rgw/buckets.po.ts
7d0b46c256e721cd222e8127442f7664d330a3c3
[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 pages = pages;
10
11 versioningStateEnabled = 'Enabled';
12 versioningStateSuspended = 'Suspended';
13
14 private selectOwner(owner: string) {
15 return this.selectOption('owner', owner);
16 }
17
18 private selectPlacementTarget(placementTarget: string) {
19 return this.selectOption('placement-target', placementTarget);
20 }
21
22 @PageHelper.restrictTo(pages.create.url)
23 create(name: string, owner: string, placementTarget: string) {
24 // Enter in bucket name
25 cy.get('#bid').type(name);
26
27 // Select bucket owner
28 this.selectOwner(owner);
29 cy.get('#owner').should('have.class', 'ng-valid');
30
31 // Select bucket placement target:
32 this.selectPlacementTarget(placementTarget);
33 cy.get('#placement-target').should('have.class', 'ng-valid');
34
35 // Click the create button and wait for bucket to be made
36 cy.contains('button', 'Create Bucket').click();
37
38 this.getFirstTableCell(name).should('exist');
39 }
40
41 @PageHelper.restrictTo(pages.index.url)
42 edit(name: string, new_owner: string) {
43 this.navigateEdit(name);
44
45 cy.get('input[name=placement-target]').should('have.value', 'default-placement');
46 this.selectOwner(new_owner);
47
48 // Enable versioning
49 cy.get('input[id=versioning]').should('not.be.checked');
50 cy.get('label[for=versioning]').click();
51 cy.get('input[id=versioning]').should('be.checked');
52
53 cy.contains('button', 'Edit Bucket').click();
54
55 // wait to be back on buckets page with table visible and click
56 this.getExpandCollapseElement(name).click();
57
58 // check its details table for edited owner field
59 cy.get('.table.table-striped.table-bordered')
60 .first()
61 .should('contains.text', new_owner)
62 .as('bucketDataTable');
63
64 // Check versioning enabled:
65 cy.get('@bucketDataTable').find('tr').its(2).find('td').last().should('have.text', new_owner);
66 cy.get('@bucketDataTable').find('tr').its(11).find('td').last().as('versioningValueCell');
67
68 cy.get('@versioningValueCell').should('have.text', this.versioningStateEnabled);
69
70 // Disable versioning:
71 this.navigateEdit(name);
72
73 cy.get('label[for=versioning]').click();
74 cy.get('input[id=versioning]').should('not.be.checked');
75 cy.contains('button', 'Edit Bucket').click();
76
77 // Check versioning suspended:
78 this.getExpandCollapseElement(name).click();
79
80 return cy.get('@versioningValueCell').should('have.text', this.versioningStateSuspended);
81 }
82
83 testInvalidCreate() {
84 this.navigateTo('create');
85 cy.get('#bid').as('nameInputField'); // Grabs name box field
86
87 // Gives an invalid name (too short), then waits for dashboard to determine validity
88 cy.get('@nameInputField').type('rq');
89
90 cy.contains('button', 'Create Bucket').click(); // To trigger a validation
91
92 // Waiting for website to decide if name is valid or not
93 // Check that name input field was marked invalid in the css
94 cy.get('@nameInputField')
95 .should('not.have.class', 'ng-pending')
96 .and('have.class', 'ng-invalid');
97
98 // Check that error message was printed under name input field
99 cy.get('#bid + .invalid-feedback').should('have.text', 'The value is not valid.');
100
101 // Test invalid owner input
102 // select some valid option. The owner drop down error message will not appear unless a valid user was selected at
103 // one point before the invalid placeholder user is selected.
104 this.selectOwner('dev');
105
106 // select the first option, which is invalid because it is a placeholder
107 this.selectOwner('-- Select a user --');
108
109 cy.get('@nameInputField').click();
110
111 // Check that owner drop down field was marked invalid in the css
112 cy.get('#owner').should('have.class', 'ng-invalid');
113
114 // Check that error message was printed under owner drop down field
115 cy.get('#owner + .invalid-feedback').should('have.text', 'This field is required.');
116
117 // Check invalid placement target input
118 this.selectOwner('dev');
119 // The drop down error message will not appear unless a valid option is previsously selected.
120 this.selectPlacementTarget('default-placement');
121 this.selectPlacementTarget('-- Select a placement target --');
122 cy.get('@nameInputField').click(); // Trigger validation
123 cy.get('#placement-target').should('have.class', 'ng-invalid');
124 cy.get('#placement-target + .invalid-feedback').should('have.text', 'This field is required.');
125
126 // Clicks the Create Bucket button but the page doesn't move.
127 // Done by testing for the breadcrumb
128 cy.contains('button', 'Create Bucket').click(); // Clicks Create Bucket button
129 this.expectBreadcrumbText('Create');
130 // content in fields seems to subsist through tests if not cleared, so it is cleared
131 cy.get('@nameInputField').clear();
132 return cy.contains('button', 'Cancel').click();
133 }
134
135 testInvalidEdit(name: string) {
136 this.navigateEdit(name);
137
138 cy.get('input[id=versioning]').should('exist').and('not.be.checked');
139
140 // Chooses 'Select a user' rather than a valid owner on Edit Bucket page
141 // and checks if it's an invalid input
142
143 // select the first option, which is invalid because it is a placeholder
144 this.selectOwner('-- Select a user --');
145
146 cy.contains('button', 'Edit Bucket').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 this.expectBreadcrumbText('Edit');
155 }
156 }