Skip to content

Commit

Permalink
add form validations on test e2e correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
3FE3LE committed Sep 17, 2023
1 parent 59b5f9b commit 833c24a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
40 changes: 32 additions & 8 deletions cypress/e2e/sign-in.spec.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Sign in', () => {
it('should navigate to the about page', () => {
describe('Validate Form', () => {
it('should show form validations', () => {
// Start from the index page
cy.visit('http://localhost:3000/sign-in')

Expand All @@ -8,29 +8,53 @@ describe('Sign in', () => {

// The new page should contain an input field with the name "email"
cy.get('input[name="email"]').should('be.visible')

// The new page should contain an input field with the name "password"
cy.get('input[name="password"]').should('be.visible')
// The new page should contain a button with the value "Sign in"

// The new page should contain a button with the value "Sign In"
// On button pressed without dirty fields
cy.get('button').contains('Sign in').should('be.visible').click()

// The email input will be focused waiting to type a email
cy.get('input[name="email"]').should('be.focused')
cy.get('input[name="email"]').should('be.focus')

// div tag element will be visible whit error validation below of email input
cy.get('div').contains('Email is required').should('be.visible')

// div tag element will be visible whit error validation below of password input
cy.get('div').contains('Password is required').should('be.visible')

cy.get('input[name=password]').focus().type('hire_me')

cy.get('span').click()

cy.get('input[type="text"]').should('be.visible')

cy.get('span').click()

cy.get('input[type="password"]').should('be.visible')
})
})
describe('Sign in', () => {
it('should sign in the app correctly', () => {
// Start from the index page
cy.visit('http://localhost:3000/sign-in')

// The new url should include "/sign-in"
cy.url().should('include', '/sign-in')

// The new page should contain an input field with the name "email"
cy.get('input[name="email"]').should('be.visible').focus().type('[email protected]')

// The new page should contain an input field with the name "password"
cy.get('input[name="password"]').should('be.visible').focus().type('12345678')

// The new page should contain a button with the value "Sign in"
// On button pressed without dirty fields
cy.get('button').contains('Sign in').should('be.visible').click()

// The new url should include "/dashboard"
cy.url().should('include', '/dashboard')
})
})
38 changes: 34 additions & 4 deletions cypress/e2e/sign-up.spec.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Navigation', () => {
it('should navigate to the about page', () => {
describe('Validate Form', () => {
it('should show form validations', () => {
// Start from the index page
cy.visit('http://localhost:3000/sign-up')

Expand All @@ -18,9 +18,9 @@ describe('Navigation', () => {
// The new page should contain a button with the value "Sign Up"
// On button pressed without dirty fields
cy.get('button').contains('Sign Up').should('be.visible').click()

// The email input will be focused waiting to type a email
cy.get('input[name="fullName"]').should('be.focused')
cy.get('input[name="fullName"]').should('be.focus')

// div tag element will be visible whit error validation below of fullName input
cy.get('div').contains('Full name is required').should('be.visible')
Expand All @@ -31,6 +31,8 @@ describe('Navigation', () => {
// div tag element will be visible whit error validation below of password input
cy.get('div').contains('Password is required').should('be.visible')

cy.get('input[name=password]').focus().type('hire_me')

cy.get('span').click()

cy.get('input[type="text"]').should('be.visible')
Expand All @@ -40,3 +42,31 @@ describe('Navigation', () => {
cy.get('input[type="password"]').should('be.visible')
})
})
describe('Sign up exist user', () => {
it('should try sign up whit exist user', () => {
// Start from the index page
cy.visit('http://localhost:3000/sign-up')

// The new url should include "/sign-up"
cy.url().should('include', '/sign-up')

// The new page should contain an input field with the name "full name"
cy.get('input[name="fullName"]').should('be.visible').focus().type('3FE 3LE')

// The new page should contain an input field with the name "email"
cy.get('input[name="email"]').should('be.visible').focus().type('[email protected]')

// The new page should contain an input field with the name "password"
cy.get('input[name="password"]').should('be.visible').focus().type('12345678')

// The new page should contain a button with the value "Sign Up"
cy.get('button').contains('Sign Up').should('be.visible').click()

// div tag element will be visible whit error validation below of fullName input
cy.get('div').contains('Email already exist').should('be.visible')

// The new url should include "/sign-up"
cy.url().should('include', '/sign-up')

})
})
8 changes: 5 additions & 3 deletions src/app/sign-up/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ export default function SignUp() {
password: data.password,
redirect: false,
})
if (response?.status === 400) {
return toast.error(`${response.data.message}`, { id: waiting })
}
if (res?.error) return setError(res.error)

toast.success('Successfully Signed up!', { id: waiting })

if (res?.ok) return router.push('/dashboard')
}).catch((error)=>
toast.error(`${error}`, { id: waiting }))
return router.push('/dashboard')
})
}
}

Expand Down

0 comments on commit 833c24a

Please sign in to comment.