From e9b3f06f0c81324febc863d31ab27a5331c3d48c Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Tue, 23 Apr 2024 17:13:41 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20test=20e2e=20para=20crear=20grup?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/features/creategroup.feature | 6 +++ webapp/e2e/steps/creategroup.steps.js | 68 +++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 webapp/e2e/features/creategroup.feature create mode 100644 webapp/e2e/steps/creategroup.steps.js diff --git a/webapp/e2e/features/creategroup.feature b/webapp/e2e/features/creategroup.feature new file mode 100644 index 00000000..c1176f54 --- /dev/null +++ b/webapp/e2e/features/creategroup.feature @@ -0,0 +1,6 @@ +Feature: Creating a group + +Scenario: The user can create a group + Given A logged-in user + When I click on the Groups link and create a group + Then The Group should be shown on the My Groups page \ No newline at end of file diff --git a/webapp/e2e/steps/creategroup.steps.js b/webapp/e2e/steps/creategroup.steps.js new file mode 100644 index 00000000..a206a3e4 --- /dev/null +++ b/webapp/e2e/steps/creategroup.steps.js @@ -0,0 +1,68 @@ +const puppeteer = require("puppeteer"); +const { defineFeature, loadFeature } = require("jest-cucumber"); +const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; +const { expect } = require("expect-puppeteer"); +const feature = loadFeature("./features/register-form.feature"); + +let page; +let browser; + +defineFeature(feature, (test) => { + beforeAll(async () => { + browser = process.env.GITHUB_ACTIONS + ? await puppeteer.launch() + : await puppeteer.launch({ headless: false, slowMo: 100 }); + page = await browser.newPage(); + //Way of setting up the timeout + setDefaultOptions({ timeout: 10000 }); + + await page + .goto("http://localhost:3000", { + waitUntil: "networkidle0", + }) + .catch(() => {}); + }); + + test("The user can create a group", ({ given, when, then }) => { + let username; + let password; + + 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 click on the Groups link and create a group", async () => { + await page.click('[data-testid="groups"]'); + await page.waitForNavigation(); + + await page.waitForSelector('[name="name"]'); + await page.type('[name="name"]', "Test Group"); + await page.click("button", { text: "Crear" }); + await page.waitForTimeout(1000); + }); + + then("The Group should be shown on the My Groups page", async () => { + await page.click('[data-testid="my-groups"]'); + await page.waitForNavigation(); + + const groupExists = await page.evaluate(() => { + const groupName = "Test Group"; + const groups = Array.from(document.querySelectorAll("tbody tr td:first-child")); + return groups.some(td => td.textContent === groupName); + }); + + expect(groupExists).toBe(true); + }); + }); + + afterAll(async () => { + browser.close(); + }); +});