Skip to content

Commit

Permalink
fix: seeing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed May 5, 2024
1 parent f820bc4 commit 0a656c4
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 50 deletions.
3 changes: 1 addition & 2 deletions webapp/e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
testMatch: ["**/playing_full_game_pos*.steps.js","**/login_register_negative_bad_email_format.steps.js","**/login_register_negative_blank_email_credentials.steps.js", "**/login_positive.steps.js","**/about_positive_logged_user_seeing_about_screen.steps.js"
,"**/about_positive_non_logged_user_seeing_about_screen.steps.js","**/login_register_negative_blank_password_credentials.steps.js","**/register*.steps.js"],
testMatch: ["**/playing*.steps.js","**/login*.steps.js","**/about*.steps.js","**/register*.steps.js","**/seeing*.steps.js"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testTimeout: 30000
}
12 changes: 2 additions & 10 deletions webapp/e2e/steps/playing_game_negative_non_logged_user.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ let browser;


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


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

test("A non-logged user wants to play a new game", ({given,when,then}) => {
let username = "pepe"
let user = username + "@pepe.com"
let password = "pepe"

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

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

when('Entering the endpoint via URL', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
await page
.goto(gameURL, {
waitUntil: "networkidle0",
Expand All @@ -55,7 +47,7 @@ defineFeature(feature, test => {


then('No new game is created and the user is redirected to the log in screen', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
Expand Down
13 changes: 2 additions & 11 deletions webapp/e2e/steps/seeing_rules_negative_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.rules.neg"
let user;
let password;


beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
Expand All @@ -36,7 +27,7 @@ defineFeature(feature, test => {
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 @@ -54,7 +45,7 @@ defineFeature(feature, test => {
});

then('The user is redirected to the log in screen', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("h2[class='chakra-heading css-79qjat']", (element) => {
return element.innerHTML
})
Expand Down
59 changes: 50 additions & 9 deletions webapp/e2e/steps/seeing_rules_positive.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 @@ -29,6 +24,12 @@ 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 logged user wants to see the rules for the game", ({given,when,and,then}) => {
Expand All @@ -46,7 +47,7 @@ defineFeature(feature, test => {
await expect(page).toClick("button[data-testid='Login'");

// Checking user is in main screen
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2[class='chakra-heading css-79qjat']", (element) => {
return element.innerHTML
})
Expand All @@ -57,7 +58,7 @@ defineFeature(feature, test => {
});

when('The user presses the button for deploying the lateral menu', async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
await expect(page).toClick("#lateralMenuButton");

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

then("The screen shows redirects the user to the rules' screen", async() => {
waitForPageToLoad();
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2[class='chakra-heading css-79qjat']", (element) => {
return element.innerHTML
})
Expand All @@ -82,4 +83,44 @@ 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();
}
14 changes: 2 additions & 12 deletions webapp/e2e/steps/seeing_stats_negative_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,11 +7,6 @@ let browser;


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


beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch({ ignoreHTTPSErrors: true })
Expand All @@ -36,7 +26,7 @@ defineFeature(feature, test => {
let gameURL = "http://localhost:3000/dashboard/game";

given('A non-logged user in main menu', async () => {
waitForPageToLoad(); // Waiting for page to fully load
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 @@ -54,7 +44,7 @@ defineFeature(feature, test => {
});

then('The user is redirected to 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[class='chakra-heading css-79qjat']", (element) => {
return element.innerHTML
})
Expand Down
54 changes: 48 additions & 6 deletions webapp/e2e/steps/seeing_stats_positive.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 Down Expand Up @@ -30,6 +25,12 @@ 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 logged user with many games wants to see its stats", ({given,when,and,then}) => {
Expand Down Expand Up @@ -83,4 +84,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 0a656c4

Please sign in to comment.