@@ -15,6 +15,7 @@ import pagePollParticipation from 'croodle/tests/pages/poll/participation';
15
15
const { run } = Ember ;
16
16
17
17
let application , server ;
18
+ let serverAvailable = true ;
18
19
19
20
const randomString = function ( length ) {
20
21
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', {
34
35
35
36
server . post ( '/polls' ,
36
37
function ( request ) {
38
+ if ( ! serverAvailable ) {
39
+ return [ 503 ] ;
40
+ }
41
+
37
42
let ret = serverPostPolls ( request . requestBody , pollId ) ;
38
43
lastCreatedPoll = ret [ 2 ] ;
39
44
return ret ;
@@ -42,6 +47,10 @@ module('Acceptance | create a poll', {
42
47
43
48
server . get ( `/polls/${ pollId } ` ,
44
49
function ( ) {
50
+ if ( ! serverAvailable ) {
51
+ return [ 503 ] ;
52
+ }
53
+
45
54
return [
46
55
200 ,
47
56
{ 'Content-Type' : 'application/json' } ,
@@ -177,46 +186,57 @@ test('create a default poll', function(assert) {
177
186
'available answers selection has autofocus'
178
187
) ;
179
188
189
+ // simulate temporate server error
190
+ serverAvailable = false ;
180
191
pageCreateSettings
181
192
. save ( ) ;
182
193
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
+ } ) ;
220
240
} ) ;
221
241
} ) ;
222
242
} ) ;
0 commit comments