0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 13:59:03 +08:00
discourse/spec/system/wizard_spec.rb
Kris fb4bbca931
A11Y: make wizard radios accessible (#37064)
We are hiding native radio inputs with `visibility: hidden;` which
breaks accessibility and makes the options impossible to select and
change. This PR switches to opacity and size instead so they're
focusable, and in combination with `focus-within` makes it apparent
they're selected!

Before (can't select options at all)
<img width="1532" height="1028" alt="image"
src="https://github.com/user-attachments/assets/6535da23-cfe8-4ada-9549-6f3f5c3aa04e"
/>


After
<img width="1504" height="1000" alt="image"
src="https://github.com/user-attachments/assets/914e916e-677d-4623-8bc0-08986e64f939"
/>
2026-01-12 13:58:34 -05:00

86 lines
3.1 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Wizard", type: :system do
fab!(:admin)
let(:wizard_page) { PageObjects::Pages::Wizard.new }
before { sign_in(admin) }
it "successfully completes the setup wizard" do
visit("/wizard")
expect(wizard_page).to be_on_step("setup")
wizard_page.fill_field("text", "title", "My Test Site")
wizard_page.select_dropdown_option("default-locale", "en")
wizard_page.click_jump_in
expect(page).to have_current_path("/")
end
describe "Setup step" do
it "lets user configure site settings including member access" do
wizard_page.go_to_step("setup")
expect(SiteSetting.login_required).to eq(false)
expect(SiteSetting.invite_only).to eq(false)
expect(SiteSetting.must_approve_users).to eq(false)
expect(wizard_page.privacy_step).to have_selected_choice("login-required", "public")
expect(wizard_page.privacy_step).to have_selected_choice("invite-only", "sign_up")
expect(wizard_page.privacy_step).to have_selected_choice("must-approve-users", "no")
wizard_page.fill_field("text", "title", "My Test Site")
wizard_page.privacy_step.select_access_option("login-required", "private")
wizard_page.privacy_step.select_access_option("invite-only", "invite_only")
wizard_page.privacy_step.select_access_option("must-approve-users", "yes")
wizard_page.click_jump_in
expect(SiteSetting.login_required).to eq(true)
expect(SiteSetting.invite_only).to eq(true)
expect(SiteSetting.must_approve_users).to eq(true)
end
it "redirects to homepage when completed" do
wizard_page.go_to_step("setup")
wizard_page.fill_field("text", "title", "My Test Site")
wizard_page.click_jump_in
expect(page).to have_current_path("/")
end
it "prevents submission when title is empty" do
wizard_page.go_to_step("setup")
wizard_page.fill_field("text", "title", "")
wizard_page.click_jump_in
expect(wizard_page).to be_on_step("setup")
expect(page).to have_css(".wizard-container__field.text-title.invalid")
end
it "prevents submission when title is 'Discourse'" do
wizard_page.go_to_step("setup")
wizard_page.fill_field("text", "title", "Discourse")
wizard_page.click_jump_in
expect(wizard_page).to be_on_step("setup")
expect(page).to have_css(".wizard-container__field.text-title.invalid")
end
it "allows keyboard navigation of radio inputs" do
wizard_page.go_to_step("setup")
radio_field = wizard_page.find_field("radio", "login-required")
first_radio = radio_field.find("input[type='radio']", match: :first, visible: :all)
choice_id = first_radio[:value]
page.execute_script("arguments[0].focus()", first_radio)
expect(radio_field).to have_css(".wizard-container__radio-choice:focus-within")
expect(page.evaluate_script("document.activeElement.type")).to eq("radio")
first_radio.send_keys(:space)
expect(radio_field).to have_css(
".wizard-container__radio-choice[data-choice-id='#{choice_id}'].--selected",
)
end
end
end