Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
describe('Login Component', () => {
})
describe("Login Component", () => {
beforeEach(() => {
cy.visit("/");
});

it("should display login form", () => {
cy.get(".login-form").should("be.visible");
cy.get('input[name="name"]').should("exist");
cy.get('input[name="password"]').should("exist");
cy.get('button[type="submit"]').should("exist");
});

it("should successfully login and redirect to welcome page", () => {
cy.get('input[name="name"]').type("test1");
cy.get('input[name="password"]').type("password1");
cy.get('button[type="submit"]').click();

// Verify redirect to welcome page
cy.get(".welcome-container").should("be.visible");
cy.get("h1").should("contain", "Welcome, test1!");
});

it("should show logout button after login", () => {
cy.get('input[name="name"]').type("test1");
cy.get('input[name="password"]').type("password1");
cy.get('button[type="submit"]').click();

cy.get(".logout-button").should("be.visible");
});
});
53 changes: 53 additions & 0 deletions fixing-Bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# BUG FIXING DOC

## Issue Description

The login form was not redirecting the user after a successful login. Although the form allowed input and submission, the app did not navigate to the welcome page as expected. This was because the login logic only updated state without triggering a navigation or redirect.


## Solution
The issue was resolved by:
```

Integrating react-router-dom for client-side routing.

Using the useNavigate hook inside the handleLogin function in App.js to programmatically redirect the user to the welcome page after login.

Implementation Details
The fix involved:

Installing react-router-dom and setting up routing in App.js.
```

**Updating handleLogin in App.js:**
```
js
Copy
Edit
import { useNavigate } from 'react-router-dom';

function App() {
const navigate = useNavigate();

const handleLogin = (formData) => {
setIsLoggedIn(true);
setUserName(formData.name);
navigate('/welcome'); // Redirect after login
};

// ...
}
```
Adding route definitions to render the LoginForm at / and Welcome at /welcome.

**Testing**

The fix was verified using Cypress end-to-end tests which confirmed:

The login form renders correctly.

A successful login redirects the user to the welcome page.

The welcome page displays the correct username.

The logout button is visible after login.
Loading