Skip to content

Commit

Permalink
add edit user test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rovel authored and M1CK431 committed Oct 9, 2024
1 parent da61f0d commit b4d062c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/components/settings/Users/EditUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
class="form-control mt-2"
required
:disabled="saving"
data-cy="edit-username-input"
/>
</label>

<button class="btn btn-primary" type="submit" :disabled="saving">
<button class="btn btn-primary" type="submit" :disabled="saving" data-cy="submit-edit-username-form">
<span v-show="saving" class="spinner-border spinner-border-sm" role="status" aria-hidden="true" />
{{ $t("Update Username") }}
</button>
Expand All @@ -35,6 +36,7 @@
class="form-control mt-2"
required
:disabled="savingPassword"
data-cy="edit-current-password-input"
/>
</label>
</div>
Expand All @@ -49,6 +51,7 @@
class="form-control mt-2"
required
:disabled="savingPassword"
data-cy="edit-new-password-input"
/>
</label>
</div>
Expand All @@ -63,11 +66,12 @@
class="form-control mt-2"
required
:disabled="savingPassword"
data-cy="edit-new-password-repeat-input"
/>
</label>
</div>

<button class="btn btn-primary" type="submit" :disabled="savingPassword">
<button class="btn btn-primary" type="submit" :disabled="savingPassword" data-cy="submit-edit-password-form">
<span v-show="savingPassword" class="spinner-border spinner-border-sm" role="status" aria-hidden="true" />
{{ $t("Update Password") }}
</button>
Expand All @@ -83,6 +87,7 @@
type="checkbox"
:disabled="saving"
@click="debounceCheckboxClick(() => { active = !active; save({ active }); })"
data-cy="edit-active-checkbox"

Check warning on line 90 in src/components/settings/Users/EditUser.vue

View workflow job for this annotation

GitHub Actions / check-linters

Attribute "data-cy" should go before "@click"
>
<div class="ps-2">{{ $t("Active") }}</div>
</label>
Expand Down
24 changes: 23 additions & 1 deletion test/cypress/e2e/settings.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const actor = require("../support/actors/actor");
const userData = require("../support/const/user-data");
const settingsUsersAddPage = require("../support/pages/settings-users-add-page");
const settingsUsersEditPage = require("../support/pages/settings-users-edit-page");

Check warning on line 4 in test/cypress/e2e/settings.cy.js

View workflow job for this annotation

GitHub Actions / check-linters

'settingsUsersEditPage' is assigned a value but never used

describe("user can create a new account on settings page", () => {
before(() => {
Expand All @@ -16,13 +17,34 @@ describe("user can create a new account on settings page", () => {
});
});

describe("logout and login with new user", () => {
describe("login with new user then edit info", () => {
before(() => {
cy.visit('/');
actor.actor.loginTask.fillAndSubmitLoginForm(userData.ADMIN_USER_DATA.username, userData.ADMIN_USER_DATA.password);
});
it("user can edit its data with new created account", () => {
cy.visit(`/settings/users/edit/${userData.ADMIN_USER_DATA.id}`);

actor.actor.editUserTask.fillAndSubmitNewUserNameForm(userData.ADMIN_USER_DATA.username + "new");
actor.actor.editUserTask.fillAndSubmitNewPasswordForm(userData.ADMIN_USER_DATA.password, userData.ADMIN_USER_DATA.password + "new", userData.ADMIN_USER_DATA.password + "new");

cy.wait(1000);
cy.visit('/');
actor.actor.loginTask.fillAndSubmitLoginForm(userData.ADMIN_USER_DATA.username + "new", userData.ADMIN_USER_DATA.password + "new");
cy.visit(`/settings/users/edit/${userData.DEFAULT_USER_DATA.id}`);
actor.actor.editUserTask.inactivateUser();
cy.wait(2000);


Check warning on line 38 in test/cypress/e2e/settings.cy.js

View workflow job for this annotation

GitHub Actions / check-linters

More than 1 blank line not allowed
});

});
describe("Inactivated user cannot login", () => {
it("user cannot login with inactivated account", () => {
cy.visit('/');
actor.actor.loginTask.fillAndSubmitLoginForm(userData.DEFAULT_USER_DATA.username, userData.DEFAULT_USER_DATA.password);
cy.get('.alert')
.should("be.visible")
.and("contain.text", "Incorrect username or password.");
});
});
2 changes: 2 additions & 0 deletions test/cypress/support/actors/actor.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const setupTask = require("../tasks/setup-task");
const loginTask = require("../tasks/login-task");
const createUserTask = require("../tasks/create-user-task");
const editUserTask = require("../tasks/edit-user-task");
class Actor {
constructor() {
this.setupTask = new setupTask.SetupTask();
this.loginTask = new loginTask.LoginTask();
this.createUserTask = new createUserTask.CreateUserTask();
this.editUserTask = new editUserTask.EditUserTask();
}
}
const actor = new Actor();
Expand Down
15 changes: 8 additions & 7 deletions test/cypress/support/pages/settings-users-edit-page.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const SettingsUsersEditPage = {
exports.SettingsUsersEditPage = {
url: Cypress.env("baseUrl") + "/settings/users/edit",
usernameInput: '[data-cy="username-input"]',
newPassWordInput: '[data-cy="password-input"]',
newPasswordRepeatInput: '[data-cy="password-repeat-input"]',
submitEditUserForm: '[data-cy="submit-create-admin-form"]',
submitNewPasswordForm: '[data-cy="submit-new-password-form"]',
activeStatus: '[data-cy="active-status"]',
usernameInput: '[data-cy="edit-username-input"]',
currentPassWordInput: '[data-cy="edit-current-password-input"]',
newPassWordInput: '[data-cy="edit-new-password-input"]',
newPasswordRepeatInput: '[data-cy="edit-new-password-repeat-input"]',
submitEditUserNameForm: '[data-cy="submit-edit-username-form"]',
submitNewPasswordForm: '[data-cy="submit-edit-password-form"]',
activeStatus: '[data-cy="edit-active-checkbox"]',
};
19 changes: 19 additions & 0 deletions test/cypress/support/tasks/edit-user-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const settingsUsersEditPage = require('../pages/settings-users-edit-page');

class EditUserTask{

Check warning on line 3 in test/cypress/support/tasks/edit-user-task.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing space before opening brace
fillAndSubmitNewUserNameForm(username){

Check warning on line 4 in test/cypress/support/tasks/edit-user-task.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing space before opening brace
cy.get(settingsUsersEditPage.SettingsUsersEditPage.usernameInput).clear();
cy.get(settingsUsersEditPage.SettingsUsersEditPage.usernameInput).type(username);
cy.get(settingsUsersEditPage.SettingsUsersEditPage.submitEditUserNameForm).click();
}
fillAndSubmitNewPasswordForm(password, newPassword, newPasswordRepeat){

Check warning on line 9 in test/cypress/support/tasks/edit-user-task.js

View workflow job for this annotation

GitHub Actions / check-linters

Expected blank line between class members
cy.get(settingsUsersEditPage.SettingsUsersEditPage.currentPassWordInput).type(password);
cy.get(settingsUsersEditPage.SettingsUsersEditPage.newPassWordInput).type(newPassword);
cy.get(settingsUsersEditPage.SettingsUsersEditPage.newPasswordRepeatInput).type(newPasswordRepeat);
cy.get(settingsUsersEditPage.SettingsUsersEditPage.submitNewPasswordForm).click();
}
inactivateUser(){
cy.get(settingsUsersEditPage.SettingsUsersEditPage.activeStatus).uncheck();
}
}
exports.EditUserTask = EditUserTask;

0 comments on commit b4d062c

Please sign in to comment.