add a user role
This commit is contained in:
parent
13a2195035
commit
819f975948
|
@ -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')
|
||||||
|
})
|
|
@ -1,13 +1,15 @@
|
||||||
import { Selector as $ } from 'testcafe'
|
import { Selector as $ } from 'testcafe'
|
||||||
import { addInstanceButton, getUrl, instanceInput, login, settingsButton } from '../utils'
|
import { addInstanceButton, getUrl, instanceInput, login, settingsButton } from '../utils'
|
||||||
|
import { foobarRole } from '../roles'
|
||||||
|
|
||||||
fixture `02-login-spec.js`
|
fixture `02-login-spec.js`
|
||||||
.page `http://localhost:4002`
|
.page `http://localhost:4002`
|
||||||
|
|
||||||
const formError = $('.form-error')
|
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'))
|
await t.click($('a').withText('log in to an instance'))
|
||||||
|
.expect(getUrl()).contains('/settings/instances/add')
|
||||||
.typeText(instanceInput, 'fake.nolanlawson.com')
|
.typeText(instanceInput, 'fake.nolanlawson.com')
|
||||||
.click(addInstanceButton)
|
.click(addInstanceButton)
|
||||||
.expect(formError.exists).ok()
|
.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 => {
|
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()
|
.expect($('article.status-article').exists).ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Logs out', async t => {
|
test('Logs out', async t => {
|
||||||
await login(t, 'foobar@localhost:3000', 'foobarfoobar')
|
await t.useRole(foobarRole)
|
||||||
.click(settingsButton)
|
.click(settingsButton)
|
||||||
.click($('a').withText('Instances'))
|
.click($('a').withText('Instances'))
|
||||||
.click($('a').withText('localhost:3000'))
|
.click($('a').withText('localhost:3000'))
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
import { Selector as $ } from 'testcafe'
|
import { Selector as $ } from 'testcafe'
|
||||||
import { getUrl, login, validateTimeline } from '../utils'
|
import { getUrl, login, validateTimeline } from '../utils'
|
||||||
import { homeTimeline, notifications, localTimeline, favorites } from '../fixtures'
|
import { homeTimeline, notifications, localTimeline, favorites } from '../fixtures'
|
||||||
|
import { foobarRole } from '../roles'
|
||||||
|
|
||||||
fixture `03-basic-timeline-spec.js`
|
fixture `03-basic-timeline-spec.js`
|
||||||
.page `http://localhost:4002`
|
.page `http://localhost:4002`
|
||||||
.beforeEach(async t => {
|
|
||||||
await login(t, 'foobar@localhost:3000', 'foobarfoobar')
|
|
||||||
})
|
|
||||||
|
|
||||||
const firstArticle = $('.virtual-list-item[aria-hidden=false] .status-article')
|
const firstArticle = $('.virtual-list-item[aria-hidden=false] .status-article')
|
||||||
|
|
||||||
test('Shows the home timeline', async t => {
|
test('Shows the home timeline', async t => {
|
||||||
await t
|
await t.useRole(foobarRole)
|
||||||
.expect(firstArticle.hasAttribute('aria-setsize')).ok()
|
.expect(firstArticle.hasAttribute('aria-setsize')).ok()
|
||||||
.expect(firstArticle.getAttribute('aria-posinset')).eql('0')
|
.expect(firstArticle.getAttribute('aria-posinset')).eql('0')
|
||||||
|
|
||||||
|
@ -21,21 +19,24 @@ test('Shows the home timeline', async t => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Shows notifications', 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')
|
.expect(getUrl()).contains('/notifications')
|
||||||
|
|
||||||
await validateTimeline(t, notifications)
|
await validateTimeline(t, notifications)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Shows the local timeline', async t => {
|
test('Shows the local timeline', async t => {
|
||||||
await t.click($('nav a[aria-label=Local]'))
|
await t.useRole(foobarRole)
|
||||||
await t.expect(getUrl()).contains('/local')
|
.click($('nav a[aria-label=Local]'))
|
||||||
|
.expect(getUrl()).contains('/local')
|
||||||
|
|
||||||
await validateTimeline(t, localTimeline)
|
await validateTimeline(t, localTimeline)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Shows the federated timeline', async t => {
|
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')
|
.expect(getUrl()).contains('/community')
|
||||||
.click($('a').withText('Federated'))
|
.click($('a').withText('Federated'))
|
||||||
.expect(getUrl()).contains('/federated')
|
.expect(getUrl()).contains('/federated')
|
||||||
|
@ -44,7 +45,8 @@ test('Shows the federated timeline', async t => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Shows favorites', 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')
|
.expect(getUrl()).contains('/community')
|
||||||
.click($('a').withText('Favorites'))
|
.click($('a').withText('Favorites'))
|
||||||
.expect(getUrl()).contains('/favorites')
|
.expect(getUrl()).contains('/favorites')
|
||||||
|
|
|
@ -6,20 +6,6 @@ export const addInstanceButton = $('.add-new-instance button')
|
||||||
|
|
||||||
export const getUrl = exec(() => window.location.href)
|
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) {
|
export function getNthVirtualArticle (n) {
|
||||||
return $(`.virtual-list-item[aria-hidden="false"] article[aria-posinset="${n}"]`)
|
return $(`.virtual-list-item[aria-hidden="false"] article[aria-posinset="${n}"]`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue