refactor tests

This commit is contained in:
Nolan Lawson 2018-03-16 10:06:02 -07:00
parent 4e47f3048b
commit bfc9692667
5 changed files with 30 additions and 30 deletions

View File

@ -12,28 +12,28 @@ global.FormData = FileApi.FormData
const instanceName = 'localhost:3000' const instanceName = 'localhost:3000'
export async function favoriteStatusAsAdmin (statusId) { export async function favoriteStatusAs (username, statusId) {
return favoriteStatus(instanceName, users.admin.accessToken, statusId) return favoriteStatus(instanceName, users[username].accessToken, statusId)
} }
export async function postAsAdmin (text) { export async function postAs (username, text) {
return postStatus(instanceName, users.admin.accessToken, text, return postStatus(instanceName, users[username].accessToken, text,
null, null, false, null, 'public') null, null, false, null, 'public')
} }
export async function postReplyAsAdmin (text, inReplyTo) { export async function postReplyAs (username, text, inReplyTo) {
return postStatus(instanceName, users.admin.accessToken, text, return postStatus(instanceName, users[username].accessToken, text,
inReplyTo, null, false, null, 'public') inReplyTo, null, false, null, 'public')
} }
export async function deleteAsAdmin (statusId) { export async function deleteAs (username, statusId) {
return deleteStatus(instanceName, users.admin.accessToken, statusId) return deleteStatus(instanceName, users[username].accessToken, statusId)
} }
export async function getFollowRequestsAsLockedAccount () { export async function getFollowRequestsAs (username) {
return getFollowRequests(instanceName, users.LockedAccount.accessToken) return getFollowRequests(instanceName, users[username].accessToken)
} }
export async function authorizeFollowRequestAsLockedAccount (id) { export async function authorizeFollowRequestAs (username, id) {
return authorizeFollowRequest(instanceName, users.LockedAccount.accessToken, id) return authorizeFollowRequest(instanceName, users[username].accessToken, id)
} }

View File

@ -1,6 +1,6 @@
import { foobarRole } from '../roles' import { foobarRole } from '../roles'
import { getNthStatus, getUrl, homeNavButton, notificationsNavButton, validateTimeline } from '../utils' import { getNthStatus, getUrl, homeNavButton, notificationsNavButton, validateTimeline } from '../utils'
import { favoriteStatusAsAdmin } from '../serverActions' import { favoriteStatusAs } from '../serverActions'
import { notifications } from '../fixtures' import { notifications } from '../fixtures'
fixture`102-notifications.js` fixture`102-notifications.js`
@ -15,7 +15,7 @@ test('shows unread notifications', async t => {
.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications') .expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications')
let statusId = (await getNthStatus(5).find('.status-relative-date').getAttribute('href')) let statusId = (await getNthStatus(5).find('.status-relative-date').getAttribute('href'))
.split('/').slice(-1)[0] .split('/').slice(-1)[0]
await favoriteStatusAsAdmin(statusId) await favoriteStatusAs('admin', statusId)
await t await t
.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications (1)') .expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications (1)')
.click(notificationsNavButton) .click(notificationsNavButton)

View File

@ -2,7 +2,7 @@ import { foobarRole } from '../roles'
import { import {
getNthStatus, scrollContainerToTop, showMoreButton, sleep getNthStatus, scrollContainerToTop, showMoreButton, sleep
} from '../utils' } from '../utils'
import { postAsAdmin } from '../serverActions' import { postAs } from '../serverActions'
fixture`104-streaming.js` fixture`104-streaming.js`
.page`http://localhost:4002` .page`http://localhost:4002`
@ -10,7 +10,7 @@ fixture`104-streaming.js`
test('new incoming statuses show up immediately', async t => { test('new incoming statuses show up immediately', async t => {
await t.useRole(foobarRole) await t.useRole(foobarRole)
.hover(getNthStatus(0)) .hover(getNthStatus(0))
await postAsAdmin('hello my baby hello my honey') await postAs('admin', 'hello my baby hello my honey')
await t.expect(getNthStatus(0).innerText).contains('hello my baby hello my honey') await t.expect(getNthStatus(0).innerText).contains('hello my baby hello my honey')
}) })
@ -20,8 +20,8 @@ test('new incoming toots show a button if scrolled down', async t => {
.hover(getNthStatus(2)) .hover(getNthStatus(2))
.hover(getNthStatus(4)) .hover(getNthStatus(4))
await sleep(1000) await sleep(1000)
await postAsAdmin('hello my ragtime gal') await postAs('admin', 'hello my ragtime gal')
await postAsAdmin('send me a kiss by wire') await postAs('admin', 'send me a kiss by wire')
await sleep(4000) await sleep(4000)
await t.hover(getNthStatus(2)) await t.hover(getNthStatus(2))
.hover(getNthStatus(0)) .hover(getNthStatus(0))
@ -29,7 +29,7 @@ test('new incoming toots show a button if scrolled down', async t => {
await sleep(1000) await sleep(1000)
await t await t
.expect(showMoreButton.innerText).contains('Show 2 more') .expect(showMoreButton.innerText).contains('Show 2 more')
await postAsAdmin("baby my heart's on fire") await postAs('admin', "baby my heart's on fire")
await sleep(4000) await sleep(4000)
await t.expect(showMoreButton.innerText).contains('Show 3 more') await t.expect(showMoreButton.innerText).contains('Show 3 more')
.click(showMoreButton) .click(showMoreButton)

View File

@ -4,7 +4,7 @@ import {
notificationsNavButton, notificationsNavButton,
sleep sleep
} from '../utils' } from '../utils'
import { deleteAsAdmin, postAsAdmin, postReplyAsAdmin } from '../serverActions' import { deleteAs, postAs, postReplyAs } from '../serverActions'
fixture`105-deletes.js` fixture`105-deletes.js`
.page`http://localhost:4002` .page`http://localhost:4002`
@ -12,10 +12,10 @@ fixture`105-deletes.js`
test('deleted statuses are removed from the timeline', async t => { test('deleted statuses are removed from the timeline', async t => {
await t.useRole(foobarRole) await t.useRole(foobarRole)
.hover(getNthStatus(0)) .hover(getNthStatus(0))
let status = await postAsAdmin("I'm gonna delete this") let status = await postAs('admin', "I'm gonna delete this")
await sleep(1000) await sleep(1000)
await t.expect(getNthStatus(0).innerText).contains("I'm gonna delete this") await t.expect(getNthStatus(0).innerText).contains("I'm gonna delete this")
await deleteAsAdmin(status.id) await deleteAs('admin', status.id)
await sleep(1000) await sleep(1000)
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this") await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this")
await clickToNotificationsAndBackHome(t) await clickToNotificationsAndBackHome(t)
@ -33,8 +33,8 @@ test('deleted statuses are removed from the timeline', async t => {
test('deleted statuses are removed from threads', async t => { test('deleted statuses are removed from threads', async t => {
await t.useRole(foobarRole) await t.useRole(foobarRole)
.hover(getNthStatus(0)) .hover(getNthStatus(0))
let status = await postAsAdmin("I won't delete this") let status = await postAs('admin', "I won't delete this")
let reply = await postReplyAsAdmin('But I will delete this', status.id) let reply = await postReplyAs('admin', 'But I will delete this', status.id)
await sleep(5000) await sleep(5000)
await t.expect(getNthStatus(0).innerText).contains('But I will delete this') await t.expect(getNthStatus(0).innerText).contains('But I will delete this')
.expect(getNthStatus(1).innerText).contains("I won't delete this") .expect(getNthStatus(1).innerText).contains("I won't delete this")
@ -42,7 +42,7 @@ test('deleted statuses are removed from threads', async t => {
.expect(getUrl()).contains('/statuses') .expect(getUrl()).contains('/statuses')
.expect(getNthStatus(0).innerText).contains("I won't delete this") .expect(getNthStatus(0).innerText).contains("I won't delete this")
.expect(getNthStatus(1).innerText).contains('But I will delete this') .expect(getNthStatus(1).innerText).contains('But I will delete this')
await deleteAsAdmin(reply.id) await deleteAs('admin', reply.id)
await sleep(1000) await sleep(1000)
await t.expect(getNthStatus(1).exists).notOk() await t.expect(getNthStatus(1).exists).notOk()
.expect(getNthStatus(0).innerText).contains("I won't delete this") .expect(getNthStatus(0).innerText).contains("I won't delete this")
@ -59,10 +59,10 @@ test('deleted statuses result in deleted notifications', async t => {
await t.useRole(foobarRole) await t.useRole(foobarRole)
.hover(getNthStatus(0)) .hover(getNthStatus(0))
.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications') .expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications')
let status = await postAsAdmin("@foobar yo yo foobar what's up") let status = await postAs('admin', "@foobar yo yo foobar what's up")
await sleep(2000) await sleep(2000)
await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications (1)') await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications (1)')
await deleteAsAdmin(status.id) await deleteAs('admin', status.id)
await sleep(5000) await sleep(5000)
await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications') await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications')
}) })

View File

@ -5,7 +5,7 @@ import {
sleep sleep
} from '../utils' } from '../utils'
import { import {
authorizeFollowRequestAsLockedAccount, getFollowRequestsAsLockedAccount authorizeFollowRequestAs, getFollowRequestsAs
} from '../serverActions' } from '../serverActions'
fixture`106-follow-requests.js` fixture`106-follow-requests.js`
@ -22,8 +22,8 @@ test('can request to follow an account', async t => {
.click(accountProfileFollowButton) .click(accountProfileFollowButton)
.expect(accountProfileFollowButton.getAttribute('aria-label')).eql('Unfollow (follow requested)') .expect(accountProfileFollowButton.getAttribute('aria-label')).eql('Unfollow (follow requested)')
let requests = await getFollowRequestsAsLockedAccount() let requests = await getFollowRequestsAs('LockedAccount')
await authorizeFollowRequestAsLockedAccount(requests.slice(-1)[0].id) await authorizeFollowRequestAs('LockedAccount', requests.slice(-1)[0].id)
await sleep(2000) await sleep(2000)