speed up tests

This commit is contained in:
Nolan Lawson 2018-02-28 22:45:42 -08:00
parent 5424242b0f
commit d7366e637a
3 changed files with 25 additions and 23 deletions

View file

@ -1,15 +1,15 @@
import { Selector as $, Role } from 'testcafe' import { Role } from 'testcafe'
import { addInstanceButton, getUrl, instanceInput } from './utils' import { authorizeInput, emailInput, getUrl, instanceInput, passwordInput } from './utils'
function login (t, username, password) { function login (t, username, password) {
return t.typeText(instanceInput, 'localhost:3000') return t.typeText(instanceInput, 'localhost:3000', {paste: true})
.click(addInstanceButton) .pressKey('enter')
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in') .expect(getUrl()).eql('http://localhost:3000/auth/sign_in')
.typeText($('input#user_email'), username) .typeText(emailInput, username, {paste: true})
.typeText($('input#user_password'), password) .typeText(passwordInput, password, {paste: true})
.click($('button[type=submit]')) .pressKey('enter')
.expect(getUrl()).contains('/oauth/authorize') .expect(getUrl()).contains('/oauth/authorize')
.click($('button[type=submit]:not(.negative)')) .click(authorizeInput)
.expect(getUrl()).eql('http://localhost:4002/') .expect(getUrl()).eql('http://localhost:4002/')
} }

View file

@ -1,5 +1,8 @@
import { Selector as $ } from 'testcafe' 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` fixture`02-login-spec.js`
.page`http://localhost:4002` .page`http://localhost:4002`
@ -8,37 +11,33 @@ function manualLogin (t, username, password) {
return t.click($('a').withText('log in to an instance')) return t.click($('a').withText('log in to an instance'))
.expect(getUrl()).contains('/settings/instances/add') .expect(getUrl()).contains('/settings/instances/add')
.typeText(instanceInput, 'localhost:3000') .typeText(instanceInput, 'localhost:3000')
.click(addInstanceButton) .pressKey('enter')
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in') .expect(getUrl()).eql('http://localhost:3000/auth/sign_in')
.typeText($('input#user_email'), username) .typeText(emailInput, username, {paste: true})
.typeText($('input#user_password'), password) .typeText(passwordInput, password, {paste: true})
.click($('button[type=submit]')) .pressKey('enter')
.expect(getUrl()).contains('/oauth/authorize') .expect(getUrl()).contains('/oauth/authorize')
.click($('button[type=submit]:not(.negative)')) .click(authorizeInput)
.expect(getUrl()).eql('http://localhost:4002/') .expect(getUrl()).eql('http://localhost:4002/')
} }
test('Cannot log in to a fake instance', async t => { test('Cannot log in to a fake instance', async t => {
await t.click($('a').withText('log in to an instance')) await t.click($('a').withText('log in to an instance'))
.expect(getUrl()).contains('/settings/instances/add') .expect(getUrl()).contains('/settings/instances/add')
.typeText(instanceInput, 'fake.nolanlawson.com') .typeText(instanceInput, 'fake.nolanlawson.com', {paste: true})
.click(addInstanceButton) .pressKey('enter')
.expect(formError.exists).ok() .expect(formError.exists).ok()
.expect(formError.innerText).contains('Is this a valid Mastodon instance?') .expect(formError.innerText).contains('Is this a valid Mastodon instance?')
.typeText(instanceInput, '.biz') .typeText(instanceInput, '.biz', {paste: true})
.expect(formError.exists).notOk() .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.exists).ok()
.expect(formError.innerText).contains('Is this a valid Mastodon instance?') .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') await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar')
.expect($('article.status-article').exists).ok() .expect($('article.status-article').exists).ok()
})
test('Logs out', async t => {
await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar')
.click(settingsButton) .click(settingsButton)
.click($('a').withText('Instances')) .click($('a').withText('Instances'))
.click($('a').withText('localhost:3000')) .click($('a').withText('localhost:3000'))

View file

@ -14,6 +14,9 @@ export const composeInput = $('.compose-box-input')
export const composeButton = $('.compose-box-button') export const composeButton = $('.compose-box-button')
export const composeLengthIndicator = $('.compose-box-length') export const composeLengthIndicator = $('.compose-box-length')
export const emojiButton = $('.compose-box-toolbar button:first-child') 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({ export const favoritesCountElement = $('.status-favs-reblogs:nth-child(3)').addCustomDOMProperties({
innerCount: el => parseInt(el.innerText, 10) innerCount: el => parseInt(el.innerText, 10)