Skip to content

Commit

Permalink
Test e2e para responder una pregunta del clasico
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 23, 2024
1 parent e9b3f06 commit 6b2b003
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 11 deletions.
6 changes: 6 additions & 0 deletions webapp/e2e/features/play-classic.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Answering a question

Scenario: The user can answer a question
Given A logged-in user
When I play on Classic mode and click on an answer
Then The right answer should be colored green
2 changes: 1 addition & 1 deletion webapp/e2e/steps/aboutus.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/aboutus.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/config.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/config.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/creategroup.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/creategroup.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/history.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/history.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/login-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/login-form.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/logout.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/logout.feature");

let page;
let browser;
Expand Down
57 changes: 57 additions & 0 deletions webapp/e2e/steps/play-classic.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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/play-classic.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();
setDefaultOptions({ timeout: 10000 });

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

test("The user can answer a question", ({ given, when, then }) => {
given("A logged-in user", async () => {

await page.type("#login-username", "testuser");
await page.type("#login-password", "Testpassword1");
await page.click("button", { text: "Login" });
await page.waitForNavigation();
});

when("I play on Classic mode and click on an answer", async () => {
await page.click('[data-testid="classic-mode"]');
await page.waitForNavigation();

await page.waitForSelector('[data-testid="question"]');

await page.click('[data-testid="answer-button"]');
});

then("The right answer should be colored green", async () => {
await page.waitForTimeout(3000);

const correctAnswerColor = await page.evaluate(() => {
const answerButton = document.querySelector('[data-testid="answer-button"]');
return window.getComputedStyle(answerButton).getPropertyValue("background-color");
});

expect(correctAnswerColor).toMatch("rgb(16, 255, 0)");
});
});

afterAll(async () => {
await browser.close();
});
});
2 changes: 1 addition & 1 deletion webapp/e2e/steps/profile.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/profile.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/ranking-sorting.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/ranking-sorting.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/ranking.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/ranking.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/stats.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/stats.feature");

let page;
let browser;
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/users-addfriend.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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");
const feature = loadFeature("./features/users-addfriend.feature");

let page;
let browser;
Expand Down

0 comments on commit 6b2b003

Please sign in to comment.