2015-06-05 15:53:57 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PreferencesHelper do
|
2017-09-11 11:44:42 -04:00
|
|
|
describe '#dashboard_choices' do
|
2018-10-12 10:10:34 -04: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 14:33:44 -04: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-25 20:04:20 -04:00
|
|
|
dashboards = User.dashboards.dup
|
|
|
|
dashboards[:projects_changed] = dashboards.delete :projects
|
|
|
|
expect(User).to receive(:dashboards).and_return(dashboards)
|
2015-08-26 14:33:44 -04: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-25 20:04:20 -04:00
|
|
|
['Starred Projects', 'stars'],
|
|
|
|
["Your Projects' Activity", 'project_activity'],
|
2016-03-24 06:12:45 -04:00
|
|
|
["Starred Projects' Activity", 'starred_project_activity'],
|
|
|
|
["Your Groups", 'groups'],
|
2018-03-27 08:16:12 -04:00
|
|
|
["Your Todos", 'todos'],
|
|
|
|
["Assigned Issues", 'issues'],
|
|
|
|
["Assigned Merge Requests", 'merge_requests']
|
2015-08-26 14:33:44 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-06 11:49:39 -05:00
|
|
|
describe '#first_day_of_week_choices' do
|
2019-02-24 00:42:22 -05:00
|
|
|
it 'returns Saturday, Sunday and Monday as choices' do
|
2019-02-06 11:49:39 -05:00
|
|
|
expect(helper.first_day_of_week_choices).to eq [
|
|
|
|
['Sunday', 0],
|
2019-02-24 00:42:22 -05:00
|
|
|
['Monday', 1],
|
|
|
|
['Saturday', 6]
|
2019-02-06 11:49:39 -05: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 00:42:22 -05:00
|
|
|
['System default (Sunday)', nil], ['Sunday', 0], ['Monday', 1], ['Saturday', 6]
|
2019-02-06 11:49:39 -05: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 00:42:22 -05: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 11:49:39 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-11 11:44:42 -04:00
|
|
|
describe '#user_application_theme' do
|
|
|
|
context 'with a user' do
|
|
|
|
it "returns user's theme's css_class" do
|
2018-06-07 08:24:57 -04:00
|
|
|
stub_user(theme_id: 3)
|
2017-09-11 11:44:42 -04:00
|
|
|
|
2018-06-07 03:37:02 -04:00
|
|
|
expect(helper.user_application_theme).to eq 'ui-light'
|
2017-09-11 11:44:42 -04: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 03:37:02 -04:00
|
|
|
expect(helper.user_application_theme).to eq 'ui-indigo'
|
2017-09-11 11:44:42 -04: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
|
|
|
|
|
|
|
|
describe '#user_color_scheme' do
|
2015-08-26 14:33:44 -04:00
|
|
|
context 'with a user' do
|
|
|
|
it "returns user's scheme's css_class" do
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double(color_scheme_id: 3))
|
2015-08-26 14:33:44 -04:00
|
|
|
|
|
|
|
expect(helper.user_color_scheme).to eq 'solarized-light'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the default when id is invalid' do
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double(color_scheme_id: Gitlab::ColorSchemes.count + 5))
|
2015-08-26 14:33:44 -04:00
|
|
|
end
|
2015-06-12 20:39:48 -04:00
|
|
|
end
|
2015-06-10 04:42:02 -04:00
|
|
|
|
2015-08-26 14:33:44 -04:00
|
|
|
context 'without a user' do
|
|
|
|
it 'returns the default theme' do
|
|
|
|
stub_user
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(helper.user_color_scheme)
|
|
|
|
.to eq Gitlab::ColorSchemes.default.css_class
|
2015-08-26 14:33:44 -04:00
|
|
|
end
|
2015-06-10 04:42:02 -04:00
|
|
|
end
|
2015-08-26 14:33:44 -04:00
|
|
|
end
|
2015-06-10 04:42:02 -04:00
|
|
|
|
2019-02-20 17:58:53 -05:00
|
|
|
describe '#language_choices' do
|
|
|
|
it 'returns an array of all available languages' do
|
|
|
|
expect(helper.language_choices).to be_an(Array)
|
|
|
|
expect(helper.language_choices.map(&:second)).to eq(Gitlab::I18n.available_locales)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-21 12:58:42 -05: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 12:43:19 -05:00
|
|
|
end
|
2015-06-05 15:53:57 -04:00
|
|
|
end
|