]>
Commit | Line | Data |
---|---|---|
e306af50 TL |
1 | import { PageHelper } from '../page-helper.po'; |
2 | ||
3 | const pages = { | |
4 | index: { url: '#/rgw/user', id: 'cd-rgw-user-list' }, | |
5 | create: { url: '#/rgw/user/create', id: 'cd-rgw-user-form' } | |
6 | }; | |
7 | ||
8 | export class UsersPageHelper extends PageHelper { | |
9 | pages = pages; | |
10 | ||
11 | @PageHelper.restrictTo(pages.create.url) | |
f67539c2 TL |
12 | create(tenant: string, user_id: string, fullname: string, email: string, maxbuckets: string) { |
13 | // Enter in user_id | |
14 | cy.get('#user_id').type(user_id); | |
15 | // Show Tenanat | |
16 | cy.get('#show_tenant').click({ force: true }); | |
17 | // Enter in tenant | |
18 | cy.get('#tenant').type(tenant); | |
e306af50 TL |
19 | // Enter in full name |
20 | cy.get('#display_name').click().type(fullname); | |
21 | ||
22 | // Enter in email | |
23 | cy.get('#email').click().type(email); | |
24 | ||
25 | // Enter max buckets | |
26 | this.selectOption('max_buckets_mode', 'Custom'); | |
f6b5b4d7 | 27 | cy.get('#max_buckets').should('exist').should('have.value', '1000'); |
e306af50 TL |
28 | cy.get('#max_buckets').click().clear().type(maxbuckets); |
29 | ||
30 | // Click the create button and wait for user to be made | |
31 | cy.contains('button', 'Create User').click(); | |
f67539c2 | 32 | this.getFirstTableCell(tenant + '$' + user_id).should('exist'); |
e306af50 TL |
33 | } |
34 | ||
35 | @PageHelper.restrictTo(pages.index.url) | |
36 | edit(name: string, new_fullname: string, new_email: string, new_maxbuckets: string) { | |
37 | this.navigateEdit(name); | |
38 | ||
39 | // Change the full name field | |
40 | cy.get('#display_name').click().clear().type(new_fullname); | |
41 | ||
42 | // Change the email field | |
43 | cy.get('#email').click().clear().type(new_email); | |
44 | ||
45 | // Change the max buckets field | |
46 | this.selectOption('max_buckets_mode', 'Custom'); | |
47 | cy.get('#max_buckets').click().clear().type(new_maxbuckets); | |
48 | ||
49 | cy.contains('button', 'Edit User').click(); | |
50 | ||
51 | // Click the user and check its details table for updated content | |
52 | this.getExpandCollapseElement(name).click(); | |
53 | cy.get('.active.tab-pane') | |
54 | .should('contain.text', new_fullname) | |
55 | .and('contain.text', new_email) | |
56 | .and('contain.text', new_maxbuckets); | |
57 | } | |
58 | ||
59 | invalidCreate() { | |
f67539c2 | 60 | const tenant = '000invalid_tenant'; |
e306af50 TL |
61 | const uname = '000invalid_create_user'; |
62 | // creating this user in order to check that you can't give two users the same name | |
63 | this.navigateTo('create'); | |
f67539c2 | 64 | this.create(tenant, uname, 'xxx', 'xxx@xxx', '1'); |
e306af50 TL |
65 | |
66 | this.navigateTo('create'); | |
67 | ||
68 | // Username | |
f67539c2 | 69 | cy.get('#user_id') |
e306af50 TL |
70 | // No username had been entered. Field should be invalid |
71 | .should('have.class', 'ng-invalid') | |
72 | // Try to give user already taken name. Should make field invalid. | |
f67539c2 TL |
73 | .type(uname); |
74 | cy.get('#show_tenant').click({ force: true }); | |
75 | cy.get('#tenant').type(tenant).should('have.class', 'ng-invalid'); | |
76 | cy.contains('#tenant + .invalid-feedback', 'The chosen user ID exists in this tenant.'); | |
e306af50 TL |
77 | |
78 | // check that username field is marked invalid if username has been cleared off | |
f67539c2 TL |
79 | cy.get('#user_id').clear().blur().should('have.class', 'ng-invalid'); |
80 | cy.contains('#user_id + .invalid-feedback', 'This field is required.'); | |
e306af50 TL |
81 | |
82 | // Full name | |
83 | cy.get('#display_name') | |
84 | // No display name has been given so field should be invalid | |
85 | .should('have.class', 'ng-invalid') | |
86 | // display name field should also be marked invalid if given input then emptied | |
87 | .type('a') | |
88 | .clear() | |
89 | .blur() | |
90 | .should('have.class', 'ng-invalid'); | |
91 | cy.contains('#display_name + .invalid-feedback', 'This field is required.'); | |
92 | ||
93 | // put invalid email to make field invalid | |
94 | cy.get('#email').type('a').blur().should('have.class', 'ng-invalid'); | |
95 | cy.contains('#email + .invalid-feedback', 'This is not a valid email address.'); | |
96 | ||
97 | // put negative max buckets to make field invalid | |
98 | this.expectSelectOption('max_buckets_mode', 'Custom'); | |
99 | cy.get('#max_buckets').clear().type('-5').blur().should('have.class', 'ng-invalid'); | |
100 | cy.contains('#max_buckets + .invalid-feedback', 'The entered value must be >= 1.'); | |
101 | ||
102 | this.navigateTo(); | |
f67539c2 | 103 | this.delete(tenant + '$' + uname); |
e306af50 TL |
104 | } |
105 | ||
106 | invalidEdit() { | |
f67539c2 | 107 | const tenant = '000invalid_tenant'; |
e306af50 TL |
108 | const uname = '000invalid_edit_user'; |
109 | // creating this user to edit for the test | |
110 | this.navigateTo('create'); | |
f67539c2 | 111 | this.create(tenant, uname, 'xxx', 'xxx@xxx', '50'); |
a4b75251 | 112 | const name = tenant + '$' + uname; |
e306af50 TL |
113 | this.navigateEdit(name); |
114 | ||
115 | // put invalid email to make field invalid | |
116 | cy.get('#email') | |
117 | .clear() | |
118 | .type('a') | |
119 | .blur() | |
120 | .should('not.have.class', 'ng-pending') | |
121 | .should('have.class', 'ng-invalid'); | |
122 | cy.contains('#email + .invalid-feedback', 'This is not a valid email address.'); | |
123 | ||
124 | // empty the display name field making it invalid | |
125 | cy.get('#display_name').clear().blur().should('have.class', 'ng-invalid'); | |
126 | cy.contains('#display_name + .invalid-feedback', 'This field is required.'); | |
127 | ||
128 | // put negative max buckets to make field invalid | |
f6b5b4d7 TL |
129 | this.selectOption('max_buckets_mode', 'Disabled'); |
130 | cy.get('#max_buckets').should('not.exist'); | |
131 | this.selectOption('max_buckets_mode', 'Custom'); | |
132 | cy.get('#max_buckets').should('exist').should('have.value', '50'); | |
e306af50 TL |
133 | cy.get('#max_buckets').clear().type('-5').blur().should('have.class', 'ng-invalid'); |
134 | cy.contains('#max_buckets + .invalid-feedback', 'The entered value must be >= 1.'); | |
135 | ||
136 | this.navigateTo(); | |
f67539c2 | 137 | this.delete(tenant + '$' + uname); |
e306af50 TL |
138 | } |
139 | } |