Skip to content

Commit 9b221e7

Browse files
committed
add a test for saving a new poll fails due to server
1 parent 6852d6c commit 9b221e7

File tree

2 files changed

+68
-43
lines changed

2 files changed

+68
-43
lines changed

app/controllers/create/settings.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ export default Controller.extend(Validations, {
5959
}
6060

6161
// save poll
62-
model.save().then((model) => {
63-
// reload as workaround for bug: duplicated records after save
64-
model.reload().then((model) => {
65-
// redirect to new poll
66-
this.get('target').send('transitionToPoll', model);
62+
model.save()
63+
.then((model) => {
64+
// reload as workaround for bug: duplicated records after save
65+
model.reload().then((model) => {
66+
// redirect to new poll
67+
this.get('target').send('transitionToPoll', model);
68+
});
69+
})
70+
.catch(() => {
71+
// ToDo: Show feedback to user
72+
return;
6773
});
68-
});
6974
}
7075
}
7176
},

tests/acceptance/create-a-poll-test.js

+57-37
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import pagePollParticipation from 'croodle/tests/pages/poll/participation';
1515
const { run } = Ember;
1616

1717
let application, server;
18+
let serverAvailable = true;
1819

1920
const randomString = function(length) {
2021
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', {
3435

3536
server.post('/polls',
3637
function(request) {
38+
if (!serverAvailable) {
39+
return [503];
40+
}
41+
3742
let ret = serverPostPolls(request.requestBody, pollId);
3843
lastCreatedPoll = ret[2];
3944
return ret;
@@ -42,6 +47,10 @@ module('Acceptance | create a poll', {
4247

4348
server.get(`/polls/${pollId}`,
4449
function() {
50+
if (!serverAvailable) {
51+
return [503];
52+
}
53+
4554
return [
4655
200,
4756
{ 'Content-Type': 'application/json' },
@@ -177,46 +186,57 @@ test('create a default poll', function(assert) {
177186
'available answers selection has autofocus'
178187
);
179188

189+
// simulate temporate server error
190+
serverAvailable = false;
180191
pageCreateSettings
181192
.save();
182193

183-
andThen(function() {
184-
assert.equal(currentPath(), 'poll.participation');
185-
assert.ok(
186-
pagePollParticipation.urlIsValid() === true,
187-
`poll url ${currentURL()} is valid`
188-
);
189-
assert.equal(
190-
pagePollParticipation.title,
191-
'default poll',
192-
'poll title is correct'
193-
);
194-
assert.equal(
195-
pagePollParticipation.description,
196-
'',
197-
'poll description is correct'
198-
);
199-
const dayFormat = moment.localeData().longDateFormat('LLLL')
200-
.replace(
201-
moment.localeData().longDateFormat('LT'), '')
202-
.trim();
203-
assert.deepEqual(
204-
pagePollParticipation.options().labels,
205-
dates.map((date) => date.format(dayFormat)),
206-
'options are correctly labeled'
207-
);
208-
assert.deepEqual(
209-
pagePollParticipation.options().answers,
210-
[
211-
t('answerTypes.yes.label').toString(),
212-
t('answerTypes.no.label').toString()
213-
],
214-
'answers are correctly labeled'
215-
);
216-
assert.ok(
217-
pagePollParticipation.nameHasFocus,
218-
'name input has autofocus'
219-
);
194+
andThen(() => {
195+
assert.equal(currentPath(), 'create.settings');
196+
197+
serverAvailable = true;
198+
199+
pageCreateSettings
200+
.save();
201+
202+
andThen(function() {
203+
assert.equal(currentPath(), 'poll.participation');
204+
assert.ok(
205+
pagePollParticipation.urlIsValid() === true,
206+
`poll url ${currentURL()} is valid`
207+
);
208+
assert.equal(
209+
pagePollParticipation.title,
210+
'default poll',
211+
'poll title is correct'
212+
);
213+
assert.equal(
214+
pagePollParticipation.description,
215+
'',
216+
'poll description is correct'
217+
);
218+
const dayFormat = moment.localeData().longDateFormat('LLLL')
219+
.replace(
220+
moment.localeData().longDateFormat('LT'), '')
221+
.trim();
222+
assert.deepEqual(
223+
pagePollParticipation.options().labels,
224+
dates.map((date) => date.format(dayFormat)),
225+
'options are correctly labeled'
226+
);
227+
assert.deepEqual(
228+
pagePollParticipation.options().answers,
229+
[
230+
t('answerTypes.yes.label').toString(),
231+
t('answerTypes.no.label').toString()
232+
],
233+
'answers are correctly labeled'
234+
);
235+
assert.ok(
236+
pagePollParticipation.nameHasFocus,
237+
'name input has autofocus'
238+
);
239+
});
220240
});
221241
});
222242
});

0 commit comments

Comments
 (0)