Skip to content

Commit bd4afbc

Browse files
Add validation test
1 parent f272e5c commit bd4afbc

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

test/js/reducers/questionnaire.spec.js

+52-7
Original file line numberDiff line numberDiff line change
@@ -1226,19 +1226,48 @@ describe('questionnaire reducer', () => {
12261226
})
12271227
})
12281228

1229-
it('should validate mobileweb message must not be blank if mobileweb mode is on', () => {
1229+
it('should validate SMS parts messages must not be blank if "SMS" mode is on and there are SMS parts', () => {
12301230
const resultState = playActions([
12311231
actions.fetch(1, 1),
12321232
actions.receive(questionnaire),
1233-
actions.addMode('mobileweb'),
1234-
actions.changeStepPromptMobileWeb('17141bea-a81c-4227-bdda-f5f69188b0e7', '')
1233+
actions.removeMode('ivr'),
1234+
actions.addLanguage('es'),
1235+
// Two empty sms parts (empty before and after split separator)
1236+
actions.changeStepPromptSms('17141bea-a81c-4227-bdda-f5f69188b0e7', `${smsSplitSeparator}` ),
1237+
actions.setActiveLanguage('es'),
1238+
// One empty sms parts (empty after split separator)
1239+
actions.changeStepPromptSms('17141bea-a81c-4227-bdda-f5f69188b0e7', `Hola!${smsSplitSeparator} `),
12351240
])
12361241

1237-
expect(resultState.errors).toInclude({
1238-
path: "steps[0].prompt['en'].mobileweb",
1242+
const errors = resultState.errors
1243+
expect(errors).toInclude({
1244+
path: "steps[1].prompt['en'].sms",
12391245
lang: 'en',
1240-
mode: 'mobileweb',
1241-
message: ['Mobile web prompt must not be blank']
1246+
mode: 'sms',
1247+
message: ['[0]SMS prompt must not be blank']
1248+
})
1249+
expect(errors).toInclude({
1250+
path: "steps[1].prompt['en'].sms",
1251+
lang: 'en',
1252+
mode: 'sms',
1253+
message: ['[1]SMS prompt must not be blank']
1254+
})
1255+
1256+
expect(errors).toInclude({
1257+
path: "steps[1].prompt['es'].sms",
1258+
lang: 'es',
1259+
mode: 'sms',
1260+
message: ['[1]SMS prompt must not be blank']
1261+
})
1262+
1263+
expect(resultState.errorsByPath).toInclude({
1264+
"steps[1].prompt['en'].sms": [['[0]SMS prompt must not be blank'], ['[1]SMS prompt must not be blank']],
1265+
"steps[1].prompt['es'].sms": [['[1]SMS prompt must not be blank']]
1266+
})
1267+
1268+
expect(resultState.errorsByLang).toInclude({
1269+
'en': true,
1270+
'es': true,
12421271
})
12431272
})
12441273

@@ -1288,6 +1317,22 @@ describe('questionnaire reducer', () => {
12881317
})
12891318
})
12901319

1320+
it('should validate mobileweb message must not be blank if mobileweb mode is on', () => {
1321+
const resultState = playActions([
1322+
actions.fetch(1, 1),
1323+
actions.receive(questionnaire),
1324+
actions.addMode('mobileweb'),
1325+
actions.changeStepPromptMobileWeb('17141bea-a81c-4227-bdda-f5f69188b0e7', '')
1326+
])
1327+
1328+
expect(resultState.errors).toInclude({
1329+
path: "steps[0].prompt['en'].mobileweb",
1330+
lang: 'en',
1331+
mode: 'mobileweb',
1332+
message: ['Mobile web prompt must not be blank']
1333+
})
1334+
})
1335+
12911336
it('should not include an error if mobile web sms message prompt exceeds the character limit', () => {
12921337
const prompt = 'a'.repeat(141)
12931338

0 commit comments

Comments
 (0)