From 8e633e3870dcbe85acd6f5117d2ec6a65b7959b9 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 18 Feb 2018 14:31:28 -0800 Subject: [PATCH] test basic login/logout behavior --- cypress.json | 5 ++-- cypress/integration/basic-spec.js | 10 +++++++- cypress/integration/login-spec.js | 37 ++++++++++++++++++++++++++++++ cypress/support/commands.js | 23 +++++++++++++++++++ package.json | 3 ++- routes/_actions/addInstance.js | 5 +++- routes/settings/instances/add.html | 2 +- 7 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 cypress/integration/login-spec.js diff --git a/cypress.json b/cypress.json index 96d06aa5..b54458d7 100644 --- a/cypress.json +++ b/cypress.json @@ -1,4 +1,5 @@ { - "baseUrl": "http://localhost:4002", - "videoRecording": false + "baseUrl": "http://localhost:4002", + "videoRecording": false, + "chromeWebSecurity": false } \ No newline at end of file diff --git a/cypress/integration/basic-spec.js b/cypress/integration/basic-spec.js index e881330e..6fc8aef9 100644 --- a/cypress/integration/basic-spec.js +++ b/cypress/integration/basic-spec.js @@ -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') diff --git a/cypress/integration/login-spec.js b/cypress/integration/login-spec.js new file mode 100644 index 00000000..0685dfc9 --- /dev/null +++ b/cypress/integration/login-spec.js @@ -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") + }) + +}) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c1f5a772..afa9dd8e 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -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/') +}) \ No newline at end of file diff --git a/package.json b/package.json index 03258625..9cd07f2f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/routes/_actions/addInstance.js b/routes/_actions/addInstance.js index baa08301..1802dfd2 100644 --- a/routes/_actions/addInstance.js +++ b/routes/_actions/addInstance.js @@ -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}) } diff --git a/routes/settings/instances/add.html b/routes/settings/instances/add.html index cca96999..764cd4bb 100644 --- a/routes/settings/instances/add.html +++ b/routes/settings/instances/add.html @@ -14,7 +14,7 @@
- {{#if $logInToInstanceError}} + {{#if $logInToInstanceError && $logInToInstanceErrorForText === $instanceNameInSearch}}