Skip to content

Commit

Permalink
Añadidos test e2e de ranking para cambiar modo de juego y filtrado
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 23, 2024
1 parent 7b395cf commit eb7f30d
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webapp/e2e/features/ranking-sorting.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Seeing ranking and changing sorting filter

Scenario: The user can see the Ranking page and change sorting filter
Given A logged-in user
When I click on the Ranking link and in Sort by Total Points
Then The ranking (sorted by Total Points) should be shown on screen
6 changes: 6 additions & 0 deletions webapp/e2e/features/ranking.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Seeing ranking and changing gamemode

Scenario: The user can see the Ranking page and change gamemode
Given A logged-in user
When I click on the Ranking link and in Battery gamemode
Then The ranking of the Battery gamemode should be shown on screen
63 changes: 63 additions & 0 deletions webapp/e2e/steps/ranking-sorting.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const puppeteer = require("puppeteer");
const { defineFeature, loadFeature } = require("jest-cucumber");
const setDefaultOptions = require("expect-puppeteer").setDefaultOptions;
const { expect } = require("expect-puppeteer");
const feature = loadFeature("./features/register-form.feature");

let page;
let browser;

defineFeature(feature, (test) => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 });

await page
.goto("http://localhost:3000", {
waitUntil: "networkidle0",
})
.catch(() => {});
});

test("The user can see the Ranking page and change sorting filter", ({ given, when, then }) => {
let username;
let password;

given("A logged-in user", async () => {
username="testuser";
password="Testpassword1";
await page.waitForSelector("#login-username");
await page.type("#login-username", username);
await page.waitForSelector("#login-password");
await page.type("#login-password", password);
await page.click("button", { text: "Login" });
await page.waitForNavigation({ waitUntil: "networkidle0" });
});

when("I click on the Ranking link and in Sort by Total Points", async () => {
await page.waitForSelector('[data-testid="ranking-link"]');
await page.click('[data-testid="ranking-link"]');
await page.select('[data-testid="combobox"]', "totalPoints");
await page.waitForSelector('th', { text: "Puntos totales" });
await page.waitForSelector('td');
await page.waitForNavigation({ waitUntil: "networkidle0" });
});

then("The ranking (sorted by Total Points) should be shown on screen", async () => {
const url = page.url();
expect(url).toContain("/ranking");
const displayedField = await page.evaluate(() => {
return document.querySelector('th').textContent;
});
expect(displayedField).toContain("Puntos totales");
});
});

afterAll(async () => {
browser.close();
});
});
62 changes: 62 additions & 0 deletions webapp/e2e/steps/ranking.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const puppeteer = require("puppeteer");
const { defineFeature, loadFeature } = require("jest-cucumber");
const setDefaultOptions = require("expect-puppeteer").setDefaultOptions;
const { expect } = require("expect-puppeteer");
const feature = loadFeature("./features/register-form.feature");

let page;
let browser;

defineFeature(feature, (test) => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 });

await page
.goto("http://localhost:3000", {
waitUntil: "networkidle0",
})
.catch(() => {});
});

test("The user can see the Ranking page and change gamemode", ({ given, when, then }) => {
let username;
let password;

given("A logged-in user", async () => {
username="testuser";
password="Testpassword1";
await page.waitForSelector("#login-username");
await page.type("#login-username", username);
await page.waitForSelector("#login-password");
await page.type("#login-password", password);
await page.click("button", { text: "Login" });
await page.waitForNavigation({ waitUntil: "networkidle0" });
});

when("I click on the Ranking link and in Battery gamemode", async () => {
await page.waitForSelector('[data-testid="ranking-link"]');
await page.click('[data-testid="ranking-link"]');
await page.click('[data-testid="battery-button"]');
await page.waitForSelector('button.active');
await page.waitForNavigation({ waitUntil: "networkidle0" });
});

then("The ranking of the Battery gamemode should be shown on screen", async () => {
const url = page.url();
expect(url).toContain("/ranking");
const statsText = await page.evaluate(() => {
return document.querySelector("h2").textContent;
});
expect(statsText).toContain("Batería de sabios");
});
});

afterAll(async () => {
browser.close();
});
});

0 comments on commit eb7f30d

Please sign in to comment.