Skip to content

Commit

Permalink
gh-238. Add login e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhbankov-rpp committed Mar 14, 2021
1 parent 1b78c67 commit 2843250
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import className from 'classnames'
import Spinner from '../../../components/Spinner'
import {useAuth} from '../hooks'

// TODO: implement form validation

export function LoginPage() {
const {login, isLogginInProgress, error, hasToken} = useAuth()
const [email, setEmail] = useState(null)
Expand Down Expand Up @@ -93,7 +95,10 @@ export function LoginPage() {
Sign in
</button>
{error && (
<div className={className('text-red-600', `${error ? 'visible' : 'invisible'}`)}>
<div
data-test-id="login-error"
className={className('text-red-600', `${error ? 'visible' : 'invisible'}`)}
>
Invalid password or email
</div>
)}
Expand Down
17 changes: 17 additions & 0 deletions e2e/cypress/integration/login.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
describe('Logging In', function () {
const email = '[email protected]'
const invalidEmail = 'invalid email string'
const password = 'password123'

beforeEach(function () {
cy.visit('/login')
})

it('fail login on invalid email', function () {
cy.get('[data-test-id="login-error"]').should('not.exist')
cy.get('[data-test-id="email"]').type(invalidEmail)
cy.get('[data-test-id="password"]').type(password)
cy.get('[data-test-id="submit"]').click()
cy.get('[data-test-id="login-error"]').should('be.visible')
})

it('fail login with empty password', function () {
cy.reload()
cy.get('[data-test-id="login-error"]').should('not.exist')
cy.get('[data-test-id="email"]').type(email)
cy.get('[data-test-id="submit"]').click()
cy.get('[data-test-id="login-error"]').should('be.visible')
})

it('redirects to /home on success', function () {
cy.get('[data-test-id="email"]').type(email)
cy.get('[data-test-id="password"]').type(password)
Expand Down

0 comments on commit 2843250

Please sign in to comment.