add a test for saving a new poll fails due to server

This commit is contained in:
jelhan 2016-08-26 19:04:50 +02:00
parent 6852d6ce27
commit 9b221e7861
2 changed files with 68 additions and 43 deletions

View file

@ -59,13 +59,18 @@ export default Controller.extend(Validations, {
} }
// save poll // save poll
model.save().then((model) => { model.save()
// reload as workaround for bug: duplicated records after save .then((model) => {
model.reload().then((model) => { // reload as workaround for bug: duplicated records after save
// redirect to new poll model.reload().then((model) => {
this.get('target').send('transitionToPoll', model); // redirect to new poll
this.get('target').send('transitionToPoll', model);
});
})
.catch(() => {
// ToDo: Show feedback to user
return;
}); });
});
} }
} }
}, },

View file

@ -15,6 +15,7 @@ import pagePollParticipation from 'croodle/tests/pages/poll/participation';
const { run } = Ember; const { run } = Ember;
let application, server; let application, server;
let serverAvailable = true;
const randomString = function(length) { const randomString = function(length) {
return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1); return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
@ -34,6 +35,10 @@ module('Acceptance | create a poll', {
server.post('/polls', server.post('/polls',
function(request) { function(request) {
if (!serverAvailable) {
return [503];
}
let ret = serverPostPolls(request.requestBody, pollId); let ret = serverPostPolls(request.requestBody, pollId);
lastCreatedPoll = ret[2]; lastCreatedPoll = ret[2];
return ret; return ret;
@ -42,6 +47,10 @@ module('Acceptance | create a poll', {
server.get(`/polls/${pollId}`, server.get(`/polls/${pollId}`,
function() { function() {
if (!serverAvailable) {
return [503];
}
return [ return [
200, 200,
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
@ -177,46 +186,57 @@ test('create a default poll', function(assert) {
'available answers selection has autofocus' 'available answers selection has autofocus'
); );
// simulate temporate server error
serverAvailable = false;
pageCreateSettings pageCreateSettings
.save(); .save();
andThen(function() { andThen(() => {
assert.equal(currentPath(), 'poll.participation'); assert.equal(currentPath(), 'create.settings');
assert.ok(
pagePollParticipation.urlIsValid() === true, serverAvailable = true;
`poll url ${currentURL()} is valid`
); pageCreateSettings
assert.equal( .save();
pagePollParticipation.title,
'default poll', andThen(function() {
'poll title is correct' assert.equal(currentPath(), 'poll.participation');
); assert.ok(
assert.equal( pagePollParticipation.urlIsValid() === true,
pagePollParticipation.description, `poll url ${currentURL()} is valid`
'', );
'poll description is correct' assert.equal(
); pagePollParticipation.title,
const dayFormat = moment.localeData().longDateFormat('LLLL') 'default poll',
.replace( 'poll title is correct'
moment.localeData().longDateFormat('LT'), '') );
.trim(); assert.equal(
assert.deepEqual( pagePollParticipation.description,
pagePollParticipation.options().labels, '',
dates.map((date) => date.format(dayFormat)), 'poll description is correct'
'options are correctly labeled' );
); const dayFormat = moment.localeData().longDateFormat('LLLL')
assert.deepEqual( .replace(
pagePollParticipation.options().answers, moment.localeData().longDateFormat('LT'), '')
[ .trim();
t('answerTypes.yes.label').toString(), assert.deepEqual(
t('answerTypes.no.label').toString() pagePollParticipation.options().labels,
], dates.map((date) => date.format(dayFormat)),
'answers are correctly labeled' 'options are correctly labeled'
); );
assert.ok( assert.deepEqual(
pagePollParticipation.nameHasFocus, pagePollParticipation.options().answers,
'name input has autofocus' [
); t('answerTypes.yes.label').toString(),
t('answerTypes.no.label').toString()
],
'answers are correctly labeled'
);
assert.ok(
pagePollParticipation.nameHasFocus,
'name input has autofocus'
);
});
}); });
}); });
}); });