diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index c2fbb3a..5a5a50d 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -1,2 +1,5 @@ -describe('Login Component', () => { -}) \ No newline at end of file +describe('Login Flow with Component Switch', () => { + it('logs in and shows welcome message with username', () => { + cy.login('layoolar','password'); + }); +}); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9d3825e..201a275 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,25 +1,8 @@ -// *********************************************** -// This example commands.js shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file +Cypress.Commands.add('login', (name = 'testuser', password = 'anything') => { + cy.visit('http://localhost:3000'); + cy.get('[data-testid="input-name"]').type(name); + cy.get('[data-testid="input-password"]').type(password); + cy.get('[data-testid="login-button"]').click(); + cy.get('[data-testid="login-form"]').should('not.exist'); + cy.contains(`Welcome, ${name}`).should('exist'); +}); diff --git a/src/components/LoginForm.js b/src/components/LoginForm.js index 26c8cc3..329b44d 100644 --- a/src/components/LoginForm.js +++ b/src/components/LoginForm.js @@ -15,9 +15,14 @@ function LoginForm({ onLogin }) { })); }; + const handleSubmit = (e) => { + e.preventDefault(); + onLogin(formData); // or however you’re calling it + }; + return (