From d7366e637a485c1b3d28224ce2af3c9e110b294b Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 28 Feb 2018 22:45:42 -0800 Subject: [PATCH] speed up tests --- tests/roles.js | 16 ++++++++-------- tests/spec/02-login-spec.js | 29 ++++++++++++++--------------- tests/utils.js | 3 +++ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/tests/roles.js b/tests/roles.js index d78f17e..b9c6958 100644 --- a/tests/roles.js +++ b/tests/roles.js @@ -1,15 +1,15 @@ -import { Selector as $, Role } from 'testcafe' -import { addInstanceButton, getUrl, instanceInput } from './utils' +import { Role } from 'testcafe' +import { authorizeInput, emailInput, getUrl, instanceInput, passwordInput } from './utils' function login (t, username, password) { - return t.typeText(instanceInput, 'localhost:3000') - .click(addInstanceButton) + return t.typeText(instanceInput, 'localhost:3000', {paste: true}) + .pressKey('enter') .expect(getUrl()).eql('http://localhost:3000/auth/sign_in') - .typeText($('input#user_email'), username) - .typeText($('input#user_password'), password) - .click($('button[type=submit]')) + .typeText(emailInput, username, {paste: true}) + .typeText(passwordInput, password, {paste: true}) + .pressKey('enter') .expect(getUrl()).contains('/oauth/authorize') - .click($('button[type=submit]:not(.negative)')) + .click(authorizeInput) .expect(getUrl()).eql('http://localhost:4002/') } diff --git a/tests/spec/02-login-spec.js b/tests/spec/02-login-spec.js index 2f630be..78c84b2 100644 --- a/tests/spec/02-login-spec.js +++ b/tests/spec/02-login-spec.js @@ -1,5 +1,8 @@ import { Selector as $ } from 'testcafe' -import { addInstanceButton, formError, getUrl, instanceInput, settingsButton } from '../utils' +import { + authorizeInput, emailInput, formError, getUrl, instanceInput, passwordInput, + settingsButton +} from '../utils' fixture`02-login-spec.js` .page`http://localhost:4002` @@ -8,37 +11,33 @@ function manualLogin (t, username, password) { return t.click($('a').withText('log in to an instance')) .expect(getUrl()).contains('/settings/instances/add') .typeText(instanceInput, 'localhost:3000') - .click(addInstanceButton) + .pressKey('enter') .expect(getUrl()).eql('http://localhost:3000/auth/sign_in') - .typeText($('input#user_email'), username) - .typeText($('input#user_password'), password) - .click($('button[type=submit]')) + .typeText(emailInput, username, {paste: true}) + .typeText(passwordInput, password, {paste: true}) + .pressKey('enter') .expect(getUrl()).contains('/oauth/authorize') - .click($('button[type=submit]:not(.negative)')) + .click(authorizeInput) .expect(getUrl()).eql('http://localhost:4002/') } test('Cannot log in to a fake instance', async t => { await t.click($('a').withText('log in to an instance')) .expect(getUrl()).contains('/settings/instances/add') - .typeText(instanceInput, 'fake.nolanlawson.com') - .click(addInstanceButton) + .typeText(instanceInput, 'fake.nolanlawson.com', {paste: true}) + .pressKey('enter') .expect(formError.exists).ok() .expect(formError.innerText).contains('Is this a valid Mastodon instance?') - .typeText(instanceInput, '.biz') + .typeText(instanceInput, '.biz', {paste: true}) .expect(formError.exists).notOk() - .typeText(instanceInput, 'fake.nolanlawson.com', {replace: true}) + .typeText(instanceInput, 'fake.nolanlawson.com', {paste: true, replace: true}) .expect(formError.exists).ok() .expect(formError.innerText).contains('Is this a valid Mastodon instance?') }) -test('Logs in to localhost:3000', async t => { +test('Logs in and logs out of localhost:3000', async t => { await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar') .expect($('article.status-article').exists).ok() -}) - -test('Logs out', async t => { - await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar') .click(settingsButton) .click($('a').withText('Instances')) .click($('a').withText('localhost:3000')) diff --git a/tests/utils.js b/tests/utils.js index 103caab..de122a7 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -14,6 +14,9 @@ export const composeInput = $('.compose-box-input') export const composeButton = $('.compose-box-button') export const composeLengthIndicator = $('.compose-box-length') export const emojiButton = $('.compose-box-toolbar button:first-child') +export const emailInput = $('input#user_email') +export const passwordInput = $('input#user_password') +export const authorizeInput = $('button[type=submit]:not(.negative)') export const favoritesCountElement = $('.status-favs-reblogs:nth-child(3)').addCustomDOMProperties({ innerCount: el => parseInt(el.innerText, 10)