Skip to content

Commit 99235e0

Browse files
committed
Remove last occurences of customizable text and adapt tests
1 parent 38d870f commit 99235e0

4 files changed

Lines changed: 28 additions & 48 deletions

File tree

app/components/primer/open_project/danger_dialog_form_helper.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ class DangerDialogFormHelperElement extends HTMLElement {
3535
this.submitButton.disabled = !enabled
3636

3737
if (this.liveRegion) {
38-
const message = enabled
39-
? this.confirmationLiveMessageChecked
40-
: this.confirmationLiveMessageUnchecked
38+
const message = enabled ? this.confirmationLiveMessageChecked : this.confirmationLiveMessageUnchecked
4139
this.liveRegion.announce(message, {politeness: 'assertive'})
4240
}
4341
}

previews/primer/open_project/danger_dialog_preview.rb

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ def default
1919
end
2020
end
2121

22-
# @label With confirmation check box
23-
# @snapshot interactive
24-
def with_confirmation_check_box
25-
render(Primer::OpenProject::DangerDialog.new(title: "Delete dialog")) do |dialog|
26-
dialog.with_show_button { "Click me" }
27-
dialog.with_confirmation_message do |message|
28-
message.with_heading(tag: :h2) { "Permanently delete this item?" }
29-
message.with_description_content("This action is not reversible. Please proceed with caution.")
30-
end
31-
dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed")
32-
end
33-
end
34-
3522
# @label Playground
3623
# @param icon [Symbol] octicon
3724
# @param icon_color [Symbol] select [default, muted, subtle, accent, success, attention, severe, danger, open, closed, done, sponsors, on_emphasis, inherit]
@@ -68,6 +55,19 @@ def playground(
6855
)
6956
end
7057

58+
# @label With confirmation check box
59+
# @snapshot interactive
60+
def with_confirmation_check_box
61+
render(Primer::OpenProject::DangerDialog.new(title: "Delete dialog")) do |dialog|
62+
dialog.with_show_button { "Click me" }
63+
dialog.with_confirmation_message do |message|
64+
message.with_heading(tag: :h2) { "Permanently delete this item?" }
65+
message.with_description_content("This action is not reversible. Please proceed with caution.")
66+
end
67+
dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed")
68+
end
69+
end
70+
7171
# @label With form using FormBuilder
7272
def with_form_builder_form(route_format: :html)
7373
render_with_template(locals: { route_format: route_format })
@@ -106,23 +106,6 @@ def with_form_builder_form_test(route_format: :html)
106106
def with_form_test(route_format: :html)
107107
render_with_template(locals: { route_format: route_format })
108108
end
109-
110-
# @label With confirmation checkbox and custom live messages
111-
# @snapshot interactive
112-
def with_confirmation_check_box_and_live_messages
113-
render(Primer::OpenProject::DangerDialog.new(
114-
title: "Delete dialog",
115-
confirmation_live_message_checked: "You checked the box — deletion is now possible.",
116-
confirmation_live_message_unchecked: "You must check the box to enable deletion."
117-
)) do |dialog|
118-
dialog.with_show_button { "Click me" }
119-
dialog.with_confirmation_message do |message|
120-
message.with_heading(tag: :h2) { "Permanently delete this item?" }
121-
message.with_description_content("This action is irreversible. Proceed with caution.")
122-
end
123-
dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed")
124-
end
125-
end
126109
end
127110
end
128111
end

test/components/primer/open_project/danger_dialog_test.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,15 @@ def test_renders_additional_details
285285

286286
def test_renders_live_region_for_confirmation_checkbox
287287
render_inline(Primer::OpenProject::DangerDialog.new(
288-
title: "Danger confirmation action",
289-
confirmation_live_message_checked: "Checkbox checked — you can proceed.",
290-
confirmation_live_message_unchecked: "Please check the confirmation box to continue."
288+
title: "Danger confirmation action"
291289
)) do |dialog|
292290
dialog.with_confirmation_message do |message|
293291
message.with_heading(tag: :h2) { "Danger" }
294292
end
295293
dialog.with_confirmation_check_box { "I confirm this deletion" }
296294
end
297295

298-
# Check that the live region exists and is sr-only
299-
assert_selector("div.sr-only[data-target='danger-dialog-form-helper.liveRegion']")
300-
301-
live_region = page.find_css("div.sr-only[data-target='danger-dialog-form-helper.liveRegion']").first
302-
assert_equal "assertive", live_region.attributes["aria-live"].value
303-
assert_equal "true", live_region.attributes["aria-atomic"].value
296+
# Check that the live region exists
297+
assert_selector("live-region[data-target='danger-dialog-form-helper.liveRegion']")
304298
end
305299
end

test/system/open_project/danger_dialog_test.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,29 @@ def test_live_region_updates_based_on_checkbox
8888
click_button("Click me")
8989

9090
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
91+
assert_selector("[data-target='danger-dialog-form-helper.liveRegion']")
9592

9693
within(".DangerDialog") do
9794
# Check the checkbox
9895
check("I understand that this deletion cannot be reversed")
9996
end
10097

98+
live_region_text = page.evaluate_script(%Q|
99+
document.querySelector("[data-target='danger-dialog-form-helper.liveRegion']")?.shadowRoot?.querySelector('#assertive')?.textContent ?? ""
100+
|)
101101
# Live region updates when checked
102-
assert_equal "Confirmation checkbox checked. You can now proceed.", live_region.text
102+
assert_equal "The button to proceed is now active.", live_region_text
103+
103104

104105
# Uncheck to verify it toggles back
105106
within(".DangerDialog") do
106107
uncheck("I understand that this deletion cannot be reversed")
107108
end
108-
assert_equal "Please check the confirmation box to proceed.", live_region.text
109+
110+
live_region_text = page.evaluate_script(%Q|
111+
document.querySelector("[data-target='danger-dialog-form-helper.liveRegion']")?.shadowRoot?.querySelector('#assertive')?.textContent ?? ""
112+
|)
113+
assert_equal "The button to proceed is now inactive. You need to tick the checkbox to continue.", live_region_text
109114
end
110115
end
111116
end

0 commit comments

Comments
 (0)