@@ -267,11 +267,8 @@ async def validator(prompt: PromptValidatorContext) -> bool:
267
267
dialogs .add (choice_prompt )
268
268
269
269
step1 = await adapter .send (Activity (type = ActivityTypes .message , text = "Hello" ))
270
- # TODO ChoiceFactory.inline() is broken, where it only uses hard-coded English locale.
271
- # commented out the CORRECT assertion below, until .inline() is fixed to use proper locale
272
- # step2 = await step1.assert_reply('Please choose a color. (1) red, (2) green, o (3) blue')
273
270
step2 = await step1 .assert_reply (
274
- "Please choose a color. (1) red, (2) green, or (3) blue"
271
+ "Please choose a color. (1) red, (2) green, o (3) blue"
275
272
)
276
273
step3 = await step2 .send (_invalid_message )
277
274
step4 = await step3 .assert_reply ("Bad input." )
@@ -318,11 +315,8 @@ async def validator(prompt: PromptValidatorContext) -> bool:
318
315
step1 = await adapter .send (
319
316
Activity (type = ActivityTypes .message , text = "Hello" , locale = Culture .Spanish )
320
317
)
321
- # TODO ChoiceFactory.inline() is broken, where it only uses hard-coded English locale.
322
- # commented out the CORRECT assertion below, until .inline() is fixed to use proper locale
323
- # step2 = await step1.assert_reply('Please choose a color. (1) red, (2) green, o (3) blue')
324
318
step2 = await step1 .assert_reply (
325
- "Please choose a color. (1) red, (2) green, or (3) blue"
319
+ "Please choose a color. (1) red, (2) green, o (3) blue"
326
320
)
327
321
step3 = await step2 .send (_answer_message )
328
322
await step3 .assert_reply ("red" )
@@ -377,9 +371,7 @@ async def validator(prompt: PromptValidatorContext) -> bool:
377
371
step3 = await step2 .send (_answer_message )
378
372
await step3 .assert_reply ("red" )
379
373
380
- async def test_should_not_render_choices_and_not_blow_up_if_choices_are_not_passed_in (
381
- self
382
- ):
374
+ async def test_should_not_render_choices_if_list_style_none_is_specified (self ):
383
375
async def exec_test (turn_context : TurnContext ):
384
376
dc = await dialogs .create_context (turn_context )
385
377
@@ -390,7 +382,8 @@ async def exec_test(turn_context: TurnContext):
390
382
prompt = Activity (
391
383
type = ActivityTypes .message , text = "Please choose a color."
392
384
),
393
- choices = None ,
385
+ choices = _color_choices ,
386
+ style = ListStyle .none ,
394
387
)
395
388
await dc .prompt ("prompt" , options )
396
389
elif results .status == DialogTurnStatus .Complete :
@@ -406,18 +399,15 @@ async def exec_test(turn_context: TurnContext):
406
399
dialogs = DialogSet (dialog_state )
407
400
408
401
choice_prompt = ChoicePrompt ("prompt" )
409
- choice_prompt .style = ListStyle .none
410
402
411
403
dialogs .add (choice_prompt )
412
404
413
405
step1 = await adapter .send ("Hello" )
414
- await step1 .assert_reply ("Please choose a color." )
406
+ step2 = await step1 .assert_reply ("Please choose a color." )
407
+ step3 = await step2 .send (_answer_message )
408
+ await step3 .assert_reply ("red" )
415
409
416
- # TODO to create parity with JS, need to refactor this so that it does not blow up when choices are None
417
- # Possibly does not work due to the side effect of list styles not applying
418
- # Note: step2 only appears to pass as ListStyle.none, probably because choices is None, and therefore appending
419
- # nothing to the prompt text
420
- async def test_should_not_recognize_if_choices_are_not_passed_in (self ):
410
+ async def test_should_create_prompt_with_inline_choices_when_specified (self ):
421
411
async def exec_test (turn_context : TurnContext ):
422
412
dc = await dialogs .create_context (turn_context )
423
413
@@ -428,7 +418,7 @@ async def exec_test(turn_context: TurnContext):
428
418
prompt = Activity (
429
419
type = ActivityTypes .message , text = "Please choose a color."
430
420
),
431
- choices = None ,
421
+ choices = _color_choices ,
432
422
)
433
423
await dc .prompt ("prompt" , options )
434
424
elif results .status == DialogTurnStatus .Complete :
@@ -444,17 +434,18 @@ async def exec_test(turn_context: TurnContext):
444
434
dialogs = DialogSet (dialog_state
1CF5
)
445
435
446
436
choice_prompt = ChoicePrompt ("prompt" )
447
- choice_prompt .style = ListStyle .none
437
+ choice_prompt .style = ListStyle .in_line
448
438
449
439
dialogs .add (choice_prompt )
450
440
451
441
step1 = await adapter .send ("Hello" )
452
- step2 = await step1 .assert_reply ("Please choose a color." )
453
- # TODO uncomment when styling is fixed for prompts - assertions should pass
454
- # step3 = await step2.send('hello')
455
- # await step3.assert_reply('Please choose a color.')
442
+ step2 = await step1 .assert_reply (
443
+ "Please choose a color. (1) red, (2) green, or (3) blue"
444
+ )
445
+ step3 = await step2 .send (_answer_message )
446
+ await step3 .assert_reply ("red" )
456
447
457
- async def test_should_create_prompt_with_inline_choices_when_specified (self ):
448
+ async def test_should_create_prompt_with_list_choices_when_specified (self ):
458
449
async def exec_test (turn_context : TurnContext ):
459
450
dc = await dialogs .create_context (turn_context )
460
451
@@ -481,20 +472,20 @@ async def exec_test(turn_context: TurnContext):
481
472
dialogs = DialogSet (dialog_state )
482
473
483
474
choice_prompt = ChoicePrompt ("prompt" )
484
- choice_prompt .style = ListStyle .in_line
475
+ choice_prompt .style = ListStyle .list_style
485
476
486
477
dialogs .add (choice_prompt )
487
478
488
479
step1 = await adapter .send ("Hello" )
489
480
step2 = await step1 .assert_reply (
490
- "Please choose a color. (1) red, (2) green, or (3) blue"
481
+ "Please choose a color.\n \n 1. red\n 2. green\n 3. blue"
491
482
)
492
483
step3 = await step2 .send (_answer_message )
493
484
await step3 .assert_reply ("red" )
494
485
495
- # TODO fix test to actually test for list_style instead of inline
496
- # currently bug where all styling is ignored and only does inline styling for prompts
497
- async def test_should_create_prompt_with_list_choices_when_specified ( self ):
486
+ async def test_should_create_prompt_with_suggested_action_style_when_specified (
487
+ self
488
+ ):
498
489
async def exec_test (turn_context : TurnContext ):
499
490
dc = await dialogs .create_context (turn_context )
500
491
@@ -506,6 +497,43 @@ async def exec_test(turn_context: TurnContext):
506
497
type = ActivityTypes .message , text = "Please choose a color."
507
498
),
508
499
choices = _color_choices ,
500
+ style = ListStyle .suggested_action ,
501
+ )
502
+ await dc .prompt ("prompt" , options )
503
+ elif results .status == DialogTurnStatus .Complete :
504
+ selected_choice = results .result
505
+ await turn_context .send_activity (selected_choice .value )
506
+
507
+ await convo_state .save_changes (turn_context )
508
+
509
+ adapter = TestAdapter (exec_test )
510
+
511
+ convo_state = ConversationState (MemoryStorage ())
512
+ dialog_state = convo_state .create_property ("dialogState" )
513
+ dialogs = DialogSet (dialog_state )
514
+
515
+ choice_prompt = ChoicePrompt ("prompt" )
516
+
517
+ dialogs .add (choice_prompt )
518
+
519
+ step1 = await adapter .send ("Hello" )
520
+ step2 = await step1 .assert_reply ("Please choose a color." )
521
+ step3 = await step2 .send (_answer_message )
522
+ await step3 .assert_reply ("red" )
523
+
524
+ async def test_should_create_prompt_with_auto_style_when_specified (self ):
525
+ async def exec_test (turn_context : TurnContext ):
526
+ dc = await dialogs .create_context (turn_context )
527
+
528
+ results : DialogTurnResult = await dc .continue_dialog ()
529
+
530
+ if results .status == DialogTurnStatus .Empty :
531
+ options = PromptOptions (
532
+ prompt = Activity (
533
+ type = ActivityTypes .message , text = "Please choose a color."
534
+ ),
535
+ choices = _color_choices ,
536
+ style = ListStyle .auto ,
509
537
)
510
538
await dc .prompt ("prompt" , options )
511
539
elif results .status == DialogTurnStatus .Complete :
@@ -521,14 +549,10 @@ async def exec_test(turn_context: TurnContext):
521
549
dialogs = DialogSet (dialog_state )
522
550
523
551
choice_prompt = ChoicePrompt ("prompt" )
524
- choice_prompt .style = ListStyle .list_style
525
552
526
553
dialogs .add (choice_prompt )
527
554
528
555
step1 = await adapter .send ("Hello" )
529
- # TODO uncomment assertion when prompt styling has been fixed - assertion should pass with list_style
530
- # Also be sure to remove inline assertion currently being tested below
531
- # step2 = await step1.assert_reply('Please choose a color.\n\n 1. red\n 2. green\n 3. blue')
532
556
step2 = await step1 .assert_reply (
533
557
"Please choose a color. (1) red, (2) green, or (3) blue"
534
558
)
0 commit comments