@@ -7,6 +7,7 @@ class IntegrationActionMenuTest < System::TestCase
7
7
include Primer ::ClipboardTestHelpers
8
8
include Primer ::JsTestHelpers
9
9
include Primer ::KeyboardTestHelpers
10
+ include Primer ::JsonResponseTestHelpers
10
11
11
12
###### HELPER METHODS ######
12
13
@@ -409,9 +410,8 @@ def test_single_select_form_submission
409
410
410
411
find ( "input[type=submit]" ) . click
411
412
412
- # for some reason the JSON response is wrapped in HTML, I have no idea why
413
- response = JSON . parse ( find ( "pre" ) . text )
414
- assert_equal "fast_forward" , response [ "value" ]
413
+ assert_json_response
414
+ assert_equal "fast_forward" , json_response [ "value" ]
415
415
end
416
416
417
417
def test_single_select_form_uses_label_if_no_value_provided
@@ -422,9 +422,8 @@ def test_single_select_form_uses_label_if_no_value_provided
422
422
423
423
find ( "input[type=submit]" ) . click
424
424
425
- # for some reason the JSON response is wrapped in HTML, I have no idea why
426
- response = JSON . parse ( find ( "pre" ) . text )
427
- assert_equal "Resolve" , response [ "value" ]
425
+ assert_json_response
426
+ assert_equal "Resolve" , json_response [ "value" ]
428
427
end
429
428
430
429
def test_multiple_select_form_submission
@@ -439,11 +438,10 @@ def test_multiple_select_form_submission
439
438
440
439
find ( "input[type=submit]" ) . click
441
440
442
- # for some reason the JSON response is wrapped in HTML, I have no idea why
443
- response = JSON . parse ( find ( "pre" ) . text )
441
+ assert_json_response
444
442
445
443
# "ours" is pre-selected
446
- assert_equal %w[ fast_forward recursive ours ] , response [ "value" ]
444
+ assert_equal %w[ fast_forward recursive ours ] , json_response [ "value" ]
447
445
end
448
446
449
447
def test_multiple_select_form_uses_label_if_no_value_provided
@@ -458,11 +456,10 @@ def test_multiple_select_form_uses_label_if_no_value_provided
458
456
459
457
find ( "input[type=submit]" ) . click
460
458
461
- # for some reason the JSON response is wrapped in HTML, I have no idea why
462
- response = JSON . parse ( find ( "pre" ) . text )
459
+ assert_json_response
463
460
464
461
# "ours" is pre-selected
465
- assert_equal %w[ fast_forward ours Resolve ] , response [ "value" ]
462
+ assert_equal %w[ fast_forward ours Resolve ] , json_response [ "value" ]
466
463
end
467
464
468
465
def test_multiple_select_does_not_set_dynamic_label_for_preselected_item
@@ -476,8 +473,8 @@ def test_individual_items_can_submit_post_requests_via_forms
476
473
click_on_invoker_button
477
474
click_on_fourth_item
478
475
479
- response = JSON . parse ( find ( "pre" ) . text )
480
- assert_equal "bar" , response [ "value" ]
476
+ assert_json_response
477
+ assert_equal "bar" , json_response [ "value" ]
481
478
end
482
479
483
480
def test_single_select_items_can_submit_forms
@@ -486,9 +483,8 @@ def test_single_select_items_can_submit_forms
486
483
click_on_invoker_button
487
484
click_on_first_item
488
485
489
- # for some reason the JSON response is wrapped in HTML, I have no idea why
490
- response = JSON . parse ( find ( "pre" ) . text )
491
- assert_equal "group-by-repository" , response [ "value" ]
486
+ assert_json_response
487
+ assert_equal "group-by-repository" , json_response [ "value" ]
492
488
end
493
489
494
490
def test_single_select_items_can_submit_forms_on_enter
@@ -499,9 +495,8 @@ def test_single_select_items_can_submit_forms_on_enter
499
495
# "click" first item
500
496
keyboard . type ( :enter )
501
497
502
- # for some reason the JSON response is wrapped in HTML, I have no idea why
503
- response = JSON . parse ( find ( "pre" ) . text )
504
- assert_equal "group-by-repository" , response [ "value" ]
498
+ assert_json_response
499
+ assert_equal "group-by-repository" , json_response [ "value" ]
505
500
end
506
501
507
502
def test_single_select_items_can_submit_forms_on_keydown_space
@@ -512,9 +507,8 @@ def test_single_select_items_can_submit_forms_on_keydown_space
512
507
# "click" first item
513
508
keyboard . type ( :space )
514
509
515
- # for some reason the JSON response is wrapped in HTML, I have no idea why
516
- response = JSON . parse ( find ( "pre" ) . text )
517
- assert_equal "group-by-repository" , response [ "value" ]
510
+ assert_json_response
511
+ assert_equal "group-by-repository" , json_response [ "value" ]
518
512
end
519
513
520
514
def test_single_select_items_can_submit_forms_with_multiple_fields
@@ -523,9 +517,8 @@ def test_single_select_items_can_submit_forms_with_multiple_fields
523
517
click_on_invoker_button
524
518
click_on_first_item
525
519
526
- # for some reason the JSON response is wrapped in HTML, I have no idea why
527
- response = JSON . parse ( find ( "pre" ) . text )
528
- assert_equal "query" , response . dig ( "other_params" , "query" )
520
+ assert_json_response
521
+ assert_equal "query" , json_response . dig ( "other_params" , "query" )
529
522
end
530
523
531
524
def test_deferred_loading
0 commit comments