2024-06-25 19:32:18 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe "User preferences | Profile", type: :system do
|
|
|
|
fab!(:user) { Fabricate(:user, active: true) }
|
|
|
|
let(:user_preferences_profile_page) { PageObjects::Pages::UserPreferencesProfile.new }
|
|
|
|
let(:user_preferences_page) { PageObjects::Pages::UserPreferences.new }
|
|
|
|
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
2024-07-05 18:31:57 +08:00
|
|
|
describe "changing bio" do
|
|
|
|
it "correctly updates the bio" do
|
|
|
|
user_preferences_profile_page.visit(user)
|
|
|
|
|
|
|
|
user_preferences_profile_page.expand_profile_details
|
|
|
|
user_preferences_profile_page.fill_bio(with: "I am a human.")
|
|
|
|
user_preferences_profile_page.save
|
|
|
|
|
|
|
|
expect(user_preferences_profile_page.cooked_bio).to have_text("I am a human.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-25 19:32:18 +08:00
|
|
|
describe "enforcing required fields" do
|
|
|
|
before do
|
|
|
|
UserRequiredFieldsVersion.create!
|
|
|
|
UserField.create!(
|
|
|
|
field_type: "text",
|
|
|
|
name: "Favourite Pokemon",
|
|
|
|
description: "Hint: It's Mudkip.",
|
|
|
|
requirement: :for_all_users,
|
|
|
|
editable: true,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-07-22 12:24:05 +08:00
|
|
|
it "server-side redirects to the profile page to fill up required fields" do
|
2024-06-25 19:32:18 +08:00
|
|
|
visit("/")
|
|
|
|
|
2024-06-26 14:49:34 +08:00
|
|
|
expect(page).to have_current_path("/u/#{user.username}/preferences/profile")
|
2024-06-25 19:32:18 +08:00
|
|
|
|
|
|
|
expect(page).to have_selector(
|
|
|
|
".alert-error",
|
|
|
|
text: I18n.t("js.user.preferences.profile.enforced_required_fields"),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-07-22 12:24:05 +08:00
|
|
|
it "client-side redirects to the profile page to fill up required fields" do
|
|
|
|
visit("/faq")
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/faq")
|
|
|
|
|
2024-08-08 19:52:48 +08:00
|
|
|
click_logo
|
2024-07-22 12:24:05 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path("/u/#{user.username}/preferences/profile")
|
|
|
|
|
|
|
|
expect(page).to have_selector(
|
|
|
|
".alert-error",
|
|
|
|
text: I18n.t("js.user.preferences.profile.enforced_required_fields"),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-06-25 19:32:18 +08:00
|
|
|
it "disables client-side routing while missing required fields" do
|
|
|
|
user_preferences_profile_page.visit(user)
|
|
|
|
|
2024-08-08 19:52:48 +08:00
|
|
|
click_logo
|
2024-06-25 19:32:18 +08:00
|
|
|
|
2024-06-26 14:49:34 +08:00
|
|
|
expect(page).to have_current_path("/u/#{user.username}/preferences/profile")
|
2024-06-25 19:32:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows user to fill up required fields" do
|
|
|
|
user_preferences_profile_page.visit(user)
|
|
|
|
|
|
|
|
find(".user-field-favourite-pokemon input").fill_in(with: "Mudkip")
|
|
|
|
find(".save-button .btn-primary").click
|
|
|
|
|
2024-08-27 16:15:30 +08:00
|
|
|
expect(page).to have_selector(".pref-bio")
|
|
|
|
|
2024-06-25 19:32:18 +08:00
|
|
|
visit("/")
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/")
|
|
|
|
end
|
2024-10-21 17:11:43 +08:00
|
|
|
|
|
|
|
it "allows enabling safe-mode" do
|
|
|
|
visit("/safe-mode")
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/safe-mode")
|
|
|
|
|
|
|
|
page.find("#btn-enter-safe-mode").click
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/u/#{user.username}/preferences/profile")
|
|
|
|
end
|
2024-06-25 19:32:18 +08:00
|
|
|
end
|
|
|
|
end
|