Skip to content

Commit

Permalink
Añado mas e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uo285427 committed Apr 29, 2024
1 parent 6d83d98 commit db789bb
Show file tree
Hide file tree
Showing 4 changed files with 1,043 additions and 234 deletions.
11 changes: 11 additions & 0 deletions webapp/e2e/features/settings.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Changing the game settings

Scenario: A registered user changes the number of questions in the game
Given A registered user in the settings view
When I change the game settings to 5 questions
Then the game settings should be updated

Scenario: A registered user changes the time limit in the game
Given A registered user in the settings view
When I change the game settings to 5:30 minutes
Then the game settings should be updated
110 changes: 110 additions & 0 deletions webapp/e2e/steps/settings.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/settings.feature');
const {textVerifyByXpath}=require('../steps_testUtils');

let page;
let browser;

defineFeature(feature, test => {
const username = "testUserSettings"
const password = "testUserSettings"
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 1 });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 })

await page
.goto("http://localhost:3000", {
waitUntil: "networkidle0",
})
.catch(() => {});
await expect(page).toClick("button", { text: "¿No tienes cuenta? Registrate aqui." });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Añadir usuario' })
await page.waitForNavigation();
});
beforeEach(async()=>{
await page
.goto("http://localhost:3000", {
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: 'Iniciar sesión' })
});
afterAll(async ()=>{
browser.close();
});


test('A registered user changes the number of questions', ({given,when,then}) => {
given('A registered user in the play view', async () => {
await expect(page).toClick('button', { text: 'AJUSTES DE PARTIDA' });
});

when('I change the game settings to 5 questions', async () => {
await page.waitForSelector('.MuiSlider-root');
changeSliderValueTo5();
});
then('the game settings should be updated', async () => {
await expect(page).toClick('button', { text: 'JUGAR' });
await expect(page).toClick('button', { text: 'COMENZAR A JUGAR' })
await expect(getByText('Pregunta Número 1')).toBeInTheDocument();
await expect(page).toClick('.MuiGrid-root:nth-child(1) > .MuiButtonBase-root')
await waitFor(() => expect(getByText('Pregunta Número 2')).toBeInTheDocument());
await expect(page).toClick('.MuiGrid-root:nth-child(1) > .MuiButtonBase-root')
await waitFor(() => expect(getByText('Pregunta Número 3')).toBeInTheDocument());
await expect(page).toClick('.MuiGrid-root:nth-child(1) > .MuiButtonBase-root')
await waitFor(() => expect(getByText('Pregunta Número 4')).toBeInTheDocument());
await expect(page).toClick('.MuiGrid-root:nth-child(1) > .MuiButtonBase-root')
await waitFor(() => expect(getByText('Pregunta Número 5')).toBeInTheDocument());
await expect(page).toClick('.MuiGrid-root:nth-child(1) > .MuiButtonBase-root')
await expect(getByText('¡Gracias por jugar!')).toBeInTheDocument();
});

test('A registered user changes the number of questions', ({given,when,then}) => {
given('A registered user in the play view', async () => {
await expect(page).toClick('button', { text: 'AJUSTES DE PARTIDA' });
});

when('I change the game settings to 5:30 minutes', async () => {
await expect(page).toClick('button', { text: 'DURACIÓN DE PARTIDA' });
await expect(page).toFill('input[name="Minutos"]', 5);
await expect(page).toFill('input[name="Segundos"]', 30);
});
then('the game settings should be updated', async () => {
await expect(page).toClick('button', { text: 'JUGAR' });
await expect(page).toClick('button', { text: 'COMENZAR A JUGAR' })
await expect(getByText('¡Tiempo restante 05:30!')).toBeInTheDocument();
});

});
});

async function changeSliderValueTo5() {
const slider = await page.$('.MuiSlider-root');

const sliderRect = await slider.boundingBox();

const sliderMidX = sliderRect.x + sliderRect.width / 2;
const sliderMidY = sliderRect.y + sliderRect.height / 2;

const initialValue = 10;
const targetValue = 5;
const steps = (initialValue - targetValue) / 5;

await page.mouse.move(sliderMidX, sliderMidY);
await page.mouse.down();
for (let i = 0; i < steps; i++) {
await page.mouse.move(sliderMidX - 50, sliderMidY, { steps: 10 });
}
await page.mouse.up();
}
});

Loading

0 comments on commit db789bb

Please sign in to comment.