Skip to content

Commit

Permalink
Add system test to test form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
myabc committed Dec 19, 2024
1 parent d605b29 commit 59fef6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ def playground(
end

# @label With form
def with_form
render(Primer::OpenProject::DangerConfirmationDialog.new(form_arguments: {
method: :post,
action: "/my-controller/my-action",
novalidate: true
})) do |dialog|
def with_form(route_format: :html)
render(Primer::OpenProject::DangerConfirmationDialog.new(
title: "Delete dialog",
form_arguments: {
method: :post,
action: generic_form_submission_path(format: route_format),
novalidate: true
}
)) do |dialog|
dialog.with_show_button { "Click me" }
dialog.with_confirmation_message do |message|
message.with_heading(tag: :h2).with_content("Permanently delete?")
Expand Down
15 changes: 15 additions & 0 deletions test/system/open_project/danger_confirmation_dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ def test_submit_button_enabled_when_confirmation_check_box_checked
assert_selector("button[data-submit-dialog-id]:enabled")
end
end

def test_submit_button_submits_form
visit_preview(:with_form, route_format: :json)

click_button("Click me")

assert_selector(".DangerConfirmationDialog") do
check("I understand that this deletion cannot be reversed")
find("button[type='submit']").click

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

0 comments on commit 59fef6e

Please sign in to comment.