2024-05-23 07:18:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-10-24 08:15:32 -04:00
|
|
|
describe "Admin User Fields", type: :system do
|
2024-05-23 07:18:25 -04:00
|
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
|
|
|
|
let(:user_fields_page) { PageObjects::Pages::AdminUserFields.new }
|
2024-12-17 17:13:39 -05:00
|
|
|
let(:page_header) { PageObjects::Components::DPageHeader.new }
|
2024-05-23 07:18:25 -04:00
|
|
|
|
|
|
|
it "correctly saves user fields" do
|
|
|
|
user_fields_page.visit
|
2024-12-17 17:13:39 -05:00
|
|
|
expect(page_header).to be_visible
|
2024-05-23 07:18:25 -04:00
|
|
|
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: "")
|
|
|
|
|
2024-10-14 01:19:53 -04:00
|
|
|
expect(user_fields_page.form.field(:description)).to have_errors("Required")
|
2024-05-23 07:18:25 -04:00
|
|
|
end
|
2024-06-25 07:32:18 -04:00
|
|
|
|
|
|
|
it "makes sure new required fields are editable after signup" do
|
|
|
|
user_fields_page.visit
|
2024-11-24 22:54:43 -05:00
|
|
|
user_fields_page.click_add_field
|
2024-06-25 07:32:18 -04:00
|
|
|
|
2024-12-17 17:13:39 -05:00
|
|
|
expect(page_header).to be_hidden
|
2024-12-09 19:59:47 -05:00
|
|
|
|
2024-06-25 07:32:18 -04:00
|
|
|
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")
|
|
|
|
|
2024-10-14 01:19:53 -04:00
|
|
|
expect(form).to have_field(editable_label, checked: true, disabled: false)
|
2024-06-25 07:32:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "requires confirmation when applying required fields retroactively" do
|
|
|
|
user_fields_page.visit
|
2024-11-24 22:54:43 -05:00
|
|
|
user_fields_page.click_add_field
|
2024-06-25 07:32:18 -04:00
|
|
|
|
|
|
|
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
|
2024-10-21 02:37:46 -04:00
|
|
|
|
|
|
|
context "when editing an existing user field" do
|
|
|
|
fab!(:user_field) { Fabricate(:user_field, requirement: "for_all_users") }
|
|
|
|
|
|
|
|
it "does not require confirmation if the field already applies to all users" do
|
|
|
|
user_fields_page.visit
|
2024-11-24 22:54:43 -05:00
|
|
|
user_fields_page.click_edit
|
2024-10-21 02:37:46 -04:00
|
|
|
|
|
|
|
form = page.find(".user-field")
|
|
|
|
|
|
|
|
form.find(".user-field-name").fill_in(with: "Favourite Transformer")
|
|
|
|
|
2024-12-17 17:13:39 -05:00
|
|
|
expect(page_header).to be_hidden
|
2024-12-09 19:59:47 -05:00
|
|
|
|
2024-10-21 02:37:46 -04:00
|
|
|
form.find(".btn-primary").click
|
|
|
|
|
|
|
|
expect(page).to have_no_text(I18n.t("admin_js.admin.user_fields.requirement.confirmation"))
|
|
|
|
end
|
|
|
|
end
|
2024-05-23 07:18:25 -04:00
|
|
|
end
|