Skip to content

Commit 98bfc3e

Browse files
committed
Add cypress tests for change password
1 parent 7486c5f commit 98bfc3e

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

cypress/e2e/3-user.cy.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,39 @@ describe('user', function() {
267267
cy.getElement('change-username-errors').should('be.visible');
268268
})
269269

270+
it('allows a user to change their password', function() {
271+
cy.loginUser('neo');
272+
cy.visit('/settings');
273+
cy.getElement('change-current-password').clear().type('Neo');
274+
cy.getElement('change-new-password').clear().type('!ThisIsASecurePassword123!');
275+
cy.getElement('change-confirm-password').clear().type('!ThisIsASecurePassword123!');
276+
cy.getElement('change-password-submit').click();
277+
278+
cy.getElement('change-password-success').should('be.visible');
279+
})
280+
281+
it('does not allow a user to change their password if current password is incorrect', function() {
282+
cy.loginUser('neo');
283+
cy.visit('/settings');
284+
cy.getElement('change-current-password').clear().type('Incorrect password');
285+
cy.getElement('change-new-password').clear().type('!ThisIsASecurePassword123!');
286+
cy.getElement('change-confirm-password').clear().type('!ThisIsASecurePassword123!');
287+
cy.getElement('change-password-submit').click();
288+
289+
cy.getElement('current-password-error').should('be.visible');
290+
})
291+
292+
it('does not allow a user to change their password if confirmed password does not match', function() {
293+
cy.loginUser('neo');
294+
cy.visit('/settings');
295+
cy.getElement('change-current-password').clear().type('Neo');
296+
cy.getElement('change-new-password').clear().type('!ThisIsASecurePassword123!');
297+
cy.getElement('change-confirm-password').clear().type('!ThisIsADifferentSecurePassword123!');
298+
cy.getElement('change-password-submit').click();
299+
300+
cy.getElement('confirm-password-error').should('be.visible');
301+
})
302+
270303
})
271304

272305
})

templates/partials/hx/change_password.html.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div id="hx-change-password" class="mb-2">
22
<div class="mb-2">
33
{% if success is defined %}
4-
<div class="alert alert-success">
4+
<div class="alert alert-success" data-test="change-password-success">
55
{{ 'fields.password.updated' | trans }}
66
</div>
77
{% endif %}
88
<label for="currentPassword" class="form-label">{{ 'fields.current_password.title' | trans }}</label>
9-
<input type="password" class="form-control{% if errors.current_password is defined %} is-invalid{% endif %}" name="current_password" id="currentPassword" autocomplete="current-password" data-test="current-password" required>
9+
<input type="password" class="form-control{% if errors.current_password is defined %} is-invalid{% endif %}" name="current_password" id="currentPassword" autocomplete="current-password" data-test="change-current-password" required>
1010
{% if errors.current_password is defined %}
11-
<div class="invalid-feedback">
11+
<div class="invalid-feedback" data-test="current-password-error">
1212
{% for errorMessage in errors.current_password %}
1313
<p>{{ errorMessage }}</p>
1414
{% endfor %}
@@ -17,9 +17,9 @@
1717
</div>
1818
<div class="mb-2">
1919
<label for="newPassword" class="form-label">{{ 'fields.new_password.title' | trans }}</label>
20-
<input type="password" class="form-control{% if errors.new_password is defined %} is-invalid{% endif %}" name="new_password" id="newPassword" aria-describedby="passwordHelpBlock" data-test="new-password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" required>
20+
<input type="password" class="form-control{% if errors.new_password is defined %} is-invalid{% endif %}" name="new_password" id="newPassword" aria-describedby="passwordHelpBlock" data-test="change-new-password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" required>
2121
{% if errors.new_password is defined %}
22-
<div class="invalid-feedback">
22+
<div class="invalid-feedback" data-test="new-password-error">
2323
{% for errorMessage in errors.new_password %}
2424
<p>{{ errorMessage }}</p>
2525
{% endfor %}
@@ -31,9 +31,9 @@
3131
</div>
3232
<div class="mb-2">
3333
<label for="confirmPassword" class="form-label">{{ 'fields.confirm_password.title' | trans }}</label>
34-
<input type="password" class="form-control{% if errors.confirm_password is defined %} is-invalid{% endif %}" name="confirm_password" id="confirmPassword" data-test="confirm-password" required>
34+
<input type="password" class="form-control{% if errors.confirm_password is defined %} is-invalid{% endif %}" name="confirm_password" id="confirmPassword" data-test="change-confirm-password" required>
3535
{% if errors.confirm_password is defined %}
36-
<div class="invalid-feedback">
36+
<div class="invalid-feedback" data-test="confirm-password-error">
3737
{% for errorMessage in errors.confirm_password %}
3838
<p>{{ errorMessage }}</p>
3939
{% endfor %}

0 commit comments

Comments
 (0)