1
1
/// <reference lib="dom" />
2
2
3
3
import { SURVEYS_REQUEST_TIMEOUT_MS } from '../constants'
4
- import { generateSurveys } from '../extensions/surveys'
4
+ import { generateSurveys , getNextSurveyStep } from '../extensions/surveys'
5
5
import {
6
6
canActivateRepeatedly ,
7
7
getDisplayOrderChoices ,
@@ -927,8 +927,8 @@ describe('surveys', () => {
927
927
{ type : SurveyQuestionType . Open , question : 'Question A' } ,
928
928
{ type : SurveyQuestionType . Open , question : 'Question B' } ,
929
929
] as SurveyQuestion [ ]
930
- expect ( surveys . getNextSurveyStep ( survey , 0 , 'Some response' ) ) . toEqual ( 1 )
931
- expect ( surveys . getNextSurveyStep ( survey , 1 , 'Some response' ) ) . toEqual ( SurveyQuestionBranchingType . End )
930
+ expect ( getNextSurveyStep ( survey , 0 , 'Some response' ) ) . toEqual ( 1 )
931
+ expect ( getNextSurveyStep ( survey , 1 , 'Some response' ) ) . toEqual ( SurveyQuestionBranchingType . End )
932
932
} )
933
933
934
934
it ( 'should branch out to `end`' , ( ) => {
@@ -940,7 +940,7 @@ describe('surveys', () => {
940
940
} ,
941
941
{ type : SurveyQuestionType . Open , question : 'Question B' } ,
942
942
] as SurveyQuestion [ ]
943
- expect ( surveys . getNextSurveyStep ( survey , 0 , 'Some response' ) ) . toEqual ( SurveyQuestionBranchingType . End )
943
+ expect ( getNextSurveyStep ( survey , 0 , 'Some response' ) ) . toEqual ( SurveyQuestionBranchingType . End )
944
944
} )
945
945
946
946
it ( 'should branch out to a specific question' , ( ) => {
@@ -953,7 +953,7 @@ describe('surveys', () => {
953
953
{ type : SurveyQuestionType . Open , question : 'Question B' } ,
954
954
{ type : SurveyQuestionType . Open , question : 'Question C' } ,
955
955
] as SurveyQuestion [ ]
956
- expect ( surveys . getNextSurveyStep ( survey , 0 , 'Some response' ) ) . toEqual ( 2 )
956
+ expect ( getNextSurveyStep ( survey , 0 , 'Some response' ) ) . toEqual ( 2 )
957
957
} )
958
958
959
959
// Single-choice
@@ -973,9 +973,9 @@ describe('surveys', () => {
973
973
{ type : SurveyQuestionType . Open , question : 'Why no?' } ,
974
974
{ type : SurveyQuestionType . Open , question : 'Why maybe?' } ,
975
975
] as unknown [ ] as SurveyQuestion [ ]
976
- expect ( surveys . getNextSurveyStep ( survey , 0 , 'Yes' ) ) . toEqual ( 1 )
977
- expect ( surveys . getNextSurveyStep ( survey , 0 , 'No' ) ) . toEqual ( 2 )
978
- expect ( surveys . getNextSurveyStep ( survey , 0 , 'Maybe' ) ) . toEqual ( 3 )
976
+ expect ( getNextSurveyStep ( survey , 0 , 'Yes' ) ) . toEqual ( 1 )
977
+ expect ( getNextSurveyStep ( survey , 0 , 'No' ) ) . toEqual ( 2 )
978
+ expect ( getNextSurveyStep ( survey , 0 , 'Maybe' ) ) . toEqual ( 3 )
979
979
} )
980
980
981
981
// Response-based branching, scale 1-3
@@ -995,9 +995,9 @@ describe('surveys', () => {
995
995
{ type : SurveyQuestionType . Open , question : 'Glad to hear that. Tell us more!' } ,
996
996
] as unknown [ ] as SurveyQuestion [ ]
997
997
998
- expect ( surveys . getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
999
- expect ( surveys . getNextSurveyStep ( survey , 0 , 2 ) ) . toEqual ( 2 )
1000
- expect ( surveys . getNextSurveyStep ( survey , 0 , 3 ) ) . toEqual ( 3 )
998
+ expect ( getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
999
+ expect ( getNextSurveyStep ( survey , 0 , 2 ) ) . toEqual ( 2 )
1000
+ expect ( getNextSurveyStep ( survey , 0 , 3 ) ) . toEqual ( 3 )
1001
1001
} )
1002
1002
1003
1003
// Response-based branching, scale 1-5
@@ -1017,9 +1017,9 @@ describe('surveys', () => {
1017
1017
{ type : SurveyQuestionType . Open , question : 'Glad to hear that. Tell us more!' } ,
1018
1018
] as unknown as SurveyQuestion [ ]
1019
1019
1020
- expect ( surveys . getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
1021
- expect ( surveys . getNextSurveyStep ( survey , 0 , 3 ) ) . toEqual ( 2 )
1022
- expect ( surveys . getNextSurveyStep ( survey , 0 , 5 ) ) . toEqual ( 3 )
1020
+ expect ( getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
1021
+ expect ( getNextSurveyStep ( survey , 0 , 3 ) ) . toEqual ( 2 )
1022
+ expect ( getNextSurveyStep ( survey , 0 , 5 ) ) . toEqual ( 3 )
1023
1023
} )
1024
1024
1025
1025
// Response-based branching, scale 1-7
@@ -1039,13 +1039,13 @@ describe('surveys', () => {
1039
1039
{ type : SurveyQuestionType . Open , question : 'Great! What did you enjoy the most?' } ,
1040
1040
] as unknown as SurveyQuestion [ ]
1041
1041
1042
- expect ( surveys . getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
1043
- expect ( surveys . getNextSurveyStep ( survey , 0 , 2 ) ) . toEqual ( 1 )
1044
- expect ( surveys . getNextSurveyStep ( survey , 0 , 3 ) ) . toEqual ( 1 )
1045
- expect ( surveys . getNextSurveyStep ( survey , 0 , 4 ) ) . toEqual ( 2 )
1046
- expect ( surveys . getNextSurveyStep ( survey , 0 , 5 ) ) . toEqual ( 3 )
1047
- expect ( surveys . getNextSurveyStep ( survey , 0 , 6 ) ) . toEqual ( 3 )
1048
- expect ( surveys . getNextSurveyStep ( survey , 0 , 7 ) ) . toEqual ( 3 )
1042
+ expect ( getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
1043
+ expect ( getNextSurveyStep ( survey , 0 , 2 ) ) . toEqual ( 1 )
1044
+ expect ( getNextSurveyStep ( survey , 0 , 3 ) ) . toEqual ( 1 )
1045
+ expect ( getNextSurveyStep ( survey , 0 , 4 ) ) . toEqual ( 2 )
1046
+ expect ( getNextSurveyStep ( survey , 0 , 5 ) ) . toEqual ( 3 )
1047
+ expect ( getNextSurveyStep ( survey , 0 , 6 ) ) . toEqual ( 3 )
1048
+ expect ( getNextSurveyStep ( survey , 0 , 7 ) ) . toEqual ( 3 )
1049
1049
} )
1050
1050
1051
1051
// Response-based branching, scale 0-10 (NPS)
@@ -1065,9 +1065,9 @@ describe('surveys', () => {
1065
1065
{ type : SurveyQuestionType . Open , question : 'Glad to hear that. Tell us more!' } ,
1066
1066
] as unknown as SurveyQuestion [ ]
1067
1067
1068
- expect ( surveys . getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
1069
- expect ( surveys . getNextSurveyStep ( survey , 0 , 8 ) ) . toEqual ( 2 )
1070
- expect ( surveys . getNextSurveyStep ( survey , 0 , 10 ) ) . toEqual ( 3 )
1068
+ expect ( getNextSurveyStep ( survey , 0 , 1 ) ) . toEqual ( 1 )
1069
+ expect ( getNextSurveyStep ( survey , 0 , 8 ) ) . toEqual ( 2 )
1070
+ expect ( getNextSurveyStep ( survey , 0 , 10 ) ) . toEqual ( 3 )
1071
1071
} )
1072
1072
1073
1073
it ( 'should display questions in the order AGCEHDFB' , ( ) => {
@@ -1121,7 +1121,7 @@ describe('surveys', () => {
1121
1121
for ( let i = 0 ; i < survey . questions . length ; i ++ ) {
1122
1122
const currentQuestion = survey . questions [ currentStep ]
1123
1123
actualOrder . push ( currentQuestion . question )
1124
- currentStep = surveys . getNextSurveyStep ( survey , currentStep , 'Some response' )
1124
+ currentStep = getNextSurveyStep ( survey , currentStep , 'Some response' )
1125
1125
}
1126
1126
1127
1127
expect ( desiredOrder ) . toEqual ( actualOrder )
@@ -1180,7 +1180,7 @@ describe('surveys', () => {
1180
1180
for ( const answer of answers ) {
1181
1181
const currentQuestion = survey . questions [ currentStep ]
1182
1182
actualOrder . push ( currentQuestion . question )
1183
- currentStep = surveys . getNextSurveyStep ( survey , currentStep , answer )
1183
+ currentStep = getNextSurveyStep ( survey , currentStep , answer )
1184
1184
}
1185
1185
expect ( desiredOrder ) . toEqual ( actualOrder )
1186
1186
expect ( currentStep ) . toEqual ( SurveyQuestionBranchingType . End )
@@ -1193,7 +1193,7 @@ describe('surveys', () => {
1193
1193
for ( const answer of answers ) {
1194
1194
const currentQuestion = survey . questions [ currentStep ]
1195
1195
actualOrder . push ( currentQuestion . question )
1196
- currentStep = surveys . getNextSurveyStep ( survey , currentStep , answer )
1196
+ currentStep = getNextSurveyStep ( survey , currentStep , answer )
1197
1197
}
1198
1198
expect ( desiredOrder ) . toEqual ( actualOrder )
1199
1199
expect ( currentStep ) . toEqual ( SurveyQuestionBranchingType . End )
@@ -1206,7 +1206,7 @@ describe('surveys', () => {
1206
1206
for ( const answer of answers ) {
1207
1207
const currentQuestion = survey . questions [ currentStep ]
1208
1208
actualOrder . push ( currentQuestion . question )
1209
- currentStep = surveys . getNextSurveyStep ( survey , currentStep , answer )
1209
+ currentStep = getNextSurveyStep ( survey , currentStep , answer )
1210
1210
}
1211
1211
expect ( desiredOrder ) . toEqual ( actualOrder )
1212
1212
expect ( currentStep ) . toEqual ( SurveyQuestionBranchingType . End )
@@ -1223,7 +1223,7 @@ describe('surveys', () => {
1223
1223
for ( const answer of answers ) {
1224
1224
const currentQuestion = survey . questions [ currentStep ]
1225
1225
actualOrder . push ( currentQuestion . question )
1226
- currentStep = surveys . getNextSurveyStep ( survey , currentStep , answer )
1226
+ currentStep = getNextSurveyStep ( survey , currentStep , answer )
1227
1227
}
1228
1228
expect ( desiredOrder ) . toEqual ( actualOrder )
1229
1229
expect ( currentStep ) . toEqual ( SurveyQuestionBranchingType . End )
@@ -1244,7 +1244,7 @@ describe('surveys', () => {
1244
1244
{ type : SurveyQuestionType . Open , question : 'Seems you are not completely happy. Tell us more!' } ,
1245
1245
{ type : SurveyQuestionType . Open , question : 'Glad to hear that. Tell us more!' } ,
1246
1246
] as unknown as SurveyQuestion [ ]
1247
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , 1 ) ) . toThrow ( 'The scale must be one of: 3, 5, 7, 10' )
1247
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , 1 ) ) . toThrow ( 'The scale must be one of: 3, 5, 7, 10' )
1248
1248
} )
1249
1249
1250
1250
it ( 'should throw an error for a response value out of the valid range' , ( ) => {
@@ -1262,13 +1262,13 @@ describe('surveys', () => {
1262
1262
{ type : SurveyQuestionType . Open , question : 'Seems you are not completely happy. Tell us more!' } ,
1263
1263
{ type : SurveyQuestionType . Open , question : 'Glad to hear that. Tell us more!' } ,
1264
1264
] as unknown as SurveyQuestion [ ]
1265
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 1-3' )
1265
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 1-3' )
1266
1266
; ( survey . questions [ 0 ] as RatingSurveyQuestion ) . scale = 5
1267
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 1-5' )
1267
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 1-5' )
1268
1268
; ( survey . questions [ 0 ] as RatingSurveyQuestion ) . scale = 7
1269
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 1-7' )
1269
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 1-7' )
1270
1270
; ( survey . questions [ 0 ] as RatingSurveyQuestion ) . scale = 10
1271
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 0-10' )
1271
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , 20 ) ) . toThrow ( 'The response must be in range 0-10' )
1272
1272
} )
1273
1273
1274
1274
it ( 'should throw an error for if a response value in a rating question is not an integer' , ( ) => {
@@ -1286,10 +1286,8 @@ describe('surveys', () => {
1286
1286
{ type : SurveyQuestionType . Open , question : 'Seems you are not completely happy. Tell us more!' } ,
1287
1287
{ type : SurveyQuestionType . Open , question : 'Glad to hear that. Tell us more!' } ,
1288
1288
] as unknown as SurveyQuestion [ ]
1289
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , '2' ) ) . toThrow ( 'The response type must be an integer' )
1290
- expect ( ( ) => surveys . getNextSurveyStep ( survey , 0 , 'some_string' ) ) . toThrow (
1291
- 'The response type must be an integer'
1292
- )
1289
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , '2' ) ) . toThrow ( 'The response type must be an integer' )
1290
+ expect ( ( ) => getNextSurveyStep ( survey , 0 , 'some_string' ) ) . toThrow ( 'The response type must be an integer' )
1293
1291
} )
1294
1292
} )
1295
1293
0 commit comments