Attainly/frontend/website/cypress/e2e/guest-auth.cy.ts

92 lines
3.1 KiB
TypeScript

describe('guest authentication pages', () => {
it('shows a public home route to guests', () => {
cy.visit('/')
cy.location('pathname').should('equal', '/')
cy.get('h1').should('have.text', 'Make big goals feel possible.')
cy.contains('a', 'Log in').should('have.attr', 'href', '/login')
cy.contains('a', 'Get started').should('have.attr', 'href', '/signup')
})
it('uses Attainly browser metadata', () => {
cy.visit('/')
cy.title().should('equal', 'Attainly')
cy.get('link[rel="icon"]')
.should('have.attr', 'type', 'image/svg+xml')
.and('have.attr', 'href', '/favicon.svg')
})
it('redirects guests away from the protected dashboard', () => {
cy.visit('/dashboard')
cy.location('pathname').should('equal', '/login')
cy.location('search').should('include', 'redirect=/dashboard')
})
it('redirects guests away from a protected set layout', () => {
cy.visit('/sets/41')
cy.location('pathname').should('equal', '/login')
cy.location('search').should('include', 'redirect=/sets/41')
})
it('redirects guests away from protected schedule routes', () => {
cy.visit('/sets/41/schedules/new')
cy.location('pathname').should('equal', '/login')
cy.visit('/schedules/73')
cy.location('pathname').should('equal', '/login')
})
it('shows the login form and links to signup', () => {
cy.visit('/login')
cy.get('h1').should('have.text', 'Welcome back')
cy.get('label[for="login-email"]').should('have.text', 'Email address')
cy.get('#login-email').should('have.attr', 'autocomplete', 'email')
cy.get('label[for="login-password"]').should('have.text', 'Password')
cy.get('#login-password').should('have.attr', 'autocomplete', 'current-password')
cy.get('button[type="submit"]').should('have.text', 'Log in')
cy.contains('a', 'Create an account').click()
cy.location('pathname').should('equal', '/signup')
})
it('shows the signup form and links to login', () => {
cy.visit('/signup')
cy.get('h1').should('have.text', 'Start your journey')
cy.get('label[for="signup-email"]').should('have.text', 'Email address')
cy.get('#signup-email').should('have.attr', 'autocomplete', 'email')
cy.get('#signup-name').should('not.exist')
cy.get('#signup-password').should('not.exist')
cy.get('#signup-password-confirmation').should('not.exist')
cy.get('button[type="submit"]').should('have.text', 'Continue with email')
cy.contains('a', 'Log in').click()
cy.location('pathname').should('equal', '/login')
})
it('keeps invalid form submissions on their current route', () => {
cy.visit('/login')
cy.get('form').submit()
cy.location('pathname').should('equal', '/login')
cy.visit('/signup')
cy.get('form').submit()
cy.location('pathname').should('equal', '/signup')
})
it('fits the signup page within a mobile viewport', () => {
cy.viewport(390, 844)
cy.visit('/signup')
cy.get('main').should('be.visible')
cy.document().then((document) => {
expect(document.documentElement.scrollWidth).to.be.at.most(
document.documentElement.clientWidth,
)
})
})
})