Skip to content

Commit

Permalink
Try to handle browser JSON responses more robustly
Browse files Browse the repository at this point in the history
Sticking to Capybara's API for getting document text should (in theory)
make this less likely to break in the event of a browser changing how it
renders plain text/JSON responses.

[skip changeset]
  • Loading branch information
myabc committed Feb 2, 2025
1 parent 7fbd8da commit e37f0bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
26 changes: 9 additions & 17 deletions test/system/alpha/action_menu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ def test_single_select_form_submission

find("input[type=submit]").click

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "fast_forward", response["value"]
end

Expand All @@ -417,8 +416,7 @@ def test_single_select_form_uses_label_if_no_value_provided

find("input[type=submit]").click

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "Resolve", response["value"]
end

Expand All @@ -434,8 +432,7 @@ def test_multiple_select_form_submission

find("input[type=submit]").click

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)

# "ours" is pre-selected
assert_equal %w[fast_forward recursive ours], response["value"]
Expand All @@ -453,8 +450,7 @@ def test_multiple_select_form_uses_label_if_no_value_provided

find("input[type=submit]").click

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)

# "ours" is pre-selected
assert_equal %w[fast_forward ours Resolve], response["value"]
Expand All @@ -471,7 +467,7 @@ def test_individual_items_can_submit_post_requests_via_forms
click_on_invoker_button
click_on_fourth_item

response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "bar", response["value"]
end

Expand All @@ -481,8 +477,7 @@ def test_single_select_items_can_submit_forms
click_on_invoker_button
click_on_first_item

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "group-by-repository", response["value"]
end

Expand All @@ -494,8 +489,7 @@ def test_single_select_items_can_submit_forms_on_enter
# "click" first item
keyboard.type(:enter)

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "group-by-repository", response["value"]
end

Expand All @@ -507,8 +501,7 @@ def test_single_select_items_can_submit_forms_on_keydown_space
# "click" first item
keyboard.type(:space)

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "group-by-repository", response["value"]
end

Expand All @@ -518,8 +511,7 @@ def test_single_select_items_can_submit_forms_with_multiple_fields
click_on_invoker_button
click_on_first_item

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "query", response.dig("other_params", "query")
end

Expand Down
9 changes: 3 additions & 6 deletions test/system/alpha/select_panel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,7 @@ def test_single_select_form

click_on "Submit"

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "item2", response.dig(*%w(form_params item))
end

Expand All @@ -1232,8 +1231,7 @@ def test_single_select_form_submits_pre_selected_item
# the first item has been pre-selected, so there's no need to select any items
click_on "Submit"

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)
assert_equal "item1", response.dig(*%w(form_params item))
end

Expand All @@ -1246,8 +1244,7 @@ def test_multi_select_form

click_on "Submit"

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
response = JSON.parse(page.document.text)

# first item is pre-selected
assert_equal ["item1", "item2"], response.dig(*%w(form_params item))
Expand Down

0 comments on commit e37f0bc

Please sign in to comment.