diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index c2fbb3a..f7996ad 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -1,2 +1,43 @@ describe('Login Component', () => { -}) \ No newline at end of file + 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'); + }); +}); diff --git a/image.png b/image.png new file mode 100644 index 0000000..d5daa9e Binary files /dev/null and b/image.png differ diff --git a/package-lock.json b/package-lock.json index 623a7e0..36864d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6333,6 +6333,7 @@ "integrity": "sha512-1Rz7zc9iqLww6BysaESqUhtIuaFHS7nL3wREovAKYsNhLTfX3TbcBWHWgEz70YimH2NkSOsm4oIcJJ9HYHOlew==", "dev": true, "hasInstallScript": true, + "license": "MIT", "dependencies": { "@cypress/request": "^3.0.8", "@cypress/xvfb": "^1.2.4", diff --git a/src/components/LoginForm.js b/src/components/LoginForm.js index 26c8cc3..463bdb8 100644 --- a/src/components/LoginForm.js +++ b/src/components/LoginForm.js @@ -15,9 +15,14 @@ function LoginForm({ onLogin }) { })); }; + const hanfleSubmitForm = (e) => { + e.preventDefault(); + onLogin(formData); + } + return (