first commit
This commit is contained in:
82
ui/tests/e2e/specs/auth.e2e.js
Normal file
82
ui/tests/e2e/specs/auth.e2e.js
Normal file
@@ -0,0 +1,82 @@
|
||||
describe('Authentication', () => {
|
||||
it('login link exists on the home page when logged out', () => {
|
||||
cy.visit('/')
|
||||
cy.contains('a', 'Log in').should('have.attr', 'href', '/login')
|
||||
})
|
||||
|
||||
it('login form shows an error on failure', () => {
|
||||
cy.visit('/login')
|
||||
|
||||
// Enter bad login info
|
||||
cy.get('input[name="username"]').type('badUsername')
|
||||
cy.get('input[name="password"]').type('badPassword')
|
||||
|
||||
// Submit the login form
|
||||
cy.contains('button', 'Log in').click()
|
||||
|
||||
// Ensure that an error displays
|
||||
cy.contains('error logging in')
|
||||
})
|
||||
|
||||
it('successful login works redirects to the home page and logging out works', () => {
|
||||
cy.visit('/login')
|
||||
|
||||
// Enter the user-supplied username and password
|
||||
cy.get('input[name="username"]').type('admin')
|
||||
cy.get('input[name="password"]').type('password')
|
||||
|
||||
// Submit the login form
|
||||
cy.contains('button', 'Log in').click()
|
||||
|
||||
// Confirm redirection to the homepage
|
||||
cy.location('pathname').should('equal', '/')
|
||||
|
||||
// Confirm a logout link exists
|
||||
cy.contains('a', 'Log out')
|
||||
})
|
||||
|
||||
it('login after attempting to visit authenticated route redirects to that route after login', () => {
|
||||
cy.visit('/profile?someQuery')
|
||||
|
||||
// Confirm redirection to the login page
|
||||
cy.location('pathname').should('equal', '/login')
|
||||
|
||||
// Enter the user-supplied username and password
|
||||
cy.get('input[name="username"]').type('admin')
|
||||
cy.get('input[name="password"]').type('password')
|
||||
|
||||
// Submit the login form
|
||||
cy.contains('button', 'Log in').click()
|
||||
|
||||
// Confirm redirection to the homepage
|
||||
cy.location('pathname').should('equal', '/profile')
|
||||
cy.location('search').should('equal', '?someQuery')
|
||||
|
||||
// Confirm a logout link exists
|
||||
cy.contains('a', 'Log out')
|
||||
})
|
||||
|
||||
it('logout link logs the user out when logged in', () => {
|
||||
cy.logIn()
|
||||
|
||||
// Click the logout link
|
||||
cy.contains('a', 'Log out').click()
|
||||
|
||||
// Confirm that the user is logged out
|
||||
cy.contains('a', 'Log in')
|
||||
})
|
||||
|
||||
it('logout from an authenticated route redirects to home', () => {
|
||||
cy.logIn()
|
||||
cy.visit('/profile')
|
||||
|
||||
// Click the logout link
|
||||
cy.contains('a', 'Log out').click()
|
||||
|
||||
// Confirm we're on the correct page
|
||||
cy.location('pathname').should('equal', '/')
|
||||
|
||||
// Confirm that the user is logged out
|
||||
cy.contains('a', 'Log in')
|
||||
})
|
||||
})
|
||||
7
ui/tests/e2e/specs/home.e2e.js
Normal file
7
ui/tests/e2e/specs/home.e2e.js
Normal file
@@ -0,0 +1,7 @@
|
||||
describe('Home Page', () => {
|
||||
it('has the correct title and heading', () => {
|
||||
cy.visit('/')
|
||||
cy.title().should('equal', 'Home | Hammond')
|
||||
cy.contains('h1', 'Home Page')
|
||||
})
|
||||
})
|
||||
33
ui/tests/e2e/specs/profile.e2e.js
Normal file
33
ui/tests/e2e/specs/profile.e2e.js
Normal file
@@ -0,0 +1,33 @@
|
||||
describe('Profile Page', () => {
|
||||
it('redirects to login when logged out', () => {
|
||||
cy.visit('/profile')
|
||||
cy.location('pathname').should('equal', '/login')
|
||||
})
|
||||
|
||||
it('nav link exists when logged in', () => {
|
||||
cy.logIn()
|
||||
cy.contains('a', 'Logged in as Vue Master').should(
|
||||
'have.attr',
|
||||
'href',
|
||||
'/profile'
|
||||
)
|
||||
})
|
||||
|
||||
it('shows the current user profile when logged in', () => {
|
||||
cy.logIn()
|
||||
cy.visit('/profile')
|
||||
cy.contains('h1', 'Vue Master')
|
||||
})
|
||||
|
||||
it('shows non-current users at username routes when logged in', () => {
|
||||
cy.logIn()
|
||||
cy.visit('/profile/user1')
|
||||
cy.contains('h1', 'User One')
|
||||
})
|
||||
|
||||
it('shows a user 404 page when looking for a user that does not exist', () => {
|
||||
cy.logIn()
|
||||
cy.visit('/profile/non-existant-user')
|
||||
cy.contains('h1', /User\s+Not\s+Found/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user