Skip to content

Commit

Permalink
fix: login register negative
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed May 5, 2024
1 parent baabe89 commit 13d23d4
Showing 1 changed file with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js';

const { defineFeature, loadFeature }=require('jest-cucumber');
const puppeteer = require('puppeteer');
const setDefaultOptions = require("expect-puppeteer").setDefaultOptions;
Expand Down Expand Up @@ -27,12 +25,17 @@ defineFeature(feature, test => {
waitUntil: "networkidle0",
})
.catch(() => {});
// Registering the user before the tests
await registerUserFromRootDirectory(username, page);

// Logging it out
await logOutUser(page);
}, 120000);

test("A registered user wants to log in using his credentials but they do not match any registered user", ({given,when,and,then}) => {

given('A registered user in the root screen', async () => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
Expand All @@ -46,7 +49,7 @@ defineFeature(feature, test => {
});

and('User enters in the log in 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 @@ -65,7 +68,7 @@ defineFeature(feature, test => {
});

then('Log in screen shows an informative error message and does not allow the user to log in', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => {
return element.innerHTML
})
Expand All @@ -80,4 +83,45 @@ 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)); // Waiting for page to fully load
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();
}

0 comments on commit 13d23d4

Please sign in to comment.