Skip to content

Commit

Permalink
add min length
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed May 29, 2023
1 parent ca9a7d8 commit 5759a43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cypress/e2e/login/login-form.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,31 @@ describe('Login form', () => {
cy.visit('/')
})

it('hides the username', () => {
cy.get(LoginPage.selectors.username).type('username', { hide: true })
})
it(
'checks if the username is at least 6 characters',
{ browser: ['electron', 'chrome'] },
() => {
// get the username input field and focus on it
// https://on.cypress.io/get
// https://on.cypress.io/focus
//
// type username that is too short
// using the cy.realType command from cypress-real-events plugin
//
// confirm the username input field has CSS pseudo class ":invalid"
// https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation
// https://glebbahmutov.com/blog/form-validation-in-cypress/
//
// confirm the form is invalid by calling its method "checkValidity"
//
// we know we are getting a form element from the page
//
// confirm the validation message on the username input field
// includes the phrase "6 characters or more"
//
// confirm the username input element
// has property "validity" which is an object
// with "tooShort: true" property
},
)
})
1 change: 1 addition & 0 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function Login(props) {
name="user-name"
autoCorrect="off"
autoCapitalize="none"
minLength="6"
/>
<InputError
isError={Boolean(error)}
Expand Down

0 comments on commit 5759a43

Please sign in to comment.