Skip to content

Commit

Permalink
fix: logout and about
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed May 5, 2024
1 parent 0a656c4 commit 4cc1089
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 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*.steps.js","**/login*.steps.js","**/about*.steps.js","**/register*.steps.js","**/seeing*.steps.js"],
testMatch: ["**/about*.steps.js","**/logout*.steps.js"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testTimeout: 30000
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let browser;


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

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
Expand Down
51 changes: 30 additions & 21 deletions webapp/e2e/steps/logout_positive_logged_user.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ let browser;


defineFeature(feature, test => {
let username = "t.logOu.pos.logged"
let userEmail;
let password;
let username = "logout_p_logged"

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
Expand All @@ -25,25 +23,16 @@ defineFeature(feature, test => {
})
.catch(() => {});

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

}, 120000);

test("A logged user wants to log out the webpage", ({given,when,and,then}) => {
let gameURL = "http://localhost:3000/dashboard/game";

given('A logged user in main menu', async () => {
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
let value = header === "Login" || "Iniciar sesión";

expect(value).toBeTruthy();


waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
let newHeader = await page.$eval("h2", (element) => {
return element.innerHTML
})
Expand All @@ -52,7 +41,7 @@ defineFeature(feature, test => {
});

when('User presses the button for deploying the lateral menu', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
await expect(page).toClick("#lateralMenuButton");

});
Expand All @@ -63,7 +52,7 @@ defineFeature(feature, test => {
});

then('The login screen shows on the user device and the user is no longer logged in', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
Expand All @@ -79,6 +68,26 @@ defineFeature(feature, test => {
});
});

async function waitForPageToLoad (timeout_ms = 6000) {
await new Promise(resolve => setTimeout(resolve, timeout_ms));
}
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];
}
18 changes: 2 additions & 16 deletions webapp/e2e/steps/logout_positive_non_logged_user.steps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js';
import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js';
import { logOutUser } from '../e2e_utils/e2e_utils_logout.js';
import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js'

const { defineFeature, loadFeature }=require('jest-cucumber');
const puppeteer = require('puppeteer');
const setDefaultOptions = require("expect-puppeteer").setDefaultOptions;
Expand All @@ -12,10 +7,6 @@ let browser;


defineFeature(feature, test => {
let username = "t.logoU.neg.n_log"
let user;
let password;

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch({ ignoreHTTPSErrors: true })
Expand All @@ -32,14 +23,9 @@ defineFeature(feature, test => {
}, 120000);

test("A non-logged user wants to log out the webpage", ({given,when,then}) => {
let username = "pepe"
let user = username + "@pepe.com"
let password = "pepe"

let gameURL = "http://localhost:3000/dashboard/game";

given('A non-logged user in main menu', async () => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
Expand All @@ -57,7 +43,7 @@ defineFeature(feature, test => {
});

then('The login screen shows on the user device', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
Expand Down

0 comments on commit 4cc1089

Please sign in to comment.