Skip to content

Commit

Permalink
Validate content block passed to ConfirmationCheckBox
Browse files Browse the repository at this point in the history
  • Loading branch information
myabc committed Dec 20, 2024
1 parent 8751daf commit 43e1243
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def call
render(Primer::Alpha::CheckBox.new(**@check_box_arguments.merge(label: trimmed_content)))
end
end

def render?
raise ArgumentError, "ConfirmationCheckBox requires a content block" unless trimmed_content.present?

true
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/components/component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PrimerComponentTest < Minitest::Test
end
component.with_confirmation_check_box { "Really do this?" }
}],
[Primer::OpenProject::DangerConfirmationDialog::ConfirmationCheckBox, { check_box_name: "foo" }],
[Primer::OpenProject::DangerConfirmationDialog::ConfirmationCheckBox, { check_box_name: "foo" }, proc { "Foo" }],
[Primer::OpenProject::FeedbackDialog, {}, proc { |component|
component.with_feedback_message do |feedback|
feedback.with_heading(tag: :h2) { "You are a hero" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def test_does_not_render_if_no_confirmation_check_box_provided
assert_equal "DangerConfirmationDialog requires a confirmation_check_box", error.message
end

def test_does_not_render_if_no_confirmation_check_box_content_provided
error = assert_raises(ArgumentError) do
render_inline(Primer::OpenProject::DangerConfirmationDialog.new) do |dialog|
dialog.with_confirmation_message do |message|
message.with_heading(tag: :h2) { "Danger" }
end
dialog.with_confirmation_check_box
end
end

assert_equal "ConfirmationCheckBox requires a content block", error.message
end

def test_renders_without_form_by_default
render_inline(Primer::OpenProject::DangerConfirmationDialog.new) do |dialog|
dialog.with_confirmation_message do |message|
Expand Down

0 comments on commit 43e1243

Please sign in to comment.