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
13 changes: 11 additions & 2 deletions cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
describe('Login Component', () => {
})
describe("Login Component", () => {
it("should login successfully and redirect to welcome page", () => {
cy.visit("/");

cy.get('input[name="name"]').type("Vimal K Manoj");
cy.get('input[name="password"]').type("password123");
cy.get('button[type="submit"]').click();

cy.contains("Welcome, Vimal K Manoj!").should("exist");
});
});
3 changes: 2 additions & 1 deletion src/components/LoginForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
}

.form-group input {
box-sizing: border-box;
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
Expand Down Expand Up @@ -64,4 +65,4 @@
.login-button:focus {
outline: none;
box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
}
}
22 changes: 14 additions & 8 deletions src/components/LoginForm.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import React, { useState } from 'react';
import './LoginForm.css';
import React, { useState } from "react";
import "./LoginForm.css";

function LoginForm({ onLogin }) {
const [formData, setFormData] = useState({
name: '',
password: ''
name: "",
password: "",
});

const handleChange = (e) => {
const { name, value } = e.target;
setFormData(prevState => ({
setFormData((prevState) => ({
...prevState,
[name]: value
[name]: value,
}));
};

// Added this handle submit for redirecting to welcome page
const handleSubmit = (e) => {
e.preventDefault();
onLogin(formData);
};

return (
<div className="login-form-container">
<form className="login-form">
<form className="login-form" onSubmit={handleSubmit}>
<h2>Login</h2>
<div className="form-group">
<label htmlFor="name">Name:</label>
Expand Down Expand Up @@ -49,4 +55,4 @@ function LoginForm({ onLogin }) {
);
}

export default LoginForm;
export default LoginForm;