Skip to content

Commit e790a2c

Browse files
committed
add a test case for checking and unchecking the checkbox
1 parent 3620082 commit e790a2c

3 files changed

Lines changed: 29 additions & 18 deletions

File tree

app/components/primer/open_project/danger_dialog.html.erb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,8 @@
1717
<%= confirmation_check_box %>
1818
<% end %>
1919
</scrollable-region>
20-
<%= render(Primer::Alpha::Dialog::Footer.new(show_divider: false)) do %>
21-
<%= render(Primer::Beta::Button.new(
22-
data: { "close-dialog-id": dialog_id }
23-
)) { @cancel_button_text } %>
24-
25-
<%= render(Primer::Beta::Button.new(
26-
type: (@form_wrapper.shows_form? ? :submit : :button),
27-
scheme: :danger,
28-
disabled: true,
29-
aria: { describedby: "#{dialog_id}-check_box" },
30-
data: {
31-
"submit-dialog-id": dialog_id,
32-
target: "danger-dialog-form-helper.submitButton"
33-
}
34-
)) { @confirm_button_text } %>
35-
<% end %>
36-
20+
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": dialog_id })) { @cancel_button_text } %>
21+
<%= render(Primer::Beta::Button.new(type: (@form_wrapper.shows_form? ? :submit : :button), scheme: :danger, aria: { describedby: "#{dialog_id}-check_box" }, data: { "submit-dialog-id": dialog_id })) { @confirm_button_text } %>
3722
<div class="sr-only"
3823
aria-live="assertive"
3924
aria-atomic="true"

previews/primer/open_project/danger_dialog_preview.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def with_confirmation_check_box_and_live_messages
123123
dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed")
124124
end
125125
end
126-
127126
end
128127
end
129128
end

test/system/open_project/danger_dialog_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,31 @@ def test_submit_button_submits_form_builder_form
8181
assert_equal "Superfluous", form_params["reason"]
8282
assert_equal ["creator", "assignee"], form_params["notify"]
8383
end
84+
85+
def test_live_region_updates_based_on_checkbox
86+
visit_preview(:with_confirmation_check_box)
87+
88+
click_button("Click me")
89+
90+
assert_selector(".DangerDialog") do
91+
live_region = find("[data-target='danger-dialog-form-helper.liveRegion']")
92+
93+
# Initially, checkbox is unchecked
94+
assert_equal "Please check the confirmation box to proceed.", live_region.text
95+
96+
within(".DangerDialog") do
97+
# Check the checkbox
98+
check("I understand that this deletion cannot be reversed")
99+
end
100+
101+
# Live region updates when checked
102+
assert_equal "Confirmation checkbox checked. You can now proceed.", live_region.text
103+
104+
# Uncheck to verify it toggles back
105+
within(".DangerDialog") do
106+
uncheck("I understand that this deletion cannot be reversed")
107+
end
108+
assert_equal "Please check the confirmation box to proceed.", live_region.text
109+
end
110+
end
84111
end

0 commit comments

Comments
 (0)