diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/profiles/preferences_controller_spec.rb | 6 | ||||
-rw-r--r-- | spec/features/dashboard/active_tab_spec.rb | 5 | ||||
-rw-r--r-- | spec/features/dashboard/shortcuts_spec.rb | 4 | ||||
-rw-r--r-- | spec/features/profiles/preferences_spec.rb | 2 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/user/login.json | 1 | ||||
-rw-r--r-- | spec/helpers/preferences_helper_spec.rb | 26 | ||||
-rw-r--r-- | spec/javascripts/dashboard_spec.js.es6 | 37 | ||||
-rw-r--r-- | spec/javascripts/fixtures/dashboard.html.haml | 45 | ||||
-rw-r--r-- | spec/javascripts/project_dashboard_spec.js.es6 | 86 | ||||
-rw-r--r-- | spec/lib/gitlab/themes_spec.rb | 48 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/gitlab_stubs/session.json | 4 | ||||
-rw-r--r-- | spec/support/gitlab_stubs/user.json | 4 |
13 files changed, 258 insertions, 12 deletions
diff --git a/spec/controllers/profiles/preferences_controller_spec.rb b/spec/controllers/profiles/preferences_controller_spec.rb index a5f544b4f92..a66b4ab0902 100644 --- a/spec/controllers/profiles/preferences_controller_spec.rb +++ b/spec/controllers/profiles/preferences_controller_spec.rb @@ -25,7 +25,8 @@ describe Profiles::PreferencesController do def go(params: {}, format: :js) params.reverse_merge!( color_scheme_id: '1', - dashboard: 'stars' + dashboard: 'stars', + theme_id: '1' ) patch :update, user: params, format: format @@ -40,7 +41,8 @@ describe Profiles::PreferencesController do it "changes the user's preferences" do prefs = { color_scheme_id: '1', - dashboard: 'stars' + dashboard: 'stars', + theme_id: '2' }.with_indifferent_access expect(user).to receive(:assign_attributes).with(prefs) diff --git a/spec/features/dashboard/active_tab_spec.rb b/spec/features/dashboard/active_tab_spec.rb index 067e4337e6a..9bcff868756 100644 --- a/spec/features/dashboard/active_tab_spec.rb +++ b/spec/features/dashboard/active_tab_spec.rb @@ -7,9 +7,8 @@ RSpec.describe 'Dashboard Active Tab', js: true do shared_examples 'page has active tab' do |title| it "#{title} tab" do - find('.global-dropdown-toggle').trigger('click') - expect(page).to have_selector('.global-dropdown-menu li.active', count: 1) - expect(find('.global-dropdown-menu li.active')).to have_content(title) + expect(page).to have_selector('.nav-sidebar li.active', count: 1) + expect(find('.nav-sidebar li.active')).to have_content(title) end end diff --git a/spec/features/dashboard/shortcuts_spec.rb b/spec/features/dashboard/shortcuts_spec.rb index 5f1f0c10339..2f77bbde23a 100644 --- a/spec/features/dashboard/shortcuts_spec.rb +++ b/spec/features/dashboard/shortcuts_spec.rb @@ -49,7 +49,7 @@ feature 'Dashboard shortcuts', :js do end end - def check_page_title(title) - expect(find('.header-content .title')).to have_content(title) + def ensure_active_main_tab(content) + expect(find('.nav-sidebar li.active')).to have_content(content) end end diff --git a/spec/features/profiles/preferences_spec.rb b/spec/features/profiles/preferences_spec.rb index c935cdfd5c4..73b14b1d338 100644 --- a/spec/features/profiles/preferences_spec.rb +++ b/spec/features/profiles/preferences_spec.rb @@ -8,7 +8,7 @@ describe 'Profile > Preferences', :js do visit profile_preferences_path end - describe 'User changes their syntax highlighting theme' do + describe 'User changes their application theme', js: true do it 'creates a flash message' do choose 'user_color_scheme_id_5' diff --git a/spec/fixtures/api/schemas/public_api/v4/user/login.json b/spec/fixtures/api/schemas/public_api/v4/user/login.json index 6181b3ccc86..e6c1d9c9d84 100644 --- a/spec/fixtures/api/schemas/public_api/v4/user/login.json +++ b/spec/fixtures/api/schemas/public_api/v4/user/login.json @@ -19,6 +19,7 @@ "organization", "last_sign_in_at", "confirmed_at", + "theme_id", "color_scheme_id", "projects_limit", "current_sign_in_at", diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index a04c87b08eb..50ac3886a36 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -26,6 +26,32 @@ describe PreferencesHelper do end end + describe 'user_application_theme' do + context 'with a user' do + it "returns user's theme's css_class" do + stub_user(theme_id: 3) + + expect(helper.user_application_theme).to eq 'ui_green' + 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(2) + + expect(helper.user_application_theme).to eq 'ui_charcoal' + 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 context 'with a user' do it "returns user's scheme's css_class" do diff --git a/spec/javascripts/dashboard_spec.js.es6 b/spec/javascripts/dashboard_spec.js.es6 new file mode 100644 index 00000000000..c0bdb89ed63 --- /dev/null +++ b/spec/javascripts/dashboard_spec.js.es6 @@ -0,0 +1,37 @@ +/* eslint-disable no-new */ + +require('~/sidebar'); +require('~/lib/utils/text_utility'); + +((global) => { + describe('Dashboard', () => { + const fixtureTemplate = 'static/dashboard.html.raw'; + + function todosCountText() { + return $('.js-todos-count').text(); + } + + function triggerToggle(newCount) { + $(document).trigger('todo:toggle', newCount); + } + + preloadFixtures(fixtureTemplate); + beforeEach(() => { + loadFixtures(fixtureTemplate); + new global.Sidebar(); + }); + + it('should update todos-count after receiving the todo:toggle event', () => { + triggerToggle(5); + expect(todosCountText()).toEqual('5'); + }); + + it('should display todos-count with delimiter', () => { + triggerToggle(1000); + expect(todosCountText()).toEqual('1,000'); + + triggerToggle(1000000); + expect(todosCountText()).toEqual('1,000,000'); + }); + }); +})(window.gl); diff --git a/spec/javascripts/fixtures/dashboard.html.haml b/spec/javascripts/fixtures/dashboard.html.haml new file mode 100644 index 00000000000..32446acfd60 --- /dev/null +++ b/spec/javascripts/fixtures/dashboard.html.haml @@ -0,0 +1,45 @@ +%ul.nav.nav-sidebar + %li.home.active + %a.dashboard-shortcuts-projects + %span + Projects + %li + %a + %span + Todos + %span.count.js-todos-count + 1 + %li + %a.dashboard-shortcuts-activity + %span + Activity + %li + %a + %span + Groups + %li + %a + %span + Milestones + %li + %a.dashboard-shortcuts-issues + %span + Issues + %span + 1 + %li + %a.dashboard-shortcuts-merge_requests + %span + Merge Requests + %li + %a + %span + Snippets + %li + %a + %span + Help + %li + %a + %span + Profile Settings diff --git a/spec/javascripts/project_dashboard_spec.js.es6 b/spec/javascripts/project_dashboard_spec.js.es6 new file mode 100644 index 00000000000..24833b4eb57 --- /dev/null +++ b/spec/javascripts/project_dashboard_spec.js.es6 @@ -0,0 +1,86 @@ +require('~/sidebar'); + +(() => { + describe('Project dashboard page', () => { + let $pageWithSidebar = null; + let $sidebarToggle = null; + let sidebar = null; + const fixtureTemplate = 'projects/dashboard.html.raw'; + + const assertSidebarStateExpanded = (shouldBeExpanded) => { + expect(sidebar.isExpanded).toBe(shouldBeExpanded); + expect($pageWithSidebar.hasClass('page-sidebar-expanded')).toBe(shouldBeExpanded); + }; + + preloadFixtures(fixtureTemplate); + beforeEach(() => { + loadFixtures(fixtureTemplate); + + $pageWithSidebar = $('.page-with-sidebar'); + $sidebarToggle = $('.toggle-nav-collapse'); + + // otherwise instantiating the Sidebar for the second time + // won't do anything, as the Sidebar is a singleton class + gl.Sidebar.singleton = null; + sidebar = new gl.Sidebar(); + }); + + it('can show the sidebar when the toggler is clicked', () => { + assertSidebarStateExpanded(false); + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + }); + + it('should dismiss the sidebar when clone button clicked', () => { + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + + const cloneButton = $('.project-clone-holder a.clone-dropdown-btn'); + cloneButton.click(); + assertSidebarStateExpanded(false); + }); + + it('should dismiss the sidebar when download button clicked', () => { + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + + const downloadButton = $('.project-action-button .btn:has(i.fa-download)'); + downloadButton.click(); + assertSidebarStateExpanded(false); + }); + + it('should dismiss the sidebar when add button clicked', () => { + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + + const addButton = $('.project-action-button .btn:has(i.fa-plus)'); + addButton.click(); + assertSidebarStateExpanded(false); + }); + + it('should dismiss the sidebar when notification button clicked', () => { + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + + const notifButton = $('.js-notification-toggle-btns .notifications-btn'); + notifButton.click(); + assertSidebarStateExpanded(false); + }); + + it('should dismiss the sidebar when clicking on the body', () => { + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + + $('body').click(); + assertSidebarStateExpanded(false); + }); + + it('should dismiss the sidebar when clicking on the project description header', () => { + $sidebarToggle.click(); + assertSidebarStateExpanded(true); + + $('.project-home-panel').click(); + assertSidebarStateExpanded(false); + }); + }); +})(); diff --git a/spec/lib/gitlab/themes_spec.rb b/spec/lib/gitlab/themes_spec.rb new file mode 100644 index 00000000000..7a140518dd2 --- /dev/null +++ b/spec/lib/gitlab/themes_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::Themes, lib: true do + describe '.body_classes' do + it 'returns a space-separated list of class names' do + css = described_class.body_classes + + expect(css).to include('ui_graphite') + expect(css).to include(' ui_charcoal ') + expect(css).to include(' ui_blue') + end + end + + describe '.by_id' do + it 'returns a Theme by its ID' do + expect(described_class.by_id(1).name).to eq 'Graphite' + expect(described_class.by_id(6).name).to eq 'Blue' + end + end + + describe '.default' do + it 'returns the default application theme' do + allow(described_class).to receive(:default_id).and_return(2) + expect(described_class.default.id).to eq 2 + end + + it 'prevents an infinite loop when configuration default is invalid' do + default = described_class::APPLICATION_DEFAULT + themes = described_class::THEMES + + config = double(default_theme: 0).as_null_object + allow(Gitlab).to receive(:config).and_return(config) + expect(described_class.default.id).to eq default + + config = double(default_theme: themes.size + 5).as_null_object + allow(Gitlab).to receive(:config).and_return(config) + expect(described_class.default.id).to eq default + end + end + + describe '.each' do + it 'passes the block to the THEMES Array' do + ids = [] + described_class.each { |theme| ids << theme.id } + expect(ids).not_to be_empty + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 97bb91a6ac8..34902cfb69d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -716,6 +716,7 @@ describe User do it "applies defaults to user" do expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group) + expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme) expect(user.external).to be_falsey end end @@ -726,6 +727,7 @@ describe User do it "applies defaults to user" do expect(user.projects_limit).to eq(123) expect(user.can_create_group).to be_falsey + expect(user.theme_id).to eq(1) end end diff --git a/spec/support/gitlab_stubs/session.json b/spec/support/gitlab_stubs/session.json index cd55d63125e..ce8dfe5ae75 100644 --- a/spec/support/gitlab_stubs/session.json +++ b/spec/support/gitlab_stubs/session.json @@ -7,7 +7,7 @@ "skype":"aertert", "linkedin":"", "twitter":"", - "color_scheme_id":2, + "theme_id":2,"color_scheme_id":2, "state":"active", "created_at":"2012-12-21T13:02:20Z", "extern_uid":null, @@ -17,4 +17,4 @@ "can_create_project":false, "private_token":"Wvjy2Krpb7y8xi93owUz", "access_token":"Wvjy2Krpb7y8xi93owUz" -} +}
\ No newline at end of file diff --git a/spec/support/gitlab_stubs/user.json b/spec/support/gitlab_stubs/user.json index cd55d63125e..ce8dfe5ae75 100644 --- a/spec/support/gitlab_stubs/user.json +++ b/spec/support/gitlab_stubs/user.json @@ -7,7 +7,7 @@ "skype":"aertert", "linkedin":"", "twitter":"", - "color_scheme_id":2, + "theme_id":2,"color_scheme_id":2, "state":"active", "created_at":"2012-12-21T13:02:20Z", "extern_uid":null, @@ -17,4 +17,4 @@ "can_create_project":false, "private_token":"Wvjy2Krpb7y8xi93owUz", "access_token":"Wvjy2Krpb7y8xi93owUz" -} +}
\ No newline at end of file |