Client: tests update

This commit is contained in:
Sam 2018-05-08 21:35:37 +02:00
parent e6d2ad914f
commit 569b6dbc6e
2 changed files with 44 additions and 2 deletions

View File

@ -0,0 +1,42 @@
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'
// eslint-disable-next-line no-undef
fixture('/activities').page(`${TEST_URL}/activities`)
test('standard user should be add a workout (w/o gpx)', async t => {
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}/activities/add`)
.expect(Selector('H1').withText('Dashboard').exists).notOk()
.expect(Selector('H2').withText('Add a sport').exists).ok()
.click(Selector('input[name="withoutGpx"]'))
.click(Selector('select').filter('[name="sport_id"]'))
.click(Selector('option').filter('[value="1"]'))
.typeText('input[name="activity_date"]', '2018-12-20')
.typeText('input[name="activity_time"]', '14:05')
.typeText('input[name="duration"]', '01:00:00')
.typeText('input[name="distance"]', '10')
.click(Selector('input[type="submit"]'))
await t
.expect(Selector('H1').withText('Dashboard').exists).notOk()
.expect(Selector('H1').withText('Activity').exists).ok()
.expect(Selector('.card-header').withText('Cycling (Sport)').exists).ok()
})

View File

@ -11,7 +11,7 @@ export const addActivity = form => dispatch => mpwoApi
.addActivity(form) .addActivity(form)
.then(ret => { .then(ret => {
if (ret.status === 'created') { if (ret.status === 'created') {
history.push('/') history.push(`/activities/${ret.data.activities[0].id}`)
} else { } else {
dispatch(setError(`activities: ${ret.message}`)) dispatch(setError(`activities: ${ret.message}`))
} }
@ -23,7 +23,7 @@ export const addActivityWithoutGpx = form => dispatch => mpwoApi
.addActivityWithoutGpx(form) .addActivityWithoutGpx(form)
.then(ret => { .then(ret => {
if (ret.status === 'created') { if (ret.status === 'created') {
history.push('/') history.push(`/activities/${ret.data.activities[0].id}`)
} else { } else {
dispatch(setError(`activities: ${ret.message}`)) dispatch(setError(`activities: ${ret.message}`))
} }