2020-12-10 13:52:35 +00:00
|
|
|
import {UserFactory} from '../../factories/user'
|
|
|
|
|
|
|
|
const testAndAssertFailed = fixture => {
|
|
|
|
cy.visit('/login')
|
|
|
|
cy.get('input[id=username]').type(fixture.username)
|
|
|
|
cy.get('input[id=password]').type(fixture.password)
|
2021-01-17 17:57:57 +00:00
|
|
|
cy.get('.button').contains('Login').click()
|
2020-12-10 13:52:35 +00:00
|
|
|
|
|
|
|
cy.wait(5000) // It can take waaaayy too long to log the user in
|
|
|
|
cy.url().should('include', '/')
|
2021-11-28 14:18:27 +00:00
|
|
|
cy.get('div.message.danger').contains('Wrong username or password.')
|
2020-12-10 13:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 21:35:17 +00:00
|
|
|
const username = 'test'
|
|
|
|
|
2020-12-10 13:52:35 +00:00
|
|
|
context('Login', () => {
|
|
|
|
beforeEach(() => {
|
2022-12-15 21:35:17 +00:00
|
|
|
UserFactory.create(1, {username})
|
2020-12-10 13:52:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should log in with the right credentials', () => {
|
|
|
|
const fixture = {
|
|
|
|
username: 'test',
|
|
|
|
password: '1234',
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.visit('/login')
|
|
|
|
cy.get('input[id=username]').type(fixture.username)
|
|
|
|
cy.get('input[id=password]').type(fixture.password)
|
2021-01-17 17:57:57 +00:00
|
|
|
cy.get('.button').contains('Login').click()
|
2020-12-10 13:52:35 +00:00
|
|
|
cy.url().should('include', '/')
|
2021-07-07 08:19:37 +00:00
|
|
|
cy.clock(1625656161057) // 13:00
|
2020-12-10 13:52:35 +00:00
|
|
|
cy.get('h2').should('contain', `Hi ${fixture.username}!`)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad password', () => {
|
|
|
|
const fixture = {
|
|
|
|
username: 'test',
|
|
|
|
password: '123456',
|
|
|
|
}
|
|
|
|
|
|
|
|
testAndAssertFailed(fixture)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad username', () => {
|
|
|
|
const fixture = {
|
|
|
|
username: 'loremipsum',
|
|
|
|
password: '1234',
|
|
|
|
}
|
|
|
|
|
|
|
|
testAndAssertFailed(fixture)
|
|
|
|
})
|
2022-10-20 14:15:58 +00:00
|
|
|
|
|
|
|
it('Should redirect to /login when no user is logged in', () => {
|
|
|
|
cy.visit('/')
|
|
|
|
cy.url().should('include', '/login')
|
|
|
|
})
|
2020-12-10 13:52:35 +00:00
|
|
|
})
|