From 02d9b0d6902b170abb34e36aef8e364e6419cc2b Mon Sep 17 00:00:00 2001 From: Sule Bello Date: Mon, 19 May 2025 20:49:25 -0400 Subject: [PATCH 1/5] login_test: verify rendering of name, password inputs, and submit button --- cypress/e2e/login.cy.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index c2fbb3a..32849e1 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -1,2 +1,13 @@ describe('Login Component', () => { + beforeEach(() => { + cy.visit('/'); + }); + + it('should render name and password inputs and login button', () => { + cy.get('input[name="name"]').should('exist'); + cy.get('input[name="password"]').should('exist'); + cy.get('button[type="submit"]').should('exist'); + + }); + }) \ No newline at end of file From 08bb6f99078c783f0ee0da0e4012d6eb0896233d Mon Sep 17 00:00:00 2001 From: Sule Bello Date: Mon, 19 May 2025 20:54:22 -0400 Subject: [PATCH 2/5] login_test: prevent form submission with empty input fields --- cypress/e2e/login.cy.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index 32849e1..129dca9 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -8,6 +8,18 @@ describe('Login Component', () => { cy.get('input[name="password"]').should('exist'); cy.get('button[type="submit"]').should('exist'); + + }); + it('prevents submission when input fields are empty', () => { + cy.get('button[type="submit"]').click(); + cy.get('input[name="name"]').then($input => { + expect($input[0].checkValidity()).to.be.false; + }); + + cy.get('input[name="password"]').then($input => { + expect($input[0].checkValidity()).to.be.false; + }); + }); }) \ No newline at end of file From 85b46567481eb4a6b61a4a99fd62b2655dd4adb0 Mon Sep 17 00:00:00 2001 From: Sule Bello Date: Mon, 19 May 2025 21:39:04 -0400 Subject: [PATCH 3/5] login_test: verify successful login with valid credentials and welcome message --- cypress/e2e/login.cy.js | 12 ++++++++++++ src/components/LoginForm.js | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index 129dca9..192a0f3 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -22,4 +22,16 @@ describe('Login Component', () => { }); + it('logs in successfully with valid credentials and redirects', () => { + cy.visit('/'); + + cy.get('input[name="name"]').type('suleiman'); + cy.get('input[name="password"]').type('suleimanpassword'); + cy.get('button[type="submit"]').click(); + + cy.contains('Welcome, suleiman!').should('exist'); + + + }); + }) \ No newline at end of file diff --git a/src/components/LoginForm.js b/src/components/LoginForm.js index 26c8cc3..64e86df 100644 --- a/src/components/LoginForm.js +++ b/src/components/LoginForm.js @@ -15,9 +15,15 @@ function LoginForm({ onLogin }) { })); }; + const handleSubmit = (e) => { + e.preventDefault(); + onLogin(formData); + }; + + return (
-
+

Login

From f9c3f5156eb881d2fc25de1086fb5c165055855c Mon Sep 17 00:00:00 2001 From: Sule Bello Date: Mon, 19 May 2025 21:54:23 -0400 Subject: [PATCH 4/5] login_test: ensure login is blocked with invalid credentials --- cypress/e2e/login.cy.js | 8 ++++++++ src/App.js | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index 192a0f3..9fc4f3c 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -34,4 +34,12 @@ describe('Login Component', () => { }); + it('shows error or blocks login with invalid credentials', () => { + cy.get('input[name="name"]').type('wronguser'); + cy.get('input[name="password"]').type('wrongpass'); + cy.get('button[type="submit"]').click(); + + cy.contains('Welcome').should('not.exist'); + }); + }) \ No newline at end of file diff --git a/src/App.js b/src/App.js index c383c91..afc9bf1 100644 --- a/src/App.js +++ b/src/App.js @@ -9,8 +9,13 @@ function App() { const handleLogin = (formData) => { // In a real app, you would validate credentials here - setIsLoggedIn(true); - setUserName(formData.name); + if (formData.name === 'suleiman' && formData.password === 'suleimanpassword'){ + setIsLoggedIn(true); + setUserName(formData.name); + } else { + alert('You have provided invalid credentials') + } + }; const handleLogout = () => { From 4aaf8a391353d88b9896cd9ed0d6c7d0be7d3c7c Mon Sep 17 00:00:00 2001 From: Sule Bello Date: Mon, 19 May 2025 22:38:31 -0400 Subject: [PATCH 5/5] added submission_notes.md with bug explanation and AI usage --- submission_notes.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 submission_notes.md diff --git a/submission_notes.md b/submission_notes.md new file mode 100644 index 0000000..331426f --- /dev/null +++ b/submission_notes.md @@ -0,0 +1,9 @@ +The redirect after login wasn’t working because the form in LoginForm.js didn’t have an onSubmit handler. As a result, the handleSubmit function never ran, and the onLogin function wasn’t triggered. + +I fixed the issue by adding onSubmit={handleSubmit} to the tag, which ensures the login logic is executed and the app transitions to the welcome screen upon successful login. + +AI Usage +prompt: +I keep getting this "Cypress could not verify that this server is running: + +http://localhost:3000 even though the app is running".