diff --git a/webapp/e2e/features/login-form.feature b/webapp/e2e/features/login-form.feature index f851bc0..6691632 100644 --- a/webapp/e2e/features/login-form.feature +++ b/webapp/e2e/features/login-form.feature @@ -3,4 +3,12 @@ Feature: Login a user on the web page Scenario: The user log in Given Email and password of a user When I click in Iniciar Sesión - Then I should be redirected to the catalog \ No newline at end of file + Then I should be redirected to the catalog +Scenario: User log in blank email + Given Blank Email and password of a user + When I click in Iniciar Sesión + Then Warning message below Email +Scenario: User log in blank password + Given Email and blank password of a user + When I click in Iniciar Sesión + Then Warning message below Password \ No newline at end of file diff --git a/webapp/e2e/features/orders-form.feature b/webapp/e2e/features/orders-form.feature new file mode 100644 index 0000000..d3b0d27 --- /dev/null +++ b/webapp/e2e/features/orders-form.feature @@ -0,0 +1,6 @@ +Feature: Seeing orders history of a user + +Scenario: Orders of user "admin" + Given Registered user admin + When Log In and click on my profile + Then I should see my orders \ No newline at end of file diff --git a/webapp/e2e/features/register-form.feature b/webapp/e2e/features/register-form.feature index df46788..11e2610 100644 --- a/webapp/e2e/features/register-form.feature +++ b/webapp/e2e/features/register-form.feature @@ -3,4 +3,28 @@ Feature: Registering a new user Scenario: The user is not registered in the site Given An unregistered user When I fill the data in the form and press Regístrate - Then I should be redirected to Login Page \ No newline at end of file + Then I should be redirected to Login Page +Scenario: User Register blank email + Given Name, Dni, Password and confirmPassword of a user + When I fill the data in the form and press Regístrate + Then Warning below email +Scenario: User Register blank name + Given Email, Dni, Password and confirmPassword of a user + When I fill the data in the form and press Regístrate + Then Warning below name +Scenario: User Register blank dni + Given Name, Email, Password and confirmPassword of a user + When I fill the data in the form and press Regístrate + Then Warning below dni +Scenario: User Register blank password + Given Name, Dni, Email and confirmPassword of a user + When I fill the data in the form and press Regístrate + Then Warning below Password +Scenario: User Register blank confirmPassword + Given Name, Dni, Password and Email of a user + When I fill the data in the form and press Regístrate + Then Warning below confirmPassword +Scenario: Password and Confirm Password don't match + Given Email, Name, Dni, Password and confirmPassword of a user + When I fill the data in the form and press Regístrate + Then Warning below confirmPassword (Las contraseñas no coinciden) \ No newline at end of file diff --git a/webapp/e2e/steps/login-form.steps.ts b/webapp/e2e/steps/login-form.steps.ts index 48c9042..afed0be 100644 --- a/webapp/e2e/steps/login-form.steps.ts +++ b/webapp/e2e/steps/login-form.steps.ts @@ -48,4 +48,49 @@ defineFeature(feature, test => { }); }); + test("User Login", ({given,when,then}) => { + let email:string + let password:string + + given("Blank Email and password of a user", () => { + email = " " + password = "admin" + }); + + when("I click in Iniciar Sesion", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/login']"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='password']", password); + await expect(page).toClick('button', { text: 'Iniciar Sesión' }); + }); + + then("Warning below email", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + test("User Login", ({given,when,then}) => { + let email:string + let password:string + + given("Email and blank password of a user", () => { + email = "adri@email.com" + password = " " + }); + + when("I click in Iniciar Sesion", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/login']"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='password']", password); + await expect(page).toClick('button', { text: 'Iniciar Sesión' }); + }); + + then("Warning below password", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + }); \ No newline at end of file diff --git a/webapp/e2e/steps/orders-form.steps.ts b/webapp/e2e/steps/orders-form.steps.ts new file mode 100644 index 0000000..4ac1ff2 --- /dev/null +++ b/webapp/e2e/steps/orders-form.steps.ts @@ -0,0 +1,56 @@ +import { defineFeature, loadFeature } from 'jest-cucumber'; +import puppeteer from "puppeteer"; + +const feature = loadFeature('./features/login.feature'); + +let page: puppeteer.Page; +let browser: puppeteer.Browser; + +defineFeature(feature, test => { + + jest.setTimeout(100000) + beforeAll(async () => { + + browser = process.env.GITHUB_ACTIONS + ? await puppeteer.launch() + : await puppeteer.launch({ headless: true, slowMo:100}); //false to run tests locally + page = await browser.newPage(); + + await page + .goto("http://localhost:3000", { + waitUntil: "networkidle0", + }) + .catch(() => {}); + }); + + test("Orders in profile", ({given,when,then}) => { + let email:string + let password:string + + given("Admin session", () => { + email = "admin@gmail.com" + password = "admin" + }); + + when("I click in Iniciar Sesion", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/login']"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='password']", password); + await expect(page).toClick('button', { text: 'Iniciar Sesión' }); + await page.waitForNavigation() + await page.waitForTimeout(2000); + await expect(page).toMatch("Yeso"); + await expect(page).toClick("a[href='/orders']"); + + + }); + + then("I should see admin order's history", async () => { + await page.waitForNavigation() + await page.waitForTimeout(2000); + await expect(page).toMatch("Cuarcita"); + }); + }); +}); diff --git a/webapp/e2e/steps/register-form.steps.ts b/webapp/e2e/steps/register-form.steps.ts index 631f496..4d9a493 100644 --- a/webapp/e2e/steps/register-form.steps.ts +++ b/webapp/e2e/steps/register-form.steps.ts @@ -54,7 +54,199 @@ defineFeature(feature, test => { then("I should be redirected to the login page", async () => { await page.waitForNavigation() await page.waitForTimeout(2000); - await expect(page).toMatch("Entrar en Sesión"); + await expect(page).toMatch("Iniciar Sesión"); + }); + }); + test("User Register blank email", ({given,when,then}) => { + let email:string + let name:string + let dni:string + let password:string + let confirmPassword:string + + given("Name, Dni, Password and confirmPassword of a user", () => { + email = "" + name = "Adri" + dni = "12345678" + password = "adri" + confirmPassword = "adri" + }); + + when("I click in Regístrate", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/register']"); + await expect(page).toMatch("Crear cuenta"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='name']", name); + await expect(page).toFill("input[name='dni']", dni); + await expect(page).toFill("input[name='password']", password); + await expect(page).toFill("input[name='confirmPassword']", confirmPassword); + await expect(page).toClick('button', { text: 'Regístrate' }); + }); + + then("Warning below email", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + test("User Register blank name", ({given,when,then}) => { + let email:string + let name:string + let dni:string + let password:string + let confirmPassword:string + + given("Email, Dni, Password and confirmPassword of a user", () => { + email = "adri@gmail.com" + name = "" + dni = "12345678" + password = "adri" + confirmPassword = "adri" + }); + + when("I click in Regístrate", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/register']"); + await expect(page).toMatch("Crear cuenta"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='name']", name); + await expect(page).toFill("input[name='dni']", dni); + await expect(page).toFill("input[name='password']", password); + await expect(page).toFill("input[name='confirmPassword']", confirmPassword); + await expect(page).toClick('button', { text: 'Regístrate' }); + }); + + then("Warning below name", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + test("User Register blank dni", ({given,when,then}) => { + let email:string + let name:string + let dni:string + let password:string + let confirmPassword:string + + given("Email, Name, Password and confirmPassword of a user", () => { + email = "adrian@gmail.com" + name = "Adri" + dni = "" + password = "adri" + confirmPassword = "adri" + }); + + when("I click in Regístrate", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/register']"); + await expect(page).toMatch("Crear cuenta"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='name']", name); + await expect(page).toFill("input[name='dni']", dni); + await expect(page).toFill("input[name='password']", password); + await expect(page).toFill("input[name='confirmPassword']", confirmPassword); + await expect(page).toClick('button', { text: 'Regístrate' }); + }); + + then("Warning below dni", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + test("User Register blank password", ({given,when,then}) => { + let email:string + let name:string + let dni:string + let password:string + let confirmPassword:string + + given("Email, Name, Dni and confirmPassword of a user", () => { + email = "adrian@gmail.com" + name = "Adri" + dni = "123456" + password = "" + confirmPassword = "adri" + }); + + when("I click in Regístrate", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/register']"); + await expect(page).toMatch("Crear cuenta"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='name']", name); + await expect(page).toFill("input[name='dni']", dni); + await expect(page).toFill("input[name='password']", password); + await expect(page).toFill("input[name='confirmPassword']", confirmPassword); + await expect(page).toClick('button', { text: 'Regístrate' }); + }); + + then("Warning below password", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + test("User Register blank confirm password", ({given,when,then}) => { + let email:string + let name:string + let dni:string + let password:string + let confirmPassword:string + + given("Email, Name, Dni Password of a user", () => { + email = "adrian@gmail.com" + name = "Adri" + dni = "123456" + password = "adri" + confirmPassword = "" + }); + + when("I click in Regístrate", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/register']"); + await expect(page).toMatch("Crear cuenta"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='name']", name); + await expect(page).toFill("input[name='dni']", dni); + await expect(page).toFill("input[name='password']", password); + await expect(page).toFill("input[name='confirmPassword']", confirmPassword); + await expect(page).toClick('button', { text: 'Regístrate' }); + }); + + then("Warning below confirmPassword", async () => { + await expect(page).toMatch("El campo no puede estar vacio"); + }); + }); + test("Confirm Password and Password don't match", ({given,when,then}) => { + let email:string + let name:string + let dni:string + let password:string + let confirmPassword:string + + given("Email, Name, Dni Password of a user", () => { + email = "adrian@gmail.com" + name = "Adri" + dni = "123456" + password = "adri" + confirmPassword = "manuel" + }); + + when("I click in Regístrate", async () => { + await page.setViewport({ width: 1200, height: 1300 }); + await expect(page).toMatch("Sedimentarias"); + await expect(page).toClick("a[href='/register']"); + await expect(page).toMatch("Crear cuenta"); + await expect(page).toFill("input[name='email']", email); + await expect(page).toFill("input[name='name']", name); + await expect(page).toFill("input[name='dni']", dni); + await expect(page).toFill("input[name='password']", password); + await expect(page).toFill("input[name='confirmPassword']", confirmPassword); + await expect(page).toClick('button', { text: 'Regístrate' }); + }); + + then("Warning below confirmPassword", async () => { + await expect(page).toMatch("Las contraseñas no coinciden"); }); }); }); diff --git a/webapp/src/components/Login.tsx b/webapp/src/components/Login.tsx index d83d4d6..5c72ff9 100644 --- a/webapp/src/components/Login.tsx +++ b/webapp/src/components/Login.tsx @@ -14,7 +14,7 @@ import axios from 'axios'; import { Grid, Link, Typography } from '@mui/material'; const checkParams = (text: String) => { - return text === "" || text == null; + return text.trim() === "" || text == null; } type EmailFormProps = { diff --git a/webapp/src/components/Register.tsx b/webapp/src/components/Register.tsx index b05bba4..f6d4bc7 100644 --- a/webapp/src/components/Register.tsx +++ b/webapp/src/components/Register.tsx @@ -20,7 +20,7 @@ type NotificationType = { }; const checkParams = (text: String) => { - return text === "" || text == null; + return text.trim() === "" || text == null; }; const checkPaswwords = (repPass: String, pass: String) => {