2019-09-30 12:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-05 19:53:57 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe PreferencesHelper do
|
2017-09-11 15:44:42 +00:00
|
|
|
describe '#dashboard_choices' do
|
2018-10-12 14:10:34 +00:00
|
|
|
let(:user) { build(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:can?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2015-08-26 18:33:44 +00:00
|
|
|
it 'raises an exception when defined choices may be missing' do
|
|
|
|
expect(User).to receive(:dashboards).and_return(foo: 'foo')
|
|
|
|
expect { helper.dashboard_choices }.to raise_error(RuntimeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an exception when defined choices may be using the wrong key' do
|
2015-09-26 00:04:20 +00:00
|
|
|
dashboards = User.dashboards.dup
|
|
|
|
dashboards[:projects_changed] = dashboards.delete :projects
|
|
|
|
expect(User).to receive(:dashboards).and_return(dashboards)
|
2015-08-26 18:33:44 +00:00
|
|
|
expect { helper.dashboard_choices }.to raise_error(KeyError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'provides better option descriptions' do
|
|
|
|
expect(helper.dashboard_choices).to match_array [
|
|
|
|
['Your Projects (default)', 'projects'],
|
2015-09-26 00:04:20 +00:00
|
|
|
['Starred Projects', 'stars'],
|
|
|
|
["Your Projects' Activity", 'project_activity'],
|
2016-03-24 10:12:45 +00:00
|
|
|
["Starred Projects' Activity", 'starred_project_activity'],
|
2021-03-03 18:11:16 +00:00
|
|
|
["Followed Users' Activity", 'followed_user_activity'],
|
2016-03-24 10:12:45 +00:00
|
|
|
["Your Groups", 'groups'],
|
2019-07-04 15:45:54 +00:00
|
|
|
["Your To-Do List", 'todos'],
|
2018-03-27 12:16:12 +00:00
|
|
|
["Assigned Issues", 'issues'],
|
2021-04-08 15:09:06 +00:00
|
|
|
["Assigned merge requests", 'merge_requests']
|
2015-08-26 18:33:44 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-06 16:49:39 +00:00
|
|
|
describe '#first_day_of_week_choices' do
|
2019-02-24 05:42:22 +00:00
|
|
|
it 'returns Saturday, Sunday and Monday as choices' do
|
2019-02-06 16:49:39 +00:00
|
|
|
expect(helper.first_day_of_week_choices).to eq [
|
|
|
|
['Sunday', 0],
|
2019-02-24 05:42:22 +00:00
|
|
|
['Monday', 1],
|
|
|
|
['Saturday', 6]
|
2019-02-06 16:49:39 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#first_day_of_week_choices_with_default' do
|
|
|
|
it 'returns choices including system default' do
|
|
|
|
expect(helper.first_day_of_week_choices_with_default).to eq [
|
2019-02-24 05:42:22 +00:00
|
|
|
['System default (Sunday)', nil], ['Sunday', 0], ['Monday', 1], ['Saturday', 6]
|
2019-02-06 16:49:39 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns choices including system default set to Monday' do
|
|
|
|
stub_application_setting(first_day_of_week: 1)
|
|
|
|
expect(helper.first_day_of_week_choices_with_default).to eq [
|
2019-02-24 05:42:22 +00:00
|
|
|
['System default (Monday)', nil], ['Sunday', 0], ['Monday', 1], ['Saturday', 6]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns choices including system default set to Saturday' do
|
|
|
|
stub_application_setting(first_day_of_week: 6)
|
|
|
|
expect(helper.first_day_of_week_choices_with_default).to eq [
|
|
|
|
['System default (Saturday)', nil], ['Sunday', 0], ['Monday', 1], ['Saturday', 6]
|
2019-02-06 16:49:39 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-11 15:44:42 +00:00
|
|
|
describe '#user_application_theme' do
|
|
|
|
context 'with a user' do
|
|
|
|
it "returns user's theme's css_class" do
|
2018-06-07 12:24:57 +00:00
|
|
|
stub_user(theme_id: 3)
|
2017-09-11 15:44:42 +00:00
|
|
|
|
2018-06-07 07:37:02 +00:00
|
|
|
expect(helper.user_application_theme).to eq 'ui-light'
|
2017-09-11 15:44:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the default when id is invalid' do
|
|
|
|
stub_user(theme_id: Gitlab::Themes.count + 5)
|
|
|
|
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:default_theme).and_return(1)
|
|
|
|
|
2018-06-07 07:37:02 +00:00
|
|
|
expect(helper.user_application_theme).to eq 'ui-indigo'
|
2017-09-11 15:44:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'returns the default theme' do
|
|
|
|
stub_user
|
|
|
|
|
|
|
|
expect(helper.user_application_theme).to eq Gitlab::Themes.default.css_class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-23 12:13:44 +00:00
|
|
|
describe '#user_application_dark_mode?' do
|
|
|
|
context 'with a user' do
|
|
|
|
it "returns true if user's selected dark theme" do
|
|
|
|
stub_user(theme_id: 11)
|
|
|
|
|
|
|
|
expect(helper.user_application_dark_mode?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if user's selected any light theme" do
|
|
|
|
stub_user(theme_id: 1)
|
|
|
|
|
|
|
|
expect(helper.user_application_dark_mode?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'returns false' do
|
|
|
|
stub_user
|
|
|
|
|
|
|
|
expect(helper.user_application_dark_mode?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-11 15:44:42 +00:00
|
|
|
describe '#user_color_scheme' do
|
2015-08-26 18:33:44 +00:00
|
|
|
context 'with a user' do
|
|
|
|
it "returns user's scheme's css_class" do
|
2017-06-21 13:48:12 +00:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double(color_scheme_id: 3))
|
2015-08-26 18:33:44 +00:00
|
|
|
|
|
|
|
expect(helper.user_color_scheme).to eq 'solarized-light'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the default when id is invalid' do
|
2017-06-21 13:48:12 +00:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double(color_scheme_id: Gitlab::ColorSchemes.count + 5))
|
2015-08-26 18:33:44 +00:00
|
|
|
end
|
2015-06-13 00:39:48 +00:00
|
|
|
end
|
2015-06-10 08:42:02 +00:00
|
|
|
|
2015-08-26 18:33:44 +00:00
|
|
|
context 'without a user' do
|
|
|
|
it 'returns the default theme' do
|
|
|
|
stub_user
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(helper.user_color_scheme)
|
|
|
|
.to eq Gitlab::ColorSchemes.default.css_class
|
2015-08-26 18:33:44 +00:00
|
|
|
end
|
2015-06-10 08:42:02 +00:00
|
|
|
end
|
2015-08-26 18:33:44 +00:00
|
|
|
end
|
2015-06-10 08:42:02 +00:00
|
|
|
|
2021-05-10 00:10:37 +00:00
|
|
|
describe '#language_choices' do
|
|
|
|
include StubLanguagesTranslationPercentage
|
|
|
|
|
|
|
|
it 'lists all the selectable language options with their translation percent' do
|
|
|
|
stub_languages_translation_percentage(en: 100, es: 65)
|
|
|
|
stub_user(preferred_language: :en)
|
|
|
|
|
|
|
|
expect(helper.language_choices).to eq([
|
|
|
|
'<option selected="selected" value="en">English (100% translated)</option>',
|
|
|
|
'<option value="es">Spanish - español (65% translated)</option>'
|
|
|
|
].join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-21 17:58:42 +00:00
|
|
|
def stub_user(messages = {})
|
|
|
|
if messages.empty?
|
|
|
|
allow(helper).to receive(:current_user).and_return(nil)
|
|
|
|
else
|
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double('user', messages))
|
|
|
|
end
|
2016-11-08 17:43:19 +00:00
|
|
|
end
|
2021-05-26 12:10:41 +00:00
|
|
|
|
|
|
|
describe '#integration_views' do
|
|
|
|
let(:gitpod_url) { 'http://gitpod.test' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(gitpod_enabled)
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:gitpod_url).and_return(gitpod_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitpod is not enabled' do
|
|
|
|
let(:gitpod_enabled) { false }
|
|
|
|
|
|
|
|
it 'does not include Gitpod integration' do
|
|
|
|
expect(helper.integration_views).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitpod is enabled' do
|
|
|
|
let(:gitpod_enabled) { true }
|
|
|
|
|
|
|
|
it 'includes Gitpod integration' do
|
|
|
|
expect(helper.integration_views[0][:name]).to eq 'gitpod'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the Gitpod url configured in settings' do
|
|
|
|
expect(helper.integration_views[0][:message_url]).to eq gitpod_url
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitpod url is not set' do
|
|
|
|
let(:gitpod_url) { '' }
|
|
|
|
|
|
|
|
it 'returns the Gitpod default url' do
|
|
|
|
expect(helper.integration_views[0][:message_url]).to eq 'https://gitpod.io/'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-06-05 19:53:57 +00:00
|
|
|
end
|