diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index c2fbb3a..5c0ff58 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -1,2 +1,6 @@ describe('Login Component', () => { + it("A successful login leads to a redirect", () => { + cy.login("kevin", "correctpass"); + cy.contains("Welcome,").should("be.visible"); + }); }) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9d3825e..1c49f43 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -10,7 +10,12 @@ // // // -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) +Cypress.Commands.add("login", (email, password) => { + cy.visit("/"); + cy.get('input[name="name"]').type(email); + cy.get('input[name="password"]').type(password); + cy.get('button[type="submit"]').click(); + }); // // // -- This is a child command -- diff --git a/src/components/LoginForm.js b/src/components/LoginForm.js index 26c8cc3..86e4f31 100644 --- a/src/components/LoginForm.js +++ b/src/components/LoginForm.js @@ -15,9 +15,14 @@ function LoginForm({ onLogin }) { })); }; + const handleLogin = (e) => { + e.preventDefault(); + onLogin(formData); + }; + return (