From efe4e72f934581749ced193672df04cd2d891508 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 16 Dec 2024 12:08:19 -0500 Subject: [PATCH] Convert `settings/preferences/appearance` controller spec to system (#33323) --- .../preferences/appearance_controller_spec.rb | 35 --------------- .../settings/preferences/appearance_spec.rb | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 35 deletions(-) delete mode 100644 spec/controllers/settings/preferences/appearance_controller_spec.rb create mode 100644 spec/system/settings/preferences/appearance_spec.rb diff --git a/spec/controllers/settings/preferences/appearance_controller_spec.rb b/spec/controllers/settings/preferences/appearance_controller_spec.rb deleted file mode 100644 index 14f9b244ab..0000000000 --- a/spec/controllers/settings/preferences/appearance_controller_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Settings::Preferences::AppearanceController do - render_views - - let!(:user) { Fabricate(:user) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - before do - get :show - end - - it 'returns http success with private cache control headers', :aggregate_failures do - expect(response).to have_http_status(200) - expect(response.headers['Cache-Control']).to include('private, no-store') - end - end - - describe 'PUT #update' do - subject { put :update, params: { user: { settings_attributes: { theme: 'contrast' } } } } - - it 'redirects correctly' do - expect { subject } - .to change { user.reload.settings.theme }.to('contrast') - - expect(response).to redirect_to(settings_preferences_appearance_path) - end - end -end diff --git a/spec/system/settings/preferences/appearance_spec.rb b/spec/system/settings/preferences/appearance_spec.rb new file mode 100644 index 0000000000..0b6f1e4b15 --- /dev/null +++ b/spec/system/settings/preferences/appearance_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Settings preferences appearance page' do + let(:user) { Fabricate :user } + + before { sign_in user } + + it 'Views and updates user prefs' do + visit settings_preferences_appearance_path + + expect(page) + .to have_private_cache_control + + select 'contrast', from: theme_selection_field + check confirm_reblog_field + uncheck confirm_delete_field + + expect { save_changes } + .to change { user.reload.settings.theme }.to('contrast') + .and change { user.reload.settings['web.reblog_modal'] }.to(true) + .and(change { user.reload.settings['web.delete_modal'] }.to(false)) + expect(page) + .to have_title(I18n.t('settings.appearance')) + end + + def save_changes + within('form') { click_on submit_button } + end + + def confirm_delete_field + I18n.t('simple_form.labels.defaults.setting_delete_modal') + end + + def confirm_reblog_field + I18n.t('simple_form.labels.defaults.setting_boost_modal') + end + + def theme_selection_field + I18n.t('simple_form.labels.defaults.setting_theme') + end +end