diff --git a/cypress.json b/cypress.json index 96d06aa..b54458d 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 e881330..6fc8aef 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 0000000..0685dfc --- /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 c1f5a77..afa9dd8 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 0325862..9cd07f2 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 baa0830..1802dfd 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 cca9699..764cd4b 100644 --- a/routes/settings/instances/add.html +++ b/routes/settings/instances/add.html @@ -14,7 +14,7 @@
- {{#if $logInToInstanceError}} + {{#if $logInToInstanceError && $logInToInstanceErrorForText === $instanceNameInSearch}}