diff --git a/mpwo_client/e2e/activities.test.js b/mpwo_client/e2e/activities.test.js new file mode 100644 index 00000000..08074827 --- /dev/null +++ b/mpwo_client/e2e/activities.test.js @@ -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() +}) + diff --git a/mpwo_client/src/actions/activities.js b/mpwo_client/src/actions/activities.js index b05ebdbf..d3c0d93a 100644 --- a/mpwo_client/src/actions/activities.js +++ b/mpwo_client/src/actions/activities.js @@ -11,7 +11,7 @@ export const addActivity = form => dispatch => mpwoApi .addActivity(form) .then(ret => { if (ret.status === 'created') { - history.push('/') + history.push(`/activities/${ret.data.activities[0].id}`) } else { dispatch(setError(`activities: ${ret.message}`)) } @@ -23,7 +23,7 @@ export const addActivityWithoutGpx = form => dispatch => mpwoApi .addActivityWithoutGpx(form) .then(ret => { if (ret.status === 'created') { - history.push('/') + history.push(`/activities/${ret.data.activities[0].id}`) } else { dispatch(setError(`activities: ${ret.message}`)) }