Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Añadido test e2e Jugar #45

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions webapp/e2e/features/jugar-form.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Game Initialization

Scenario: User Initiates a Game
Given a registered user exists
When the user enters their details on the login form and submits
And the user clicks the "Play" button on the homepage
Then the questions should be displayed
65 changes: 65 additions & 0 deletions webapp/e2e/steps/jugar-form.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature } = require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions;
const feature = loadFeature('./features/jugar-form.feature');

let page;
let browser;

defineFeature(feature, (test) => {
let username;
let password;

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/login", {
waitUntil: "networkidle0",
}).catch(() => {});
}, 60000);

test('User Initiates a Game', ({ given, when, then }) => {

given('a registered user exists', async () => {
username = "zohaib"
password = "zohaib"
});

when('the user enters their details on the login form and submits', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Entrar' })
});

when('the user clicks the "Play" button on the homepage', async () => {
await expect(page).toClick('button', { text: 'JUGAR' })
});

then('the questions should be displayed', async () => {
await expect(page).toMatchElement('.quiz-header');

// Recuperar y verificar el texto de la pregunta actual
const questionText = await page.$eval('.quiz-header h2', el => el.textContent);
expect(questionText).toBeTruthy();

// Opcionalmente, puedes verificar el número de la pregunta actual vs. el total
const questionIndicatorText = await page.$eval('.quiz-header div', el => el.textContent);
expect(questionIndicatorText).toMatch(/Pregunta \d+ de \d+/);

// Verificar que las opciones de respuesta se muestran
const answersCount = await page.$$eval('.answers-list li', answers => answers.length);
expect(answersCount).toBe(4);

});

});

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

});
3 changes: 2 additions & 1 deletion webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let mongoserver;
let userservice;
let authservice;
let gatewayservice;

let questionservice;
async function startServer() {
console.log('Starting MongoDB memory server...');
mongoserver = await MongoMemoryServer.create();
Expand All @@ -14,6 +14,7 @@ async function startServer() {
userservice = await require("../../users/userservice/user-service");
authservice = await require("../../users/authservice/auth-service");
gatewayservice = await require("../../gatewayservice/gateway-service");
questionservice = await requiree("../../questionservice/question-service");
}

startServer();
2 changes: 2 additions & 0 deletions webapp/src/components/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ const Login = () => {
Entrar
</Typography>
<TextField
name ="username"
margin="normal"
fullWidth
label="Nombre de Usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<TextField
name = "password"
margin="normal"
fullWidth
label="Contraseña"
Expand Down