Skip to content

Commit

Permalink
Merge pull request #2 from Rovel/add-new-admins-cy-tests
Browse files Browse the repository at this point in the history
add cy login and create admin tests for louislam#3571
  • Loading branch information
M1CK431 authored Nov 5, 2023
2 parents 5f06084 + 590e810 commit 4cef0a5
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@
<h1 class="h3 mb-3 fw-normal" />

<div v-if="!tokenRequired" class="form-floating">
<input id="floatingInput" v-model="username" type="text" class="form-control" placeholder="Username">
<input id="floatingInput" v-model="username" type="text" class="form-control" placeholder="Username" data-cy="login-username-input">
<label for="floatingInput">{{ $t("Username") }}</label>
</div>

<div v-if="!tokenRequired" class="form-floating mt-3">
<input id="floatingPassword" v-model="password" type="password" class="form-control" placeholder="Password">
<input id="floatingPassword" v-model="password" type="password" class="form-control" placeholder="Password" data-cy="login-password-input">
<label for="floatingPassword">{{ $t("Password") }}</label>
</div>

<div v-if="tokenRequired">
<div class="form-floating mt-3">
<input id="otp" v-model="token" type="text" maxlength="6" class="form-control" placeholder="123456">
<input id="otp" v-model="token" type="text" maxlength="6" class="form-control" placeholder="123456" data-cy="login-otp-input">
<label for="otp">{{ $t("Token") }}</label>
</div>
</div>

<div class="form-check mb-3 mt-3 d-flex justify-content-center pe-4">
<div class="form-check">
<input id="remember" v-model="$root.remember" type="checkbox" value="remember-me" class="form-check-input">

<input id="remember" v-model="$root.remember" type="checkbox" value="remember-me" class="form-check-input" data-cy="login-remember-check">
<label class="form-check-label" for="remember">
{{ $t("Remember me") }}
</label>
</div>
</div>
<button class="w-100 btn btn-primary" type="submit" :disabled="processing">
<button class="w-100 btn btn-primary" type="submit" :disabled="processing" data-cy="submit-login-form">
{{ $t("Login") }}
</button>

Expand Down
28 changes: 28 additions & 0 deletions test/cypress/e2e/settings.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const actor = require("../support/actors/actor");
const userData = require("../support/const/user-data");
const settingsUsersAddPage = require("../support/pages/settings-users-add-page");

describe("user can create a new account on settings page", () => {
before(() => {
cy.visit("/settings/users/add");
actor.actor.loginTask.fillAndSubmitLoginForm();
});
it("user cannot create new account with same", () => {
cy.url().should("be.equal", settingsUsersAddPage.SettingsUsersAddPage.url);
actor.actor.createUserTask.fillAndSubmitNewUserForm(userData.ADMIN_USER_DATA.username, userData.ADMIN_USER_DATA.password, userData.DEFAULT_USER_DATA.password);
cy.get('[role="alert"]')
.should("be.visible")
.and("contain.text", "Added Successfully.");
});
});

describe("logout and login with new user", () => {
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}`);

});
});
11 changes: 11 additions & 0 deletions test/cypress/e2e/setup.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@ describe("user can create a new account on setup page", () => {
cy.get('[role="alert"]')
.should("be.visible")
.and("contain.text", "Added Successfully.");
});
});

describe("after first setup login form is presented", () => {
before(() => {
cy.visit("/setup");
});
it("user can login with created account", () => {
cy.url().should("be.equal", dashboardPage.DashboardPage.url);
actor.actor.loginTask.fillAndSubmitLoginForm();
cy.url().should("be.equal", dashboardPage.DashboardPage.url);
});
});
4 changes: 4 additions & 0 deletions test/cypress/support/actors/actor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const setupTask = require("../tasks/setup-task");
const loginTask = require("../tasks/login-task");
const createUserTask = require("../tasks/create-user-task");
class Actor {
constructor() {
this.setupTask = new setupTask.SetupTask();
this.loginTask = new loginTask.LoginTask();
this.createUserTask = new createUserTask.CreateUserTask();
}
}
const actor = new Actor();
Expand Down
5 changes: 5 additions & 0 deletions test/cypress/support/components/login-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.LoginCompónent = {
userNameInput: '[data-cy="login-username-input"]',
passWordInput: '[data-cy="login-password-input"]',
submitLoginForm: '[data-cy="submit-login-form"]',
};
6 changes: 6 additions & 0 deletions test/cypress/support/const/user-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
exports.DEFAULT_USER_DATA = {
id: "1",
username: "testuser",
password: "testuser123",
};
exports.ADMIN_USER_DATA = {
id: "2",
username: "admin_user",
password: "testuser123",
};
7 changes: 7 additions & 0 deletions test/cypress/support/pages/settings-users-add-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports.SettingsUsersAddPage = {
url: Cypress.env("baseUrl") + "/settings/users/add",
usernameInput: '[data-cy="username-input"]',
passWordInput: '[data-cy="password-input"]',
passwordRepeatInput: '[data-cy="password-repeat-input"]',
submitNewUserForm: '[data-cy="submit-create-admin-form"]',
};
9 changes: 9 additions & 0 deletions test/cypress/support/pages/settings-users-edit-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const 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"]',
};
11 changes: 11 additions & 0 deletions test/cypress/support/tasks/create-user-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const settingsUsersAddPage = require('../pages/settings-users-add-page');

class CreateUserTask{
fillAndSubmitNewUserForm(username, password, passwordRepeat){
cy.get(settingsUsersAddPage.SettingsUsersAddPage.usernameInput).type(username);
cy.get(settingsUsersAddPage.SettingsUsersAddPage.passWordInput).type(password);
cy.get(settingsUsersAddPage.SettingsUsersAddPage.passwordRepeatInput).type(passwordRepeat);
cy.get(settingsUsersAddPage.SettingsUsersAddPage.submitNewUserForm).click();
}
}
exports.CreateUserTask = CreateUserTask;
18 changes: 18 additions & 0 deletions test/cypress/support/tasks/login-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const user_data = require('../const/user-data');
const login_component = require('../components/login-component');

class LoginTask {
fillAndSubmitLoginForm(username, password) {
// check if username and password are provided else use default user
if (username && password) {
cy.get(login_component.LoginCompónent.userNameInput).type(username);
cy.get(login_component.LoginCompónent.passWordInput).type(password);
} else {
cy.get(login_component.LoginCompónent.userNameInput).type(user_data.DEFAULT_USER_DATA.username);
cy.get(login_component.LoginCompónent.passWordInput).type(user_data.DEFAULT_USER_DATA.password);
}

cy.get(login_component.LoginCompónent.submitLoginForm).click();
}
}
exports.LoginTask = LoginTask;

0 comments on commit 4cef0a5

Please sign in to comment.