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 { 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/')
}

View File

@ -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'))

View File

@ -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)