diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index c2fbb3a..b253bf8 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -1,2 +1,30 @@ describe('Login Component', () => { -}) \ No newline at end of file + beforeEach(() => { + cy.visit('/'); + }); + + it('displays the login form', () => { + cy.get('h2').should('contain', 'Login'); + cy.get('input[name="name"]').should('exist'); + cy.get('input[name="password"]').should('exist'); + cy.get('button').contains('Login'); + }); + + it('logs in successfully and redirects to welcome screen', () => { + cy.get('input[name="name"]').type('TestUser'); + cy.get('input[name="password"]').type('password123'); + cy.get('button').contains('Login').click(); + + cy.contains('Welcome, TestUser!').should('exist'); + cy.get('button').contains('Logout').should('exist'); + }); + + it('can logout and go back to login screen', () => { + cy.get('input[name="name"]').type('TestUser'); + cy.get('input[name="password"]').type('password123'); + cy.get('button').contains('Login').click(); + + cy.get('button').contains('Logout').click(); + cy.contains('Login').should('exist'); + }); +}); diff --git a/src/components/LoginForm.js b/src/components/LoginForm.js index 26c8cc3..b40ce64 100644 --- a/src/components/LoginForm.js +++ b/src/components/LoginForm.js @@ -17,7 +17,10 @@ function LoginForm({ onLogin }) { return (