From 6ab94aa3da0d69f1997bc67ef7f3f2690b249fd3 Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Thu, 15 May 2025 23:03:38 -0400 Subject: [PATCH 1/9] Added E2E for Auth and Random Recipes --- frontend/cypress/e2e/Auth.cy.ts | 34 ++++++++++++++++++++++++++++++ frontend/cypress/e2e/recipes.cy.ts | 8 +++++++ frontend/src/components/Recipe.tsx | 7 ++++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 frontend/cypress/e2e/Auth.cy.ts create mode 100644 frontend/cypress/e2e/recipes.cy.ts diff --git a/frontend/cypress/e2e/Auth.cy.ts b/frontend/cypress/e2e/Auth.cy.ts new file mode 100644 index 0000000..0f0569c --- /dev/null +++ b/frontend/cypress/e2e/Auth.cy.ts @@ -0,0 +1,34 @@ +/// + +describe("Signup Page", () => { + it("should allow a new user to sign up", () => { + cy.visit("http://localhost:4173/signup"); + + cy.get("input#name").type("Test User"); + cy.get("input#email").type(`testuser_${Date.now()}@gmail.com`); + cy.get("input#password").type("TestPassword123!"); + + cy.get('button[type="submit"]').click(); + + cy.on("window:alert", (txt) => { + expect(txt.toLowerCase()).to.contain("signup successful"); + }); + + cy.url({ timeout: 10000 }).should("include", "/login"); + }); +}); + +describe("Login Page", () => { + it("should allow an existing user to log in", () => { + cy.visit("http://localhost:4173/login"); + + cy.get("input#email").type("Arihanttiwari2005@gmail.com"); + cy.get("input#password").type("Testing123@"); + + cy.get('button[type="submit"]').click(); + + cy.contains(/welcome|dashboard|recipes|logout/i, { timeout: 10000 }).should( + "exist" + ); + }); +}); diff --git a/frontend/cypress/e2e/recipes.cy.ts b/frontend/cypress/e2e/recipes.cy.ts new file mode 100644 index 0000000..fa22f6a --- /dev/null +++ b/frontend/cypress/e2e/recipes.cy.ts @@ -0,0 +1,8 @@ +/// + +describe('Recipes Page', () => { + it('should display exactly 20 recipes', () => { + cy.visit('http://localhost:4173/recipes'); + cy.get('[data-cy=recipe-card]').should('have.length', 20); + }); +}); \ No newline at end of file diff --git a/frontend/src/components/Recipe.tsx b/frontend/src/components/Recipe.tsx index 6975979..c88e489 100644 --- a/frontend/src/components/Recipe.tsx +++ b/frontend/src/components/Recipe.tsx @@ -14,7 +14,7 @@ interface RecipeProps { vegan: boolean; vegetarian: boolean; }; - initialFavorited?: boolean; // ← new + initialFavorited?: boolean; // ← new } function Recipe({ recipe, initialFavorited = false }: RecipeProps) { @@ -59,7 +59,10 @@ function Recipe({ recipe, initialFavorited = false }: RecipeProps) { }; return ( -
+
{/* Favorite button */}