Skip to content

Commit

Permalink
Merge pull request #46 from Arquisoft/yago
Browse files Browse the repository at this point in the history
Añadido test e2e history y login
  • Loading branch information
Verzidee authored Apr 7, 2024
2 parents 2d8d2c8 + e5489d2 commit f27f58a
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
11 changes: 11 additions & 0 deletions webapp/e2e/features/history.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Seeing the loged user history

Scenario: The user is not loged in the site
Given A not loged user
When Press history
Then Redirected to login

Scenario: The user is loged in the site so he can see history
Given A registered user, i fill the login
When I press history
Then I see my history
6 changes: 6 additions & 0 deletions webapp/e2e/features/login-form.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Login a existing user

Scenario: The user is registered in the site
Given A registered user, fill the data
When Presses submit
Then The user is redirected
79 changes: 79 additions & 0 deletions webapp/e2e/steps/history.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/register-form.feature');

let page;
let browser;

defineFeature(feature, test => {

let username = "usuario"
let password = "contraseña"

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

//Registrar al user
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Registrarse' });

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

}, 60000);

test('The user is not loged in the site', ({given,when,then}) => {

given('A not loged user', async () => {

});

when('Press history', async () => {
await expect(page).toClick('button', { text: 'Historial' });
});

then('Redirected to login', async () => {
await expect(page).toMatchElement('div', { text: 'Entrar' });
});
})

test('The user is loged in the site so he can see history', ({given,when,then}) => {

given('A registered user, i fill the login', async () => {
await page.goto("http://localhost:3000/login", {
waitUntil: "networkidle0",
}).catch(() => {});
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Entrar' });
});

when('I press history', async () => {
await expect(page).toClick('button', { text: 'Historial' });
});

then('I see my history', async () => {
await expect(page).toMatchElement('h1', { text: 'HISTORIAL' });
await expect(page).toMatch('Número de Partidas:');
await expect(page).toMatch('Número de Preguntas Jugadas:');
await expect(page).toMatch('Número de acertadas:');
await expect(page).toMatch('Número de falladas:');
});
})

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

});
54 changes: 54 additions & 0 deletions webapp/e2e/steps/login-form.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/register-form.feature');

let page;
let browser;

defineFeature(feature, test => {

let username = "usuario"
let password = "contraseña"

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

//Registrar al user

await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Registrarse' })

}, 60000);

test('The user is registered in the site', ({given,when,then}) => {

given('A registered user, fill the data', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
});

when('Presses submit', async () => {
await expect(page).toClick('button', { text: 'Entrar' });
});


then('The user is redirected', async () => {
await expect(page).toMatchElement("div", { text: "Inicio de sesión exitoso" });
});
})

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

});
2 changes: 2 additions & 0 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { MongoMemoryServer } = require('mongodb-memory-server');
let mongoserver;
let userservice;
let authservice;
let historyservice;
let gatewayservice;
let questionservice;
async function startServer() {
Expand All @@ -13,6 +14,7 @@ async function startServer() {
process.env.MONGODB_URI = mongoUri;
userservice = await require("../../users/userservice/user-service");
authservice = await require("../../users/authservice/auth-service");
historyservice = await require("../../users/historyservice/history-service");
gatewayservice = await require("../../gatewayservice/gateway-service");
questionservice = await requiree("../../questionservice/question-service");
}
Expand Down

0 comments on commit f27f58a

Please sign in to comment.