make tests faster by logging in directly

This commit is contained in:
Nolan Lawson 2018-06-07 19:33:18 -07:00
parent 992c3a890d
commit 71d3aa5e75
2 changed files with 38 additions and 21 deletions

View File

@ -0,0 +1,32 @@
<!-- this is only used in the tests, to log in quickly -->
<script>
import { store } from '../_store/store'
import { goto } from 'sapper/runtime.js'
export default {
oncreate () {
let accessToken = location.search.match(/accessToken=([^&]+)/)[1]
let instanceName = location.search.match(/instanceName=([^&]+)/)[1]
let {
loggedInInstances,
loggedInInstancesInOrder
} = store.get()
loggedInInstances[instanceName] = {
access_token: accessToken
}
if (!loggedInInstancesInOrder.includes(instanceName)) {
loggedInInstancesInOrder.push(instanceName)
}
store.set({
currentInstance: instanceName,
loggedInInstances,
loggedInInstancesInOrder
})
store.save()
goto('/')
}
}
</script>

View File

@ -1,22 +1,9 @@
import {
authorizeInput, emailInput, getUrl, instanceInput, mastodonLogInButton,
passwordInput,
sleep
} from './utils'
import { getUrl } from './utils'
import { users } from './users'
async function login (t, username, password) {
await sleep(500)
await t.typeText(instanceInput, 'localhost:3000', {paste: true})
await sleep(500)
return t
.pressKey('enter')
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in', {timeout: 30000})
.typeText(emailInput, username, {paste: true})
.typeText(passwordInput, password, {paste: true})
.click(mastodonLogInButton)
.expect(getUrl()).contains('/oauth/authorize')
.click(authorizeInput)
// quick login using a secret page and a known access token (makes tests run faster)
async function login (t, user) {
await t.navigateTo(`/settings/quick-login?instanceName=localhost:3000&accessToken=${user.accessToken}`)
.expect(getUrl()).eql('http://localhost:4002/', {timeout: 30000})
}
@ -30,11 +17,9 @@ async function login (t, username, password) {
// })
export async function loginAsFoobar (t) {
await t.navigateTo('/settings/instances/add')
await login(t, users.foobar.email, users.foobar.password)
await login(t, users.foobar)
}
export async function loginAsLockedAccount (t) {
await t.navigateTo('/settings/instances/add')
await login(t, users.LockedAccount.email, users.LockedAccount.password)
await login(t, users.LockedAccount)
}