]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { by, element } from 'protractor'; |
2 | import { PageHelper } from '../page-helper.po'; | |
3 | ||
4 | const pages = { | |
5 | index: '/#/rgw/bucket', | |
6 | create: '/#/rgw/bucket/create' | |
7 | }; | |
8 | ||
9 | export class BucketsPageHelper extends PageHelper { | |
10 | pages = pages; | |
11 | versioningStateEnabled = 'Enabled'; | |
12 | versioningStateSuspended = 'Suspended'; | |
13 | ||
14 | private async selectOwner(owner: string) { | |
15 | return this.selectOption('owner', owner); | |
16 | } | |
17 | ||
18 | private async selectPlacementTarget(placementTarget: string) { | |
19 | return this.selectOption('placement-target', placementTarget); | |
20 | } | |
21 | ||
22 | /** | |
23 | * TODO add check to verify the existance of the bucket! | |
24 | * TODO let it print a meaningful error message (for devs) if it does not exist! | |
25 | */ | |
26 | @PageHelper.restrictTo(pages.create) | |
27 | async create(name: string, owner: string, placementTarget: string) { | |
28 | // Enter in bucket name | |
29 | await element(by.id('bid')).sendKeys(name); | |
30 | ||
31 | // Select bucket owner | |
32 | await this.selectOwner(owner); | |
33 | await expect(element(by.id('owner')).getAttribute('class')).toContain('ng-valid'); | |
34 | ||
35 | // Select bucket placement target: | |
36 | await this.selectPlacementTarget(placementTarget); | |
37 | await expect(element(by.id('placement-target')).getAttribute('class')).toContain('ng-valid'); | |
38 | ||
39 | // Click the create button and wait for bucket to be made | |
40 | const createButton = element(by.cssContainingText('button', 'Create Bucket')); | |
41 | await createButton.click(); | |
42 | ||
43 | return this.waitPresence( | |
44 | this.getFirstTableCellWithText(name), | |
45 | 'Timed out waiting for bucket creation' | |
46 | ); | |
47 | } | |
48 | ||
49 | @PageHelper.restrictTo(pages.index) | |
50 | async edit(name: string, new_owner: string) { | |
51 | await this.waitClickableAndClick(this.getFirstTableCellWithText(name)); // wait for table to load and click | |
52 | await element(by.cssContainingText('button', 'Edit')).click(); // click button to move to edit page | |
53 | await this.waitTextToBePresent(this.getBreadcrumb(), 'Edit'); | |
54 | await expect(element(by.css('input[name=placement-target]')).getAttribute('value')).toBe( | |
55 | 'default-placement' | |
56 | ); | |
57 | await this.selectOwner(new_owner); | |
58 | ||
59 | // Enable versioning | |
60 | await expect(element(by.css('input[id=versioning]')).getAttribute('checked')).toBeFalsy(); | |
61 | await element(by.css('label[for=versioning]')).click(); | |
62 | await expect(element(by.css('input[id=versioning]')).getAttribute('checked')).toBeTruthy(); | |
63 | ||
64 | await element(by.cssContainingText('button', 'Edit Bucket')).click(); | |
65 | ||
66 | // wait to be back on buckets page with table visible and click | |
67 | await this.waitClickableAndClick( | |
68 | this.getFirstTableCellWithText(name), | |
69 | 'Could not return to buckets page and load table after editing bucket' | |
70 | ); | |
71 | ||
72 | // check its details table for edited owner field | |
73 | let bucketDataTable = element.all(by.css('.table.table-striped.table-bordered')).first(); | |
74 | await expect(bucketDataTable.getText()).toMatch(new_owner); | |
75 | ||
76 | // Check versioning enabled: | |
77 | const ownerValueCell = bucketDataTable | |
78 | .all(by.css('tr')) | |
79 | .get(2) | |
80 | .all(by.css('td')) | |
81 | .last(); | |
82 | await expect(ownerValueCell.getText()).toEqual(new_owner); | |
83 | let versioningValueCell = bucketDataTable | |
84 | .all(by.css('tr')) | |
85 | .get(11) | |
86 | .all(by.css('td')) | |
87 | .last(); | |
88 | await expect(versioningValueCell.getText()).toEqual(this.versioningStateEnabled); | |
89 | ||
90 | // Disable versioning: | |
91 | await this.uncheckAllTableRows(); | |
92 | await this.waitClickableAndClick(this.getFirstTableCellWithText(name)); // wait for table to load and click | |
93 | await element(by.cssContainingText('button', 'Edit')).click(); // click button to move to edit page | |
94 | await this.waitTextToBePresent(this.getBreadcrumb(), 'Edit'); | |
95 | await element(by.css('label[for=versioning]')).click(); | |
96 | await expect(element(by.css('input[id=versioning]')).getAttribute('checked')).toBeFalsy(); | |
97 | await element(by.cssContainingText('button', 'Edit Bucket')).click(); | |
98 | ||
99 | // Check versioning suspended: | |
100 | await this.waitClickableAndClick( | |
101 | this.getFirstTableCellWithText(name), | |
102 | 'Could not return to buckets page and load table after editing bucket' | |
103 | ); | |
104 | bucketDataTable = element.all(by.css('.table.table-striped.table-bordered')).first(); | |
105 | versioningValueCell = bucketDataTable | |
106 | .all(by.css('tr')) | |
107 | .get(11) | |
108 | .all(by.css('td')) | |
109 | .last(); | |
110 | return expect(versioningValueCell.getText()).toEqual(this.versioningStateSuspended); | |
111 | } | |
112 | ||
113 | async testInvalidCreate() { | |
114 | await this.navigateTo('create'); | |
115 | const nameInputField = element(by.id('bid')); // Grabs name box field | |
116 | ||
117 | // Gives an invalid name (too short), then waits for dashboard to determine validity | |
118 | await nameInputField.sendKeys('rq'); | |
119 | ||
120 | await element(by.id('owner')).click(); // To trigger a validation | |
121 | ||
122 | await this.waitFn(async () => { | |
123 | // Waiting for website to decide if name is valid or not | |
124 | const klass = await nameInputField.getAttribute('class'); | |
125 | return !klass.includes('ng-pending'); | |
126 | }, 'Timed out waiting for dashboard to decide bucket name validity'); | |
127 | ||
128 | // Check that name input field was marked invalid in the css | |
129 | await expect(nameInputField.getAttribute('class')).toContain('ng-invalid'); | |
130 | ||
131 | // Check that error message was printed under name input field | |
132 | await expect(element(by.css('#bid + .invalid-feedback')).getText()).toMatch( | |
133 | 'The value is not valid.' | |
134 | ); | |
135 | ||
136 | // Test invalid owner input | |
137 | // select some valid option. The owner drop down error message will not appear unless a valid user was selected at | |
138 | // one point before the invalid placeholder user is selected. | |
139 | await this.selectOwner('dev'); | |
140 | ||
141 | // select the first option, which is invalid because it is a placeholder | |
142 | await this.selectOwner('Select a user'); | |
143 | ||
144 | await nameInputField.click(); | |
145 | ||
146 | // Check that owner drop down field was marked invalid in the css | |
147 | await expect(element(by.id('owner')).getAttribute('class')).toContain('ng-invalid'); | |
148 | ||
149 | // Check that error message was printed under owner drop down field | |
150 | await expect(element(by.css('#owner + .invalid-feedback')).getText()).toMatch( | |
151 | 'This field is required.' | |
152 | ); | |
153 | ||
154 | // Check invalid placement target input | |
155 | await this.selectOwner('dev'); | |
156 | // The drop down error message will not appear unless a valid option is previsously selected. | |
157 | await this.selectPlacementTarget('default-placement'); | |
158 | await this.selectPlacementTarget('Select a placement target'); | |
159 | await nameInputField.click(); // Trigger validation | |
160 | await expect(element(by.id('placement-target')).getAttribute('class')).toContain('ng-invalid'); | |
161 | await expect(element(by.css('#placement-target + .invalid-feedback')).getText()).toMatch( | |
162 | 'This field is required.' | |
163 | ); | |
164 | ||
165 | // Clicks the Create Bucket button but the page doesn't move. Done by testing | |
166 | // for the breadcrumb | |
167 | await element(by.cssContainingText('button', 'Create Bucket')).click(); // Clicks Create Bucket button | |
168 | await this.waitTextToBePresent(this.getBreadcrumb(), 'Create'); | |
169 | // content in fields seems to subsist through tests if not cleared, so it is cleared | |
170 | await nameInputField.clear(); | |
171 | return element(by.cssContainingText('button', 'Cancel')).click(); | |
172 | } | |
173 | ||
174 | async testInvalidEdit(name: string) { | |
175 | await this.navigateTo(); | |
176 | ||
177 | await this.waitClickableAndClick(this.getFirstTableCellWithText(name)); // wait for table to load and click | |
178 | await element(by.cssContainingText('button', 'Edit')).click(); // click button to move to edit page | |
179 | ||
180 | await this.waitTextToBePresent(this.getBreadcrumb(), 'Edit'); | |
181 | ||
182 | await expect(element(by.css('input[id=versioning]')).getAttribute('checked')).toBeFalsy(); | |
183 | ||
184 | // Chooses 'Select a user' rather than a valid owner on Edit Bucket page | |
185 | // and checks if it's an invalid input | |
186 | ||
187 | // select the first option, which is invalid because it is a placeholder | |
188 | await this.selectOwner('Select a user'); | |
189 | ||
190 | // Changes when updated to bootstrap 4 -> Error message takes a long time to appear unless another field | |
191 | // is clicked on. For that reason, I'm having the test click on the edit button before checking for errors | |
192 | await element(by.cssContainingText('button', 'Edit Bucket')).click(); | |
193 | ||
194 | // Check that owner drop down field was marked invalid in the css | |
195 | await expect(element(by.id('owner')).getAttribute('class')).toContain('ng-invalid'); | |
196 | ||
197 | // Check that error message was printed under owner drop down field | |
198 | await expect(element(by.css('#owner + .invalid-feedback')).getText()).toMatch( | |
199 | 'This field is required.' | |
200 | ); | |
201 | ||
202 | await this.waitTextToBePresent(this.getBreadcrumb(), 'Edit'); | |
203 | } | |
204 | } |