discourse/spec/system/user_page/user_preferences_profile_spec.rb
Ted Johansson 23d7800ff1
DEV: Redirect to actionable page if routing is restricted (#28002)
If a user has a required action, e.g. adding a 2FA method or filling in new required fields, we disable client-side routing except to allowed pages.

This led to a situation where a user might navigate away from e.g. the profile page to look at the new ToS, and then being "stuck" due to not knowing how to get back to accept the new terms.

This PR makes it so that if you click any restricted link, instead of doing nothing we transition the user back to the page where they can take the required action.
2024-07-22 12:24:05 +08:00

80 lines
2.3 KiB
Ruby

# 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) }
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
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
it "server-side redirects to the profile page to fill up required fields" do
visit("/")
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
it "client-side redirects to the profile page to fill up required fields" do
visit("/faq")
expect(page).to have_current_path("/faq")
find("#site-logo").click
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
it "disables client-side routing while missing required fields" do
user_preferences_profile_page.visit(user)
find("#site-logo").click
expect(page).to have_current_path("/u/#{user.username}/preferences/profile")
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
visit("/")
expect(page).to have_current_path("/")
end
end
end