mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 01:44:02 +08:00
d63f1826fe
We want to allow admins to make new required fields apply to existing users. In order for this to work we need to have a way to make those users fill up the fields on their next page load. This is very similar to how adding a 2FA requirement post-fact works. Users will be redirected to a page where they can fill up the remaining required fields, and until they do that they won't be able to do anything else.
63 lines
1.8 KiB
Ruby
63 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Admin User Fields", type: :system, js: true do
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
let(:user_fields_page) { PageObjects::Pages::AdminUserFields.new }
|
|
|
|
it "correctly saves user fields" do
|
|
user_fields_page.visit
|
|
user_fields_page.add_field(name: "Occupation", description: "What you do for work")
|
|
|
|
expect(user_fields_page).to have_user_field("Occupation")
|
|
|
|
user_fields_page.refresh
|
|
|
|
expect(user_fields_page).to have_user_field("Occupation")
|
|
end
|
|
|
|
it "displays an error when missing required fields" do
|
|
user_fields_page.visit
|
|
|
|
user_fields_page.add_field(name: "Occupation", description: "")
|
|
|
|
expect(user_fields_page).to have_text(/Description can't be blank/)
|
|
end
|
|
|
|
it "makes sure new required fields are editable after signup" do
|
|
user_fields_page.visit
|
|
|
|
page.find(".user-fields .btn-primary").click
|
|
|
|
form = page.find(".user-field")
|
|
editable_label = I18n.t("admin_js.admin.user_fields.editable.title")
|
|
|
|
user_fields_page.choose_requirement("for_all_users")
|
|
|
|
expect(form).to have_field(editable_label, checked: true, disabled: true)
|
|
|
|
user_fields_page.choose_requirement("optional")
|
|
|
|
expect(form).to have_field(editable_label, checked: false, disabled: false)
|
|
end
|
|
|
|
it "requires confirmation when applying required fields retroactively" do
|
|
user_fields_page.visit
|
|
|
|
page.find(".user-fields .btn-primary").click
|
|
|
|
form = page.find(".user-field")
|
|
|
|
form.find(".user-field-name").fill_in(with: "Favourite Pokémon")
|
|
form.find(".user-field-desc").fill_in(with: "Hint: It's Mudkip")
|
|
|
|
user_fields_page.choose_requirement("for_all_users")
|
|
|
|
form.find(".btn-primary").click
|
|
|
|
expect(page).to have_text(I18n.t("admin_js.admin.user_fields.requirement.confirmation"))
|
|
end
|
|
end
|