test basic login/logout behavior

This commit is contained in:
Nolan Lawson 2018-02-18 14:31:28 -08:00
parent 302ece9cfa
commit 8e633e3870
7 changed files with 79 additions and 6 deletions

View File

@ -1,4 +1,5 @@
{
"baseUrl": "http://localhost:4002",
"videoRecording": false
"baseUrl": "http://localhost:4002",
"videoRecording": false,
"chromeWebSecurity": false
}

View File

@ -1,4 +1,4 @@
describe('Basic test', () => {
describe('Basic spec', () => {
beforeEach(() => {
cy.visit('/')
})
@ -7,6 +7,14 @@ describe('Basic test', () => {
cy.contains('h1', 'Pinafore')
})
it('navigates to about', () => {
cy.get('nav a').contains('Settings').click()
cy.url().should('contain', '/settings')
cy.get('a').contains('About').click()
cy.url().should('contain', '/settings/about')
cy.contains('h1', 'About Pinafore')
})
it('navigates to /settings/instances/add', () => {
cy.contains('log in to an instance').click()
cy.url().should('contain', '/settings/instances/add')

View File

@ -0,0 +1,37 @@
describe('Login spec', () => {
beforeEach(() => {
cy.visit('/')
})
it('Cannot log in to a fake instance', () => {
cy.get('a').contains('log in to an instance').click()
cy.get('#instanceInput').clear().type('fake.nolanlawson.com')
cy.get('.add-new-instance').submit()
cy.get('.form-error', {timeout: 20000}).contains('Is this a valid Mastodon instance?')
cy.get('#instanceInput').type('.biz')
cy.get('.form-error').should('not.exist')
cy.get('#instanceInput').clear().type('fake.nolanlawson.com')
cy.get('.form-error').should('exist')
})
it('Logs in to localhost:3000', () => {
cy.login('foobar@localhost:3000', 'foobarfoobar')
cy.url().should('equal', 'http://localhost:4002/')
cy.get('article.status-article').should('exist')
})
it('Logs out', () => {
cy.login('foobar@localhost:3000', 'foobarfoobar')
cy.get('nav a').contains('Settings').click()
cy.get('a').contains('Instances').click()
cy.get('a').contains('localhost:3000').click()
cy.url().should('contain', '/settings/instances/localhost:3000')
cy.get('button').contains('Log out').click()
cy.get('button').contains('OK').click()
cy.url().should('contain', '/settings/instances')
cy.contains("You're not logged in to any instances")
})
})

View File

@ -23,3 +23,26 @@
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add('login', (email, password) => {
// mastodon throws some uncaught TypeErrors
cy.on('uncaught:exception', (err) => {
expect(err.name).to.include('TypeError')
expect(err.message).to.include('Illegal invocation')
return false
})
cy.visit('/settings/instances/add')
cy.get('#instanceInput').clear().type('localhost:3000')
cy.get('.add-new-instance').submit()
cy.url().should('equal', 'http://localhost:3000/auth/sign_in')
cy.get('input#user_email').should('exist')
cy.get('input#user_password').should('exist')
cy.get('input#user_email').type(email)
cy.get('input#user_password').type(password)
cy.get('form#new_user').submit()
cy.url().should('contain', '/oauth/authorize')
cy.get('button').contains('Authorize').click()
cy.url().should('equal', 'http://localhost:4002/')
})

View File

@ -18,7 +18,8 @@
"test-mastodon": "run-s wait-for-mastodon-to-start cy:run",
"wait-for-mastodon-to-start": "node bin/wait-for-mastodon-to-start.js",
"globalize-css": "node ./bin/globalize-css.js",
"deglobalize-css": "node ./bin/globalize-css.js --reverse"
"deglobalize-css": "node ./bin/globalize-css.js --reverse",
"backup-mastodon-for-tests": "pg_dump -Fc mastodon_development > fixtures/dump.sql && cd mastodon/public/system && tar -czf ../../../fixtures/system.tgz ."
},
"dependencies": {
"@gamestdio/websocket": "^0.2.2",

View File

@ -47,7 +47,10 @@ export async function logInToInstance () {
(navigator.onLine
? `Is this a valid Mastodon instance?`
: `Are you offline?`)
store.set({logInToInstanceError: error})
store.set({
logInToInstanceError: error,
logInToInstanceErrorForText: store.get('instanceNameInSearch')
})
} finally {
store.set({logInToInstanceLoading: false})
}

View File

@ -14,7 +14,7 @@
<form class="add-new-instance" on:submit='onSubmit(event)' aria-labelledby="add-an-instance-h1">
{{#if $logInToInstanceError}}
{{#if $logInToInstanceError && $logInToInstanceErrorForText === $instanceNameInSearch}}
<div class="form-error" role="alert">
Error: {{$logInToInstanceError}}
</div>