FitTrackee/mpwo_client/e2e/admin.test.js
Sam 3f025357b9 e2e test: admin/sports
e2e test: admin/sports
2018-04-29 19:21:22 +02:00

51 lines
1.5 KiB
JavaScript

import { Selector } from 'testcafe'
import { TEST_URL } from './utils'
const randomstring = require('randomstring')
const username = randomstring.generate(8)
const email = `${username}@test.com`
const password = 'lentghOk'
// database must be initialiazed
const adminEmail = 'admin@example.com'
const adminPassword = 'mpwoadmin'
// eslint-disable-next-line no-undef
fixture('/admin').page(`${TEST_URL}/admin`)
test('standard user should not be able to access admin page', async t => {
// register user
await t
.navigateTo(`${TEST_URL}/register`)
.typeText('input[name="username"]', username)
.typeText('input[name="email"]', email)
.typeText('input[name="password"]', password)
.typeText('input[name="passwordConf"]', password)
.click(Selector('input[type="submit"]'))
await t
.navigateTo(`${TEST_URL}/admin`)
.expect(Selector('H1').withText('Access denied').exists).ok()
.expect(Selector('H1').withText('Dashboard').exists).notOk()
})
test('admin should be able to access admin page', async t => {
// admin login
await t
.navigateTo(`${TEST_URL}/login`)
.typeText('input[name="email"]', adminEmail)
.typeText('input[name="password"]', adminPassword)
.click(Selector('input[type="submit"]'))
await t
.navigateTo(`${TEST_URL}/admin`)
.expect(Selector('H1').withText('Access denied').exists).notOk()
.expect(Selector('H1').withText('Administration').exists).ok()
.expect(Selector('.admin-items').withText('Sports').exists).ok()
})