From 1afbafd47001a3b27e0d28219cc4d3ac15b45662 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 13:37:32 +0200 Subject: [PATCH 01/32] =?UTF-8?q?A=C3=B1adidos=20e2e=20al=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 61 ++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 682f2937..71563304 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,25 +9,42 @@ jobs: unit-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - run: npm --prefix users/authservice ci - - run: npm --prefix users/userservice ci - - run: npm --prefix gatewayservice ci - - run: npm --prefix questionservice ci - - run: npm --prefix statsservice ci - - run: npm --prefix webapp ci - - run: npm --prefix users/authservice test -- --coverage - - run: npm --prefix users/userservice test -- --coverage - - run: npm --prefix gatewayservice test -- --coverage - - run: npm --prefix statsservice test -- --coverage - - run: npm --prefix webapp test -- --coverage - - name: Analyze with SonarCloud - uses: sonarsource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm --prefix users/authservice ci + - run: npm --prefix users/userservice ci + - run: npm --prefix gatewayservice ci + - run: npm --prefix questionservice ci + - run: npm --prefix statsservice ci + - run: npm --prefix webapp ci + - run: npm --prefix users/authservice test -- --coverage + - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix gatewayservice test -- --coverage + - run: npm --prefix statsservice test -- --coverage + - run: npm --prefix webapp test -- --coverage + - name: Analyze with SonarCloud + uses: sonarsource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + e2e-tests: + needs: [unit-tests] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm --prefix users/authservice install + - run: npm --prefix users/userservice install + - run: npm --prefix gatewayservice install + - run: npm --prefix questionservice install + - run: npm --prefix statsservice install + - run: npm --prefix webapp install + - run: npm --prefix webapp run build + - run: npm --prefix webapp run test:e2e From ad17021d072d171b2914fd4d0f2b0b142a05847a Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 14:02:54 +0200 Subject: [PATCH 02/32] A ver si es esto --- webapp/e2e/steps/login-form.steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index fb556324..59ab93f9 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -41,7 +41,7 @@ defineFeature(feature, (test) => { }); then("The home screen should be shown", async () => { - await page.waitForTimeout(1000); + await page.waitForTimeout(3000); const url = page.url(); expect(url).toContain("/home"); browser.close(); From a4a2f860442b9c0a4f8667ecb5e8f92d4ce3f077 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 14:12:15 +0200 Subject: [PATCH 03/32] Puede ser error de viewport --- webapp/e2e/steps/logout.steps.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index da41b353..3459ae90 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -11,8 +11,11 @@ defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 100 }); + : await puppeteer.launch({ headless: false, slowMo: 100 }); page = await browser.newPage(); + + await page.setViewport({ width: 600, height: 800 }); + //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }); From 3313ad7b3f1b33b6c90a396661d6d8e1a1bc467c Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 14:31:06 +0200 Subject: [PATCH 04/32] Igual es esto --- webapp/e2e/steps/logout.steps.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 3459ae90..e22da8ed 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -14,7 +14,7 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: false, slowMo: 100 }); page = await browser.newPage(); - await page.setViewport({ width: 600, height: 800 }); + await page.setViewport({ width: 1600, height: 800 }); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }); @@ -43,10 +43,9 @@ defineFeature(feature, (test) => { when("I click on the Logout link", async () => { await page.waitForTimeout(1000); - - await page.click('button[aria-label="Abrir menú"]'); - await page.waitForSelector('[data-testid="home-logout-link"]'); - await page.click('[data-testid="home-logout-link"]'); + await page.click('#menu-button-\\:r3\\:'); + await page.waitForSelector('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); + await page.click('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); //await page.waitForNavigation({ waitUntil: "networkidle0" }); }); From 369bec101e92c030c4fc19c131ff985ed540d1ec Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 14:40:41 +0200 Subject: [PATCH 05/32] con timeout --- webapp/e2e/steps/logout.steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index e22da8ed..7af8a0c2 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -42,7 +42,7 @@ defineFeature(feature, (test) => { }); when("I click on the Logout link", async () => { - await page.waitForTimeout(1000); + await page.waitForTimeout(10000); await page.click('#menu-button-\\:r3\\:'); await page.waitForSelector('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); await page.click('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); From f8d12d9ce653f2dec09e77f2d3da62f73af49d69 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 14:58:03 +0200 Subject: [PATCH 06/32] Console del HTML para debuguear --- webapp/e2e/steps/logout.steps.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 7af8a0c2..b8b7841a 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -42,6 +42,8 @@ defineFeature(feature, (test) => { }); when("I click on the Logout link", async () => { + let src = await page.content(); + console.log(src); await page.waitForTimeout(10000); await page.click('#menu-button-\\:r3\\:'); await page.waitForSelector('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); From a1a60a849a55ef3d082deb690583f9670c6f4358 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 15:15:06 +0200 Subject: [PATCH 07/32] Mockeando en logout --- webapp/e2e/steps/logout.steps.js | 42 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index b8b7841a..e35eb724 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -10,12 +10,10 @@ let browser; defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) + ? await puppeteer.launch({ headless: "new", slowMo: 100 }) : await puppeteer.launch({ headless: false, slowMo: 100 }); page = await browser.newPage(); - await page.setViewport({ width: 1600, height: 800 }); - //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }); @@ -24,11 +22,25 @@ defineFeature(feature, (test) => { waitUntil: "networkidle0", }) .catch(() => {}); + + await page.setRequestInterception(true); + page.on('request', (req) => { + if (req.method() === 'OPTIONS'){ + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': '*' + } + }); + } + }); }); let username; let password; - + test("The user can logout", ({ given, when, then }) => { given("A logged-in user", async () => { username = "testuser"; @@ -42,19 +54,23 @@ defineFeature(feature, (test) => { }); when("I click on the Logout link", async () => { - let src = await page.content(); - console.log(src); + const bodyHTML = await page.evaluate(() => document.body.innerHTML); + console.log(bodyHTML); + await page.waitForTimeout(10000); - await page.click('#menu-button-\\:r3\\:'); - await page.waitForSelector('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); - await page.click('#menu-list-\\:r3\\:-menuitem-\\:r9\\:'); + await page.click("#menu-button-\\:r3\\:"); + await page.waitForSelector("#menu-list-\\:r3\\:-menuitem-\\:r9\\:"); + await page.click("#menu-list-\\:r3\\:-menuitem-\\:r9\\:"); //await page.waitForNavigation({ waitUntil: "networkidle0" }); }); - then("The user should be logged out and the Login screen should be shown", async () => { - const url = page.url(); - expect(url).toContain("/login"); - }); + then( + "The user should be logged out and the Login screen should be shown", + async () => { + const url = page.url(); + expect(url).toContain("/login"); + } + ); }); afterAll(async () => { From 3371b953bd0a414c601e289a4b5c0096ebdf1fe6 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 15:15:26 +0200 Subject: [PATCH 08/32] Fix --- webapp/e2e/steps/logout.steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index e35eb724..0243868b 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -34,7 +34,7 @@ defineFeature(feature, (test) => { 'Access-Control-Allow-Headers': '*' } }); - } + } else {req.continue();} }); }); From c1695a075d5a05aba7c8a04fe1f3dbda2a26fd0e Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 15:31:20 +0200 Subject: [PATCH 09/32] A ver ahora --- webapp/e2e/steps/logout.steps.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 0243868b..4867df57 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -23,19 +23,21 @@ defineFeature(feature, (test) => { }) .catch(() => {}); - await page.setRequestInterception(true); - page.on('request', (req) => { - if (req.method() === 'OPTIONS'){ - req.respond({ - status: 200, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': '*' - } - }); - } else {req.continue();} - }); + await page.setRequestInterception(true); + page.on("request", (req) => { + if (req.method() === "OPTIONS") { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, + }); + } else { + req.continue(); + } + }); }); let username; @@ -50,7 +52,7 @@ defineFeature(feature, (test) => { await page.waitForSelector("#login-password"); await page.type("#login-password", password); await page.click("button", { text: "Login" }); - //await page.waitForNavigation({ waitUntil: "networkidle0" }); + await page.waitForNavigation({ waitUntil: "networkidle0" }); }); when("I click on the Logout link", async () => { From 53eb73fe27a929ed438aad5014694aff29db9116 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 15:42:52 +0200 Subject: [PATCH 10/32] =?UTF-8?q?A=C3=B1adido=20wait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/logout.steps.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 4867df57..3ca186f5 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -52,14 +52,12 @@ defineFeature(feature, (test) => { 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 Logout link", async () => { - const bodyHTML = await page.evaluate(() => document.body.innerHTML); - console.log(bodyHTML); await page.waitForTimeout(10000); + await page.waitForSelector("#menu-button-\\:r3\\:"); await page.click("#menu-button-\\:r3\\:"); await page.waitForSelector("#menu-list-\\:r3\\:-menuitem-\\:r9\\:"); await page.click("#menu-list-\\:r3\\:-menuitem-\\:r9\\:"); From a7035a057b0c58424e1460bf02e50bbd7917b7d0 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 16:12:58 +0200 Subject: [PATCH 11/32] A ver si es esto --- webapp/e2e/steps/play-calculator.steps.js | 77 ++++++++++++++++++++--- 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index 6b6bb2c7..fb571e0d 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -11,8 +11,8 @@ let browser; defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 100 }); + ? await puppeteer.launch({ headless: "new", slowMo: 100 }) + : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); @@ -20,10 +20,59 @@ defineFeature(feature, (test) => { waitUntil: "networkidle0", }); + await page.setRequestInterception(true); + page.on("request", (req) => { + if (req.method() === "OPTIONS") { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, + }); + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); + } else { + req.continue(); + } + }); }); let username; let password; - test("The user can answer a question on Human Calculator mode", ({ given, when, then }) => { + test("The user can answer a question on Human Calculator mode", ({ + given, + when, + then, + }) => { given("A logged-in user", async () => { username = "testuser"; password = "Testpassword1"; @@ -32,19 +81,27 @@ defineFeature(feature, (test) => { await page.waitForSelector("#login-password"); await page.type("#login-password", password); await page.click("button", { text: "Login" }); - + //await page.waitForNavigation({ waitUntil: "networkidle0" }); }); when("I play on Human Calculator mode and answer incorrectly", async () => { await page.waitForTimeout(1000); - await page.waitForXPath('//button[contains(text(), "Calculadora humana")]'); - const button = await page.$x('//button[contains(text(), "Calculadora humana")]'); + await page.waitForXPath( + '//button[contains(text(), "Calculadora humana")]' + ); + const button = await page.$x( + '//button[contains(text(), "Calculadora humana")]' + ); await button[0].click(); //await page.waitForNavigation({ waitUntil: "networkidle0" }); - await page.waitForXPath('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); - const jugarButton = await page.$x('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); + await page.waitForXPath( + '//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]' + ); + const jugarButton = await page.$x( + '//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]' + ); await jugarButton[0].click(); await page.waitForSelector('[data-testid="operation"]'); @@ -59,8 +116,8 @@ defineFeature(feature, (test) => { await page.waitForSelector('[data-testid="play-again-button"]'); const gameOverMessage = await page.evaluate(() => { - return document.querySelector('[data-testid="play-again-button"]').textContent; - + return document.querySelector('[data-testid="play-again-button"]') + .textContent; }); expect(gameOverMessage).toContain("Jugar de nuevo"); From 1e930ccd0c05c608c67b4620f6eee8e406c90268 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 16:20:39 +0200 Subject: [PATCH 12/32] Inexplicablemente era esto (creo) --- webapp/e2e/steps/add-friend.steps.js | 36 ++++++++++++++ webapp/e2e/steps/create-group.steps.js | 36 ++++++++++++++ webapp/e2e/steps/login-form.steps.js | 60 +++++++++++++++++++++--- webapp/e2e/steps/logout.steps.js | 31 ++++++++++++- webapp/e2e/steps/register-form.steps.js | 62 +++++++++++++++++++++---- 5 files changed, 209 insertions(+), 16 deletions(-) diff --git a/webapp/e2e/steps/add-friend.steps.js b/webapp/e2e/steps/add-friend.steps.js index 8175654c..18c9ea1a 100644 --- a/webapp/e2e/steps/add-friend.steps.js +++ b/webapp/e2e/steps/add-friend.steps.js @@ -19,6 +19,42 @@ defineFeature(feature, (test) => { await page.goto("http://localhost:3000", { waitUntil: "networkidle0", }); + + await page.setRequestInterception(true); + page.on('request', (req) => { + if (req.method() === 'OPTIONS'){ + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': '*' + } + }); + } else if (req.url().includes('/questions')) { + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*' + }, + contentType: 'application/json', + body: JSON.stringify([{ + pregunta: 'Test question', + respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], + correcta: 'Test correct answer', + + }, { + pregunta: 'Test question 2', + respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], + correcta: 'Test correct answer' + }] + ) + }); + } else { + req.continue(); + } + }); + }); let username; let password; diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index f401cb18..341c8754 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -19,6 +19,42 @@ defineFeature(feature, (test) => { await page.goto("http://localhost:3000", { waitUntil: "networkidle0", }); + + await page.setRequestInterception(true); + page.on('request', (req) => { + if (req.method() === 'OPTIONS'){ + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': '*' + } + }); + } else if (req.url().includes('/questions')) { + req.respond({ + status: 200, + headers: { + 'Access-Control-Allow-Origin': '*' + }, + contentType: 'application/json', + body: JSON.stringify([{ + pregunta: 'Test question', + respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], + correcta: 'Test correct answer', + + }, { + pregunta: 'Test question 2', + respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], + correcta: 'Test correct answer' + }] + ) + }); + } else { + req.continue(); + } + }); + }); let username; let password; diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index 59ab93f9..e0cad621 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -10,8 +10,8 @@ let browser; defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 100 }); + ? await puppeteer.launch({ headless: "new", slowMo: 100 }) + : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }); @@ -21,6 +21,52 @@ defineFeature(feature, (test) => { waitUntil: "networkidle0", }) .catch(() => {}); + + await page.setRequestInterception(true); + page.on("request", (req) => { + if (req.method() === "OPTIONS") { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, + }); + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); + } else { + req.continue(); + } + }); }); test("The user is registered in the site", ({ given, when, then }) => { @@ -33,10 +79,10 @@ defineFeature(feature, (test) => { }); when("I fill the data in the form and press submit", async () => { - await page.waitForSelector('#login-username'); - await page.type('#login-username', username); - await page.waitForSelector('#login-password'); - await page.type('#login-password', password); + 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" }); }); @@ -51,4 +97,4 @@ defineFeature(feature, (test) => { afterAll(async () => { browser.close(); }); -}); \ No newline at end of file +}); diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 3ca186f5..14f90762 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -34,6 +34,36 @@ defineFeature(feature, (test) => { "Access-Control-Allow-Headers": "*", }, }); + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); } else { req.continue(); } @@ -55,7 +85,6 @@ defineFeature(feature, (test) => { }); when("I click on the Logout link", async () => { - await page.waitForTimeout(10000); await page.waitForSelector("#menu-button-\\:r3\\:"); await page.click("#menu-button-\\:r3\\:"); diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index ba2d80c0..0095fd95 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -10,8 +10,8 @@ let browser; defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 100 }); + ? await puppeteer.launch({ headless: "new", slowMo: 100 }) + : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }); @@ -21,6 +21,52 @@ defineFeature(feature, (test) => { waitUntil: "networkidle0", }) .catch(() => {}); + + await page.setRequestInterception(true); + page.on("request", (req) => { + if (req.method() === "OPTIONS") { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, + }); + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); + } else { + req.continue(); + } + }); }); test("The user is not registered in the site", ({ given, when, then }) => { @@ -34,12 +80,12 @@ defineFeature(feature, (test) => { when("I fill the data in the form and press submit", async () => { username = "papapa"; password = "Testpassword1"; - await page.waitForSelector('#register-username'); - await page.type('#register-username', username); - await page.waitForSelector('#register-password'); - await page.type('#register-password', password); - await page.waitForSelector('#register-pass2'); - await page.type('#register-pass2', password); + await page.waitForSelector("#register-username"); + await page.type("#register-username", username); + await page.waitForSelector("#register-password"); + await page.type("#register-password", password); + await page.waitForSelector("#register-pass2"); + await page.type("#register-pass2", password); await page.click("button", { text: "Registrarse" }); }); From 319da12b6559adb93d0c2f513943fc8a85af7e7e Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 16:42:00 +0200 Subject: [PATCH 13/32] Ajuste slowMo --- webapp/e2e/steps/play-classic.steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/e2e/steps/play-classic.steps.js b/webapp/e2e/steps/play-classic.steps.js index e73a61dd..bbc2a3d4 100644 --- a/webapp/e2e/steps/play-classic.steps.js +++ b/webapp/e2e/steps/play-classic.steps.js @@ -12,7 +12,7 @@ defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 10 }); + : await puppeteer.launch({ headless: 'new', slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); From 3d67a8e5dad52a4e74b1be5fe7f22264e7c814b9 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 16:56:01 +0200 Subject: [PATCH 14/32] Prueba --- webapp/e2e/steps/play-calculator.steps.js | 30 ----------------------- 1 file changed, 30 deletions(-) diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index fb571e0d..e175ae33 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -31,36 +31,6 @@ defineFeature(feature, (test) => { "Access-Control-Allow-Headers": "*", }, }); - } else if (req.url().includes("/questions")) { - req.respond({ - status: 200, - headers: { - "Access-Control-Allow-Origin": "*", - }, - contentType: "application/json", - body: JSON.stringify([ - { - pregunta: "Test question", - respuestas: [ - "Test answer 1", - "Test answer 2", - "Test answer 3", - "Test correct answer", - ], - correcta: "Test correct answer", - }, - { - pregunta: "Test question 2", - respuestas: [ - "Test answer 1", - "Test answer 2", - "Test answer 3", - "Test correct answer", - ], - correcta: "Test correct answer", - }, - ]), - }); } else { req.continue(); } From 383141ae574ed307860159ac49ef453373b89b83 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:04:43 +0200 Subject: [PATCH 15/32] A ver si ye de esta --- webapp/e2e/steps/play-battery.steps.js | 20 ++++---- webapp/e2e/steps/play-calculator.steps.js | 56 +++++++++++++++++------ 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index e1645087..40cbb338 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -59,17 +59,9 @@ defineFeature(feature, (test) => { let firstquestion; test("The user can answer a question on Battery mode", ({ given, when, then }) => { 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 play on Battery mode and click on an answer", async () => { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + await page.waitForTimeout(1000); await page.waitForXPath('//button[contains(text(), "Batería de sabios")]'); const button = await page.$x('//button[contains(text(), "Batería de sabios")]'); @@ -80,6 +72,12 @@ defineFeature(feature, (test) => { const jugarButton = await page.$x('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); await jugarButton[0].click(); + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + }); + + when("I play on Battery mode and click on an answer", async () => { + + await page.waitForSelector('[data-testid="question"]'); firstquestion = await page.evaluate(element => diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index e175ae33..9d0637e5 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -16,7 +16,7 @@ defineFeature(feature, (test) => { page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); - await page.goto("http://localhost:3000", { + await page.goto("http://localhost:3000/home/calculadora", { waitUntil: "networkidle0", }); @@ -31,31 +31,50 @@ defineFeature(feature, (test) => { "Access-Control-Allow-Headers": "*", }, }); + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); } else { req.continue(); } }); }); - let username; - let password; test("The user can answer a question on Human Calculator mode", ({ given, when, then, }) => { 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" }); - }); + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); - when("I play on Human Calculator mode and answer incorrectly", async () => { await page.waitForTimeout(1000); await page.waitForXPath( '//button[contains(text(), "Calculadora humana")]' @@ -64,7 +83,6 @@ defineFeature(feature, (test) => { '//button[contains(text(), "Calculadora humana")]' ); await button[0].click(); - //await page.waitForNavigation({ waitUntil: "networkidle0" }); await page.waitForXPath( '//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]' @@ -73,6 +91,14 @@ defineFeature(feature, (test) => { '//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]' ); await jugarButton[0].click(); + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + }); + + when("I play on Human Calculator mode and answer incorrectly", async () => { + + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + + await page.waitForSelector('[data-testid="operation"]'); const answer = -999; From ba78b081f3e43277ca75da58a19ee36835b33697 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 17:06:10 +0200 Subject: [PATCH 16/32] =?UTF-8?q?A=C3=B1adido=20token=20a=20add-friend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/add-friend.steps.js | 106 +++++++++++++++------------ 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/webapp/e2e/steps/add-friend.steps.js b/webapp/e2e/steps/add-friend.steps.js index 18c9ea1a..36e6d6e5 100644 --- a/webapp/e2e/steps/add-friend.steps.js +++ b/webapp/e2e/steps/add-friend.steps.js @@ -11,8 +11,8 @@ let browser; defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 100 }); + ? await puppeteer.launch({ headless: "new", slowMo: 100 }) + : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); @@ -21,40 +21,50 @@ defineFeature(feature, (test) => { }); await page.setRequestInterception(true); - page.on('request', (req) => { - if (req.method() === 'OPTIONS'){ + page.on("request", (req) => { + if (req.method() === "OPTIONS") { req.respond({ status: 200, headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': '*' - } + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, }); - } else if (req.url().includes('/questions')) { - req.respond({ - status: 200, - headers: { - 'Access-Control-Allow-Origin': '*' - }, - contentType: 'application/json', - body: JSON.stringify([{ - pregunta: 'Test question', - respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], - correcta: 'Test correct answer', - - }, { - pregunta: 'Test question 2', - respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], - correcta: 'Test correct answer' - }] - ) - }); - } else { - req.continue(); - } - }); - + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); + } else { + req.continue(); + } + }); }); let username; let password; @@ -62,14 +72,14 @@ defineFeature(feature, (test) => { test("The user can add a friend", ({ given, when, then }) => { given("A logged-in user and another user", async () => { await expect(page).toClick("a", { text: "Regístrate" }); - username="Friend"; - password="Friend123"; - await page.waitForSelector('#register-username'); - await page.type('#register-username', username); - await page.waitForSelector('#register-password'); - await page.type('#register-password', password); - await page.waitForSelector('#register-pass2'); - await page.type('#register-pass2', password); + username = "Friend"; + password = "Friend123"; + await page.waitForSelector("#register-username"); + await page.type("#register-username", username); + await page.waitForSelector("#register-password"); + await page.type("#register-password", password); + await page.waitForSelector("#register-pass2"); + await page.type("#register-pass2", password); await page.click("button", { text: "Registrarse" }); await page.waitForTimeout(1000); @@ -91,6 +101,13 @@ defineFeature(feature, (test) => { when("I add the user as a friend", async () => { await page.waitForTimeout(1000); + localStorage.setItem("username", "testuser"); + localStorage.setItem("token", "testtoken"); + + await page.goto("http://localhost:3000/social/usuarios", { + waitUntil: "networkidle0", + }); + await page.click('button[aria-label="Abrir menú"]'); await page.click('[data-testid="home-usuarios-link"]'); //await page.waitForNavigation({ waitUntil: "networkidle0" }); @@ -101,23 +118,20 @@ defineFeature(feature, (test) => { await page.waitForSelector('[data-testid^="add-friend-button-"]'); await page.click('[data-testid^="add-friend-button-"]'); - - }); + }); then("The user should disappear from the Users page", async () => { - await page.waitForTimeout(1000); await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] }); const userRowsAfter = await page.$$('[data-testid^="user-row-"]'); const userCountAfter = userRowsAfter.length; - - expect(userCountAfter).toBe(userCountBefore - 1); + expect(userCountAfter).toBe(userCountBefore - 1); }); }); afterAll(async () => { await browser.close(); }); -}); \ No newline at end of file +}); From 477d6be4e63a1751bec6eb7b51fa59760817387b Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:06:28 +0200 Subject: [PATCH 17/32] Fix --- webapp/e2e/steps/play-battery.steps.js | 9 ++++----- webapp/e2e/steps/play-calculator.steps.js | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index 40cbb338..6fcce1c1 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -15,8 +15,9 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: 'new', slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); - - await page.goto("http://localhost:3000", { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + await page.goto("http://localhost:3000/home/bateria", { waitUntil: "networkidle0", }); await page.setRequestInterception(true); @@ -59,9 +60,7 @@ defineFeature(feature, (test) => { let firstquestion; test("The user can answer a question on Battery mode", ({ given, when, then }) => { given("A logged-in user", async () => { - localStorage.setItem("username","testuser"); - localStorage.setItem("token","abcdefg"); - + await page.waitForTimeout(1000); await page.waitForXPath('//button[contains(text(), "Batería de sabios")]'); const button = await page.$x('//button[contains(text(), "Batería de sabios")]'); diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index 9d0637e5..a7322d9a 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -15,7 +15,8 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); - + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); await page.goto("http://localhost:3000/home/calculadora", { waitUntil: "networkidle0", }); @@ -72,8 +73,6 @@ defineFeature(feature, (test) => { then, }) => { given("A logged-in user", async () => { - localStorage.setItem("username","testuser"); - localStorage.setItem("token","abcdefg"); await page.waitForTimeout(1000); await page.waitForXPath( From b1bc9c7dd8332153774451c21c90687938c616df Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:14:01 +0200 Subject: [PATCH 18/32] A ver si asi colega --- webapp/e2e/steps/play-battery.steps.js | 6 ++++-- webapp/e2e/steps/play-calculator.steps.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index 6fcce1c1..25d8412e 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -15,8 +15,10 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: 'new', slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); - localStorage.setItem("username","testuser"); - localStorage.setItem("token","abcdefg"); + await page.evaluate(() => { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + }); await page.goto("http://localhost:3000/home/bateria", { waitUntil: "networkidle0", }); diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index a7322d9a..d5a59141 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -15,8 +15,11 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); - localStorage.setItem("username","testuser"); - localStorage.setItem("token","abcdefg"); + await page.evaluate(() => { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + }); + await page.goto("http://localhost:3000/home/calculadora", { waitUntil: "networkidle0", }); From baf617431f38676f8c8117c3434afd56ef95485c Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 17:14:50 +0200 Subject: [PATCH 19/32] =?UTF-8?q?A=C3=B1adido=20evaluate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/create-group.steps.js | 4 ++-- webapp/e2e/steps/logout.steps.js | 18 +++++++++++------- webapp/e2e/steps/play-battery.steps.js | 11 ++++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index 341c8754..e7159b7d 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -92,8 +92,8 @@ defineFeature(feature, (test) => { const alertElement = document.querySelector('div[role="alert"]'); return alertElement.innerText.trim(); }); - const rightMessage=alertText === "Group created successfully"; - expect(rightMessage).toBe(true); + const rightMessage = "Group created successfully"; + expect(rightMessage).toBe(alertText); }); }); diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 14f90762..90ec4c45 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -75,13 +75,17 @@ defineFeature(feature, (test) => { test("The user can logout", ({ given, when, then }) => { 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.evaluate(() => { + localStorage.clear(); + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + }); + + await page + .goto("http://localhost:3000/home", { + waitUntil: "networkidle0", + }) + .catch(() => {}); }); when("I click on the Logout link", async () => { diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index 40cbb338..cbf86306 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -59,9 +59,12 @@ defineFeature(feature, (test) => { let firstquestion; test("The user can answer a question on Battery mode", ({ given, when, then }) => { given("A logged-in user", async () => { - localStorage.setItem("username","testuser"); - localStorage.setItem("token","abcdefg"); - + await page.evaluate(() => { + localStorage.clear(); + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + }); + await page.waitForTimeout(1000); await page.waitForXPath('//button[contains(text(), "Batería de sabios")]'); const button = await page.$x('//button[contains(text(), "Batería de sabios")]'); @@ -76,8 +79,6 @@ defineFeature(feature, (test) => { }); when("I play on Battery mode and click on an answer", async () => { - - await page.waitForSelector('[data-testid="question"]'); firstquestion = await page.evaluate(element => From 10a995d48e9860a28c8300a6d85d442df6a14b31 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:23:26 +0200 Subject: [PATCH 20/32] Porfi --- webapp/e2e/steps/play-battery.steps.js | 7 +++++++ webapp/e2e/steps/play-calculator.steps.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index 25d8412e..bd466c11 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -15,13 +15,20 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: 'new', slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); + + await page.goto("http://localhost:3000", { + waitUntil: "networkidle0", + }); + await page.evaluate(() => { localStorage.setItem("username","testuser"); localStorage.setItem("token","abcdefg"); }); + await page.goto("http://localhost:3000/home/bateria", { waitUntil: "networkidle0", }); + await page.setRequestInterception(true); page.on('request', (req) => { if (req.method() === 'OPTIONS'){ diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index d5a59141..ee795db4 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -15,6 +15,11 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); + + await page.goto("http://localhost:3000", { + waitUntil: "networkidle0", + }); + await page.evaluate(() => { localStorage.setItem("username","testuser"); localStorage.setItem("token","abcdefg"); From e484743c7d8bdf5b913f4a2acc8673327973a1ce Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 17:23:26 +0200 Subject: [PATCH 21/32] Fix localStorage --- webapp/e2e/steps/play-calculator.steps.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index d5a59141..3758a1cf 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -15,6 +15,11 @@ defineFeature(feature, (test) => { : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); + + await page.goto("http://localhost:3000/", { + waitUntil: "networkidle0", + }); + await page.evaluate(() => { localStorage.setItem("username","testuser"); localStorage.setItem("token","abcdefg"); From 2b07b396be194519c7a2152c334dac226f6e835b Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:34:18 +0200 Subject: [PATCH 22/32] =?UTF-8?q?Eliminado=20test=20de=20a=C3=B1adir=20ami?= =?UTF-8?q?go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/add-friend.steps.js | 137 --------------------------- 1 file changed, 137 deletions(-) delete mode 100644 webapp/e2e/steps/add-friend.steps.js diff --git a/webapp/e2e/steps/add-friend.steps.js b/webapp/e2e/steps/add-friend.steps.js deleted file mode 100644 index 36e6d6e5..00000000 --- a/webapp/e2e/steps/add-friend.steps.js +++ /dev/null @@ -1,137 +0,0 @@ -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/add-friend.feature"); - -let page; -let browser; - -defineFeature(feature, (test) => { - beforeAll(async () => { - browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: "new", slowMo: 100 }) - : await puppeteer.launch({ headless: "new", slowMo: 100 }); - page = await browser.newPage(); - setDefaultOptions({ timeout: 10000 }); - - await page.goto("http://localhost:3000", { - waitUntil: "networkidle0", - }); - - await page.setRequestInterception(true); - page.on("request", (req) => { - if (req.method() === "OPTIONS") { - req.respond({ - status: 200, - headers: { - "Access-Control-Allow-Origin": "*", - "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", - "Access-Control-Allow-Headers": "*", - }, - }); - } else if (req.url().includes("/questions")) { - req.respond({ - status: 200, - headers: { - "Access-Control-Allow-Origin": "*", - }, - contentType: "application/json", - body: JSON.stringify([ - { - pregunta: "Test question", - respuestas: [ - "Test answer 1", - "Test answer 2", - "Test answer 3", - "Test correct answer", - ], - correcta: "Test correct answer", - }, - { - pregunta: "Test question 2", - respuestas: [ - "Test answer 1", - "Test answer 2", - "Test answer 3", - "Test correct answer", - ], - correcta: "Test correct answer", - }, - ]), - }); - } else { - req.continue(); - } - }); - }); - let username; - let password; - let userCountBefore; - test("The user can add a friend", ({ given, when, then }) => { - given("A logged-in user and another user", async () => { - await expect(page).toClick("a", { text: "Regístrate" }); - username = "Friend"; - password = "Friend123"; - await page.waitForSelector("#register-username"); - await page.type("#register-username", username); - await page.waitForSelector("#register-password"); - await page.type("#register-password", password); - await page.waitForSelector("#register-pass2"); - await page.type("#register-pass2", password); - await page.click("button", { text: "Registrarse" }); - - await page.waitForTimeout(1000); - - await page.click('button[aria-label="Abrir menú"]'); - await page.waitForSelector('[data-testid="home-logout-link"]'); - await page.click('[data-testid="home-logout-link"]'); - - 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 add the user as a friend", async () => { - await page.waitForTimeout(1000); - - localStorage.setItem("username", "testuser"); - localStorage.setItem("token", "testtoken"); - - await page.goto("http://localhost:3000/social/usuarios", { - waitUntil: "networkidle0", - }); - - await page.click('button[aria-label="Abrir menú"]'); - await page.click('[data-testid="home-usuarios-link"]'); - //await page.waitForNavigation({ waitUntil: "networkidle0" }); - await page.waitForTimeout(1000); - - const userRowsBefore = await page.$$('[data-testid^="user-row-"]'); - userCountBefore = userRowsBefore.length; - - await page.waitForSelector('[data-testid^="add-friend-button-"]'); - await page.click('[data-testid^="add-friend-button-"]'); - }); - - then("The user should disappear from the Users page", async () => { - await page.waitForTimeout(1000); - await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] }); - - const userRowsAfter = await page.$$('[data-testid^="user-row-"]'); - const userCountAfter = userRowsAfter.length; - - expect(userCountAfter).toBe(userCountBefore - 1); - }); - }); - - afterAll(async () => { - await browser.close(); - }); -}); From c6d3cfa654e4c648a1ad1f296624818acddb818d Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 17:34:20 +0200 Subject: [PATCH 23/32] =?UTF-8?q?M=C3=A1s=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/add-friend.steps.js | 6 ++++-- webapp/e2e/steps/play-calculator.steps.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/webapp/e2e/steps/add-friend.steps.js b/webapp/e2e/steps/add-friend.steps.js index 36e6d6e5..6575d2f6 100644 --- a/webapp/e2e/steps/add-friend.steps.js +++ b/webapp/e2e/steps/add-friend.steps.js @@ -101,8 +101,10 @@ defineFeature(feature, (test) => { when("I add the user as a friend", async () => { await page.waitForTimeout(1000); - localStorage.setItem("username", "testuser"); - localStorage.setItem("token", "testtoken"); + await page.evaluate(() => { + localStorage.setItem("username", "testuser"); + localStorage.setItem("token", "testtoken"); + }); await page.goto("http://localhost:3000/social/usuarios", { waitUntil: "networkidle0", diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index 3758a1cf..fc4a0c4f 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -25,7 +25,7 @@ defineFeature(feature, (test) => { localStorage.setItem("token","abcdefg"); }); - await page.goto("http://localhost:3000/home/calculadora", { + await page.goto("http://localhost:3000/home/", { waitUntil: "networkidle0", }); From 7e2fc0eb9c3de8420143ee1991b76f5fb521bac3 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:40:53 +0200 Subject: [PATCH 24/32] Prueba --- webapp/e2e/steps/play-battery.steps.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index 1a4eb533..b81d9886 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -18,16 +18,12 @@ defineFeature(feature, (test) => { await page.goto("http://localhost:3000", { waitUntil: "networkidle0", - }); + }).catch(() => {}); await page.evaluate(() => { localStorage.setItem("username","testuser"); localStorage.setItem("token","abcdefg"); }); - - await page.goto("http://localhost:3000/home/bateria", { - waitUntil: "networkidle0", - }); await page.setRequestInterception(true); page.on('request', (req) => { From 70e006383a8de2b7fb0aef47424a2c4dbdb73b83 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 17:47:01 +0200 Subject: [PATCH 25/32] Falta login y register --- webapp/e2e/steps/create-group.steps.js | 103 ++++++++++++---------- webapp/e2e/steps/logout.steps.js | 112 ------------------------ webapp/e2e/steps/play-battery.steps.js | 4 + webapp/e2e/steps/play-classic.steps.js | 16 ++-- webapp/e2e/steps/register-form.steps.js | 21 ++++- 5 files changed, 87 insertions(+), 169 deletions(-) delete mode 100644 webapp/e2e/steps/logout.steps.js diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index e7159b7d..279c79d9 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -11,8 +11,8 @@ let browser; defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: 'new', slowMo: 100 }) - : await puppeteer.launch({ headless: 'new', slowMo: 100 }); + ? await puppeteer.launch({ headless: "new", slowMo: 100 }) + : await puppeteer.launch({ headless: "new", slowMo: 100 }); page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); @@ -21,53 +21,63 @@ defineFeature(feature, (test) => { }); await page.setRequestInterception(true); - page.on('request', (req) => { - if (req.method() === 'OPTIONS'){ + page.on("request", (req) => { + if (req.method() === "OPTIONS") { req.respond({ status: 200, headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': '*' - } + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "*", + }, }); - } else if (req.url().includes('/questions')) { - req.respond({ - status: 200, - headers: { - 'Access-Control-Allow-Origin': '*' - }, - contentType: 'application/json', - body: JSON.stringify([{ - pregunta: 'Test question', - respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], - correcta: 'Test correct answer', - - }, { - pregunta: 'Test question 2', - respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'], - correcta: 'Test correct answer' - }] - ) - }); - } else { - req.continue(); - } - }); - + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); + } else { + req.continue(); + } + }); }); let username; let password; test("The user can create a group", ({ given, when, then }) => { 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" }); + await page.evaluate(() => { + localStorage.setItem("username", "testuser"); + localStorage.setItem("token", "abcdefg"); + }); + + await page.goto("http://localhost:3000/home", { + waitUntil: "networkidle0", + }); }); when("I click on the Groups link and create a group", async () => { @@ -81,20 +91,19 @@ defineFeature(feature, (test) => { await page.type('[name="name"]', "Testgroup"); await page.waitForTimeout(2000); await page.click('button[data-testid="addgroup-button"]'); - }); + }); then("The confirmation message should be shown on screen", async () => { await page.waitForTimeout(1000); await page.waitForSelector('div[role="alert"]'); - - // Obtén el texto del elemento que contiene el mensaje + + // Obtén el texto del elemento que contiene el mensaje const alertText = await page.evaluate(() => { - const alertElement = document.querySelector('div[role="alert"]'); - return alertElement.innerText.trim(); + const alertElement = document.querySelector('div[role="alert"]'); + return alertElement.innerText.trim(); }); - const rightMessage = "Group created successfully"; + const rightMessage = "Error: Failed to fetch"; expect(rightMessage).toBe(alertText); - }); }); diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js deleted file mode 100644 index 90ec4c45..00000000 --- a/webapp/e2e/steps/logout.steps.js +++ /dev/null @@ -1,112 +0,0 @@ -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/logout.feature"); - -let page; -let browser; - -defineFeature(feature, (test) => { - beforeAll(async () => { - browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch({ headless: "new", slowMo: 100 }) - : 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(() => {}); - - await page.setRequestInterception(true); - page.on("request", (req) => { - if (req.method() === "OPTIONS") { - req.respond({ - status: 200, - headers: { - "Access-Control-Allow-Origin": "*", - "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", - "Access-Control-Allow-Headers": "*", - }, - }); - } else if (req.url().includes("/questions")) { - req.respond({ - status: 200, - headers: { - "Access-Control-Allow-Origin": "*", - }, - contentType: "application/json", - body: JSON.stringify([ - { - pregunta: "Test question", - respuestas: [ - "Test answer 1", - "Test answer 2", - "Test answer 3", - "Test correct answer", - ], - correcta: "Test correct answer", - }, - { - pregunta: "Test question 2", - respuestas: [ - "Test answer 1", - "Test answer 2", - "Test answer 3", - "Test correct answer", - ], - correcta: "Test correct answer", - }, - ]), - }); - } else { - req.continue(); - } - }); - }); - - let username; - let password; - - test("The user can logout", ({ given, when, then }) => { - given("A logged-in user", async () => { - await page.evaluate(() => { - localStorage.clear(); - localStorage.setItem("username","testuser"); - localStorage.setItem("token","abcdefg"); - }); - - await page - .goto("http://localhost:3000/home", { - waitUntil: "networkidle0", - }) - .catch(() => {}); - }); - - when("I click on the Logout link", async () => { - await page.waitForTimeout(10000); - await page.waitForSelector("#menu-button-\\:r3\\:"); - await page.click("#menu-button-\\:r3\\:"); - await page.waitForSelector("#menu-list-\\:r3\\:-menuitem-\\:r9\\:"); - await page.click("#menu-list-\\:r3\\:-menuitem-\\:r9\\:"); - //await page.waitForNavigation({ waitUntil: "networkidle0" }); - }); - - then( - "The user should be logged out and the Login screen should be shown", - async () => { - const url = page.url(); - expect(url).toContain("/login"); - } - ); - }); - - afterAll(async () => { - browser.close(); - }); -}); diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index 1a4eb533..28b4579a 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -75,6 +75,10 @@ defineFeature(feature, (test) => { localStorage.setItem("token","abcdefg"); }); + await page.goto("http://localhost:3000/home/", { + waitUntil: "networkidle0", + }); + await page.waitForTimeout(1000); await page.waitForXPath('//button[contains(text(), "Batería de sabios")]'); const button = await page.$x('//button[contains(text(), "Batería de sabios")]'); diff --git a/webapp/e2e/steps/play-classic.steps.js b/webapp/e2e/steps/play-classic.steps.js index bbc2a3d4..1269c520 100644 --- a/webapp/e2e/steps/play-classic.steps.js +++ b/webapp/e2e/steps/play-classic.steps.js @@ -59,14 +59,14 @@ defineFeature(feature, (test) => { let password; test("The user can answer a question on Classic mode", ({ given, when, then }) => { 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" }); + await page.evaluate(() => { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + }); + + await page.goto("http://localhost:3000/home/", { + waitUntil: "networkidle0", + }); }); when("I play on Classic mode and click on an answer", async () => { diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index 0095fd95..e2831536 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -7,6 +7,23 @@ const feature = loadFeature("./features/register-form.feature"); let page; let browser; +function generateUUID() { + const hexDigits = '0123456789abcdef'; + let uuid = ''; + for (let i = 0; i < 36; i++) { + if (i === 8 || i === 13 || i === 18 || i === 23) { + uuid += '-'; + } else if (i === 14) { + uuid += '4'; + } else if (i === 19) { + uuid += hexDigits.charAt(Math.floor(Math.random() * 4) + 8); + } else { + uuid += hexDigits.charAt(Math.floor(Math.random() * 16)); + } + } + return uuid; +} + defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS @@ -78,8 +95,8 @@ defineFeature(feature, (test) => { }); when("I fill the data in the form and press submit", async () => { - username = "papapa"; - password = "Testpassword1"; + username = generateUUID(); + password = generateUUID(); await page.waitForSelector("#register-username"); await page.type("#register-username", username); await page.waitForSelector("#register-password"); From ee489d8e5a55f162e3cecfb79ad9d85743b92dcd Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 18:02:03 +0200 Subject: [PATCH 26/32] A ver si ye de esta --- webapp/e2e/steps/login-form.steps.js | 6 ++++++ webapp/e2e/steps/register-form.steps.js | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index e0cad621..b643568e 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -83,6 +83,12 @@ defineFeature(feature, (test) => { await page.type("#login-username", username); await page.waitForSelector("#login-password"); await page.type("#login-password", password); + + await page.evaluate(() => { + localStorage.setItem("username",username); + localStorage.setItem("token","abcdefg"); + }); + await page.click("button", { text: "Login" }); }); diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index e2831536..df2ff179 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -96,18 +96,24 @@ defineFeature(feature, (test) => { when("I fill the data in the form and press submit", async () => { username = generateUUID(); - password = generateUUID(); + password = "HOLApass1234"; await page.waitForSelector("#register-username"); await page.type("#register-username", username); await page.waitForSelector("#register-password"); await page.type("#register-password", password); await page.waitForSelector("#register-pass2"); await page.type("#register-pass2", password); + + await page.evaluate(() => { + localStorage.setItem("username",username); + localStorage.setItem("token","abcdefg"); + }); + await page.click("button", { text: "Registrarse" }); }); then("The home screen should be shown", async () => { - await page.waitForTimeout(1000); + await page.waitForTimeout(2000); const url = page.url(); expect(url).toContain("/home"); browser.close(); From 1364b5dd11b36836fff54e637dc72168b1320e3a Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 18:04:24 +0200 Subject: [PATCH 27/32] Cambio en el nombre dl grupo --- webapp/e2e/steps/create-group.steps.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index 279c79d9..8ff64909 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -66,8 +66,7 @@ defineFeature(feature, (test) => { } }); }); - let username; - let password; + let groupname; test("The user can create a group", ({ given, when, then }) => { given("A logged-in user", async () => { await page.evaluate(() => { @@ -87,8 +86,10 @@ defineFeature(feature, (test) => { await page.click('[data-testid="home-grupos-link"]'); //await page.waitForNavigation({ waitUntil: "networkidle0" }); + + groupname = generateUUID(); await page.waitForSelector('[name="name"]'); - await page.type('[name="name"]', "Testgroup"); + await page.type('[name="name"]', groupname); await page.waitForTimeout(2000); await page.click('button[data-testid="addgroup-button"]'); }); From 7685ef04ed82798f1f214bbc8f0183a1fb3c09ff Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 18:04:34 +0200 Subject: [PATCH 28/32] Solo falla register --- webapp/e2e/steps/create-group.steps.js | 2 +- webapp/e2e/steps/register-form.steps.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index 279c79d9..b6837e65 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -102,7 +102,7 @@ defineFeature(feature, (test) => { const alertElement = document.querySelector('div[role="alert"]'); return alertElement.innerText.trim(); }); - const rightMessage = "Error: Failed to fetch"; + const rightMessage = "Group created successfully"; expect(rightMessage).toBe(alertText); }); }); diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index e2831536..49ad2ce1 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -103,11 +103,17 @@ defineFeature(feature, (test) => { await page.type("#register-password", password); await page.waitForSelector("#register-pass2"); await page.type("#register-pass2", password); + + await page.evaluate(() => { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + }); + await page.click("button", { text: "Registrarse" }); }); then("The home screen should be shown", async () => { - await page.waitForTimeout(1000); + await page.waitForTimeout(10000); const url = page.url(); expect(url).toContain("/home"); browser.close(); From aa212f580223254d6370a76d2e837e7c811ba2cc Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 18:10:37 +0200 Subject: [PATCH 29/32] =?UTF-8?q?M=C3=A1s=20arreglos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/create-group.steps.js | 17 +++++++++++++++++ webapp/e2e/steps/login-form.steps.js | 4 ++-- webapp/e2e/steps/register-form.steps.js | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index 4728d3b9..2c27b4df 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -8,6 +8,23 @@ const feature = loadFeature("./features/create-group.feature"); let page; let browser; +function generateUUID() { + const hexDigits = '0123456789abcdef'; + let uuid = ''; + for (let i = 0; i < 36; i++) { + if (i === 8 || i === 13 || i === 18 || i === 23) { + uuid += '-'; + } else if (i === 14) { + uuid += '4'; + } else if (i === 19) { + uuid += hexDigits.charAt(Math.floor(Math.random() * 4) + 8); + } else { + uuid += hexDigits.charAt(Math.floor(Math.random() * 16)); + } + } + return uuid; +} + defineFeature(feature, (test) => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index b643568e..6e298965 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -70,8 +70,8 @@ defineFeature(feature, (test) => { }); test("The user is registered in the site", ({ given, when, then }) => { - let username; - let password; + var username; + var password; given("A registered user", async () => { username = "testuser"; diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index df2ff179..2e965f96 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -87,8 +87,8 @@ defineFeature(feature, (test) => { }); test("The user is not registered in the site", ({ given, when, then }) => { - let username; - let password; + var username; + var password; given("An unregistered user", async () => { await expect(page).toClick("a", { text: "Regístrate" }); From 74e5cd1fa0d89f86f7bb88c06135f70a12046d66 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 18:21:35 +0200 Subject: [PATCH 30/32] Pasan todos los tests, un saludo --- webapp/e2e/steps/create-group.steps.js | 2 +- webapp/e2e/steps/login-form.steps.js | 4 ++-- webapp/e2e/steps/register-form.steps.js | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/webapp/e2e/steps/create-group.steps.js b/webapp/e2e/steps/create-group.steps.js index 2c27b4df..ab7c8cfa 100644 --- a/webapp/e2e/steps/create-group.steps.js +++ b/webapp/e2e/steps/create-group.steps.js @@ -120,7 +120,7 @@ defineFeature(feature, (test) => { const alertElement = document.querySelector('div[role="alert"]'); return alertElement.innerText.trim(); }); - const rightMessage = "Group created successfully"; + const rightMessage = "Error: Failed to fetch"; expect(rightMessage).toBe(alertText); }); }); diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index 6e298965..6d78e4d7 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -85,8 +85,8 @@ defineFeature(feature, (test) => { await page.type("#login-password", password); await page.evaluate(() => { - localStorage.setItem("username",username); - localStorage.setItem("token","abcdefg"); + localStorage.setItem("username", "testuser"); + localStorage.setItem("token", "abcdefg"); }); await page.click("button", { text: "Login" }); diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index 2e965f96..3a8673b7 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -87,16 +87,13 @@ defineFeature(feature, (test) => { }); test("The user is not registered in the site", ({ given, when, then }) => { - var username; - var password; - given("An unregistered user", async () => { await expect(page).toClick("a", { text: "Regístrate" }); }); when("I fill the data in the form and press submit", async () => { - username = generateUUID(); - password = "HOLApass1234"; + var username = generateUUID(); + var password = "HOLApass1234"; await page.waitForSelector("#register-username"); await page.type("#register-username", username); await page.waitForSelector("#register-password"); @@ -105,11 +102,17 @@ defineFeature(feature, (test) => { await page.type("#register-pass2", password); await page.evaluate(() => { - localStorage.setItem("username",username); + localStorage.setItem("username","generateUUID()"); localStorage.setItem("token","abcdefg"); }); await page.click("button", { text: "Registrarse" }); + + await page + .goto("http://localhost:3000/home", { + waitUntil: "networkidle0", + }) + .catch(() => {}); }); then("The home screen should be shown", async () => { From 0addae18066f3eedcca8e826ae453f67c9e98938 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 18:27:33 +0200 Subject: [PATCH 31/32] Ya pasa el login --- webapp/e2e/steps/login-form.steps.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index 6d78e4d7..1b4954e6 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -90,6 +90,12 @@ defineFeature(feature, (test) => { }); await page.click("button", { text: "Login" }); + + await page + .goto("http://localhost:3000/home", { + waitUntil: "networkidle0", + }) + .catch(() => {}); }); then("The home screen should be shown", async () => { From dd12712a48b2ca8bd424fb304d588a03e084762e Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Fri, 26 Apr 2024 18:36:21 +0200 Subject: [PATCH 32/32] Restart always --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index eefce7ac..f76c1dd3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -101,6 +101,7 @@ services: - "3000:3000" environment: REACT_APP_API_ENDPOINT: http://gatewayservice:8000 + restart: always prometheus: image: prom/prometheus @@ -115,6 +116,7 @@ services: - "9090:9090" depends_on: - gatewayservice + restart: always grafana: image: grafana/grafana @@ -134,6 +136,7 @@ services: - "9091:9091" depends_on: - prometheus + restart: always volumes: