add a user role

modify-database
Nolan Lawson 2018-02-19 17:18:40 -08:00
rodzic 13a2195035
commit 819f975948
4 zmienionych plików z 34 dodań i 26 usunięć

18
tests/roles.js 100644
Wyświetl plik

@ -0,0 +1,18 @@
import { Selector as $, Role } from 'testcafe'
import { addInstanceButton, getUrl, instanceInput } from './utils'
function login(t, username, password) {
return t.typeText(instanceInput, 'localhost:3000')
.click(addInstanceButton)
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in')
.typeText($('input#user_email'), username)
.typeText($('input#user_password'), password)
.click($('button[type=submit]'))
.expect(getUrl()).contains('/oauth/authorize')
.click($('button[type=submit]:not(.negative)'))
.expect(getUrl()).eql('http://localhost:4002/')
}
export const foobarRole = Role('http://localhost:4002/settings/instances/add', async t => {
await login(t, 'foobar@localhost:3000', 'foobarfoobar')
})

Wyświetl plik

@ -1,13 +1,15 @@
import { Selector as $ } from 'testcafe'
import { addInstanceButton, getUrl, instanceInput, login, settingsButton } from '../utils'
import { foobarRole } from '../roles'
fixture `02-login-spec.js`
.page `http://localhost:4002`
const formError = $('.form-error')
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'))
.expect(getUrl()).contains('/settings/instances/add')
.typeText(instanceInput, 'fake.nolanlawson.com')
.click(addInstanceButton)
.expect(formError.exists).ok()
@ -20,12 +22,12 @@ test('Cannot log in to a fake instance', async t => {
})
test('Logs in to localhost:3000', async t => {
await login(t, 'foobar@localhost:3000', 'foobarfoobar')
await t.useRole(foobarRole)
.expect($('article.status-article').exists).ok()
})
test('Logs out', async t => {
await login(t, 'foobar@localhost:3000', 'foobarfoobar')
await t.useRole(foobarRole)
.click(settingsButton)
.click($('a').withText('Instances'))
.click($('a').withText('localhost:3000'))

Wyświetl plik

@ -1,17 +1,15 @@
import { Selector as $ } from 'testcafe'
import { getUrl, login, validateTimeline } from '../utils'
import { homeTimeline, notifications, localTimeline, favorites } from '../fixtures'
import { foobarRole } from '../roles'
fixture `03-basic-timeline-spec.js`
.page `http://localhost:4002`
.beforeEach(async t => {
await login(t, 'foobar@localhost:3000', 'foobarfoobar')
})
const firstArticle = $('.virtual-list-item[aria-hidden=false] .status-article')
test('Shows the home timeline', async t => {
await t
await t.useRole(foobarRole)
.expect(firstArticle.hasAttribute('aria-setsize')).ok()
.expect(firstArticle.getAttribute('aria-posinset')).eql('0')
@ -21,21 +19,24 @@ test('Shows the home timeline', async t => {
})
test('Shows notifications', async t => {
await t.click($('nav a[aria-label=Notifications]'))
await t.useRole(foobarRole)
.click($('nav a[aria-label=Notifications]'))
.expect(getUrl()).contains('/notifications')
await validateTimeline(t, notifications)
})
test('Shows the local timeline', async t => {
await t.click($('nav a[aria-label=Local]'))
await t.expect(getUrl()).contains('/local')
await t.useRole(foobarRole)
.click($('nav a[aria-label=Local]'))
.expect(getUrl()).contains('/local')
await validateTimeline(t, localTimeline)
})
test('Shows the federated timeline', async t => {
await t.click($('nav a[aria-label=Community]'))
await t.useRole(foobarRole)
.click($('nav a[aria-label=Community]'))
.expect(getUrl()).contains('/community')
.click($('a').withText('Federated'))
.expect(getUrl()).contains('/federated')
@ -44,7 +45,8 @@ test('Shows the federated timeline', async t => {
})
test('Shows favorites', async t => {
await t.click($('nav a[aria-label=Community]'))
await t.useRole(foobarRole)
.click($('nav a[aria-label=Community]'))
.expect(getUrl()).contains('/community')
.click($('a').withText('Favorites'))
.expect(getUrl()).contains('/favorites')

Wyświetl plik

@ -6,20 +6,6 @@ export const addInstanceButton = $('.add-new-instance button')
export const getUrl = exec(() => window.location.href)
export function login(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)
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in')
.typeText($('input#user_email'), username)
.typeText($('input#user_password'), password)
.click($('button[type=submit]'))
.expect(getUrl()).contains('/oauth/authorize')
.click($('button[type=submit]:not(.negative)'))
.expect(getUrl()).eql('http://localhost:4002/')
}
export function getNthVirtualArticle (n) {
return $(`.virtual-list-item[aria-hidden="false"] article[aria-posinset="${n}"]`)
}