Skip to content

Commit

Permalink
fix: about_positive_logged_user_seeing_about_screen.steps.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed May 5, 2024
1 parent 53c1ed3 commit e445f41
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
2 changes: 1 addition & 1 deletion webapp/e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testMatch: ["**/playing_full_game_pos*.steps.js","**/about.steps.js", "**/login_positive.steps.js"],
testMatch: ["**/playing_full_game_pos*.steps.js","**/about.steps.js", "**/login_positive.steps.js","**/about_positive_logged_user_seeing_about_screen.steps.js"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testTimeout: 30000
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

const {registerUserFromRootDirectory} = require('../e2e_utils/e2e_utils_register.js');
const {waitForPageToLoad} = require('../e2e_utils/e2e_utils_timeout.js');
const {logOutUser} = require('../e2e_utils/e2e_utils_logout.js');
const {loginUserFromRootDirectory} = require('../e2e_utils/e2e_utils_login.js');
const { defineFeature, loadFeature }=require('jest-cucumber');
const puppeteer = require('puppeteer');
const setDefaultOptions = require("expect-puppeteer").setDefaultOptions;
Expand All @@ -13,13 +8,11 @@ let browser;

defineFeature(feature, test => {
let username = "t.about.pos";
let email;
let password;

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
? await puppeteer.launch({ ignoreHTTPSErrors: true})
: await puppeteer.launch({ headless: false, slowMo: 100, ignoreHTTPSErrors: true });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })
Expand All @@ -31,19 +24,17 @@ defineFeature(feature, test => {
.catch(() => {});

// Registering the user before the tests
let credentials = registerUserFromRootDirectory(username, page);
email = credentials[0];
username = credentials[1];
await registerUserFromRootDirectory(username, page);

// Logging it out
logOutUser(page);
await logOutUser(page);

}, 120000);

test("A logged user wants to see the about screen of the webpage", ({given,when,and,then}) => {

given("A logged user in the main menu", async () => {
loginUserFromRootDirectory(username, email, password, page);
await loginUserFromRootDirectory(username, page);
});

when("The user presses the button for deploying the lateral menu", async () => {
Expand All @@ -55,7 +46,7 @@ defineFeature(feature, test => {
});

then("The user is presented to the about screen", async () => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
Expand All @@ -68,4 +59,63 @@ defineFeature(feature, test => {
done();
browser.close();
});
});
});
async function registerUserFromRootDirectory(username, page) {
// Credentials for the new user
let email = username + "@email.com"
let password = username + "psw"

// Registering process
await expect(page).toClick("span[class='chakra-link css-1bicqx'");
await expect(page).toFill("input[id='user'", email);
await expect(page).toFill("input[id='username'", username);
await expect(page).toFill("#password", password);
await expect(page).toFill("input[id='field-:r5:']", password);
await expect(page).toClick("button[data-testid='Sign up'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();

return [email, password];
}

async function logOutUser(page) {
// Logging out
await expect(page).toClick("#lateralMenuButton");
await new Promise(resolve => setTimeout(resolve, 5000));
await expect(page).toClick("button[data-testid='LogOut']");

// Checking for the log out to be sucessful
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
let value = header === "Login" || "Iniciar sesión";

expect(value).toBeTruthy();
}
async function loginUserFromRootDirectory(username, page) {
// Credentials for the new user
let email = username + "@email.com"
let password = username + "psw"

// login process
await expect(page).toClick("button[data-testid='Login'");
await expect(page).toFill("#user", email);
await expect(page).toFill("#password", password);
await expect(page).toClick("button[data-testid='Login'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();

}
3 changes: 2 additions & 1 deletion webapp/e2e/steps/playing_full_game_positive.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ async function loginUserFromRootDirectory(username, page) {
}
async function logOutUser(page) {
// Logging out
await expect(page).toClick("#lateralMenuButton");
await expect(page).toClick("#lateralMenuButton");
await new Promise(resolve => setTimeout(resolve, 5000));
await expect(page).toClick("button[data-testid='LogOut']");

// Checking for the log out to be sucessful
Expand Down

0 comments on commit e445f41

Please sign in to comment.