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
43 changes: 42 additions & 1 deletion cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
describe('Login Component', () => {
})
beforeEach(() => {
cy.visit('http://localhost:3000');
});

it('make sure that login page exits', () => {
cy.contains('Login').should('exist');
cy.get('input[name="name"]').should('exist');
cy.get('input[name="password"]').should('exist');
});

it('cheking empty submissions.', () => {
cy.get('button[type="submit"]').click();
cy.get('form.login-form').should('exist');
cy.contains('Welcome').should('not.exist');
});

const users = [
{ name: 'Akhil', password: 'pass123' },
{ name: 'Nikhil', password: '123@123' },
{ name: 'TestNewCandidate', password: 'password@2211' }
];

users.forEach(({ name, password }) => {
it(`must login for all the users: ${name}`, () => {
cy.get('input[name="name"]').type(name);
cy.get('input[name="password"]').type(password);
cy.get('button[type="submit"]').click();

cy.contains(`Welcome, ${name}!`).should('exist');
cy.contains('Logout').should('exist').click();
cy.contains('Login').should('exist');
});
});

it('checking sucessfull logout and return to the login page', () => {
cy.get('input[name="name"]').type('Akhil');
cy.get('input[name="password"]').type('pass123');
cy.get('button[type="submit"]').click();
cy.contains('Logout').click();
cy.contains('Login').should('exist');
});
});
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/components/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ function LoginForm({ onLogin }) {
}));
};

const hanfleSubmitForm = (e) => {
e.preventDefault();
onLogin(formData);
}

return (
<div className="login-form-container">
<form className="login-form">
<form className="login-form" onSubmit={hanfleSubmitForm}>
<h2>Login</h2>
<div className="form-group">
<label htmlFor="name">Name:</label>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import './Welcome.css';

function Welcome({ userName, onLogout }) {
return (
<div className="welcome-container">
<div className="welcome-container" data-testid="welcome-container">
<div className="welcome-card">
<h1>Welcome, {userName}!</h1>
<h1 data-testid="welcome-message">Welcome, {userName}!</h1>
<p>You have successfully logged in.</p>
<button onClick={onLogout} className="logout-button">
<button onClick={onLogout} className="logout-button" data-testid="logout-button" >
Logout
</button>
</div>
Expand Down