diff options
Diffstat (limited to 'spec/views')
-rw-r--r-- | spec/views/groups/show.html.haml_spec.rb | 52 | ||||
-rw-r--r-- | spec/views/layouts/_head.html.haml_spec.rb | 38 | ||||
-rw-r--r-- | spec/views/layouts/header/_new_dropdown.haml_spec.rb | 6 | ||||
-rw-r--r-- | spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb | 2 | ||||
-rw-r--r-- | spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb | 29 | ||||
-rw-r--r-- | spec/views/projects/_home_panel.html.haml_spec.rb | 1 | ||||
-rw-r--r-- | spec/views/projects/empty.html.haml_spec.rb | 37 | ||||
-rw-r--r-- | spec/views/projects/show.html.haml_spec.rb | 51 | ||||
-rw-r--r-- | spec/views/projects/tree/_tree_row.html.haml_spec.rb | 43 | ||||
-rw-r--r-- | spec/views/search/_filter.html.haml_spec.rb | 17 | ||||
-rw-r--r-- | spec/views/search/_form.html.haml_spec.rb | 14 | ||||
-rw-r--r-- | spec/views/shared/ssh_keys/_key_details.html.haml_spec.rb | 20 |
12 files changed, 232 insertions, 78 deletions
diff --git a/spec/views/groups/show.html.haml_spec.rb b/spec/views/groups/show.html.haml_spec.rb new file mode 100644 index 00000000000..a53aab43c18 --- /dev/null +++ b/spec/views/groups/show.html.haml_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'groups/show.html.haml' do + let_it_be(:user) { build(:user) } + let_it_be(:group) { create(:group) } + + before do + assign(:group, group) + end + + context 'when rendering with the layout' do + subject(:render_page) { render template: 'groups/show.html.haml', layout: 'layouts/group' } + + describe 'invite team members' do + before do + allow(view).to receive(:session).and_return({}) + allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(user)) + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:experiment_enabled?).and_return(false) + allow(view).to receive(:group_path).and_return('') + allow(view).to receive(:group_shared_path).and_return('') + allow(view).to receive(:group_archived_path).and_return('') + end + + context 'when invite team members is not available in sidebar' do + before do + allow(view).to receive(:can_invite_members_for_group?).and_return(false) + end + + it 'does not display the js-invite-members-trigger' do + render_page + + expect(rendered).not_to have_selector('.js-invite-members-trigger') + end + end + + context 'when invite team members is available' do + before do + allow(view).to receive(:can_invite_members_for_group?).and_return(true) + end + + it 'includes the div for js-invite-members-trigger' do + render_page + + expect(rendered).to have_selector('.js-invite-members-trigger') + end + end + end + end +end diff --git a/spec/views/layouts/_head.html.haml_spec.rb b/spec/views/layouts/_head.html.haml_spec.rb index 15fdfaaaa65..0b06309deff 100644 --- a/spec/views/layouts/_head.html.haml_spec.rb +++ b/spec/views/layouts/_head.html.haml_spec.rb @@ -102,6 +102,44 @@ RSpec.describe 'layouts/_head' do expect(rendered).to match(/<script.*>.*var u="\/\/#{matomo_host}\/".*<\/script>/m) expect(rendered).to match(%r(<noscript>.*<img src="//#{matomo_host}/matomo.php.*</noscript>)) end + + context 'matomo_disable_cookies' do + context 'when true' do + before do + stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345, matomo_disable_cookies: true }) + end + + it 'disables cookies' do + render + + expect(rendered).to include('_paq.push(["disableCookies"])') + end + end + + context 'when false' do + before do + stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345, matomo_disable_cookies: false }) + end + + it 'does not disable cookies' do + render + + expect(rendered).not_to include('_paq.push(["disableCookies"])') + end + end + + context 'when absent' do + before do + stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345 }) + end + + it 'does not disable cookies' do + render + + expect(rendered).not_to include('_paq.push(["disableCookies"])') + end + end + end end def stub_helper_with_safe_string(method) diff --git a/spec/views/layouts/header/_new_dropdown.haml_spec.rb b/spec/views/layouts/header/_new_dropdown.haml_spec.rb index 01892e72c97..80342cbdb41 100644 --- a/spec/views/layouts/header/_new_dropdown.haml_spec.rb +++ b/spec/views/layouts/header/_new_dropdown.haml_spec.rb @@ -10,7 +10,7 @@ RSpec.describe 'layouts/header/_new_dropdown' do before do allow(Gitlab::Experimentation).to receive(:active?).and_return(true) allow(view).to receive(:experiment_tracking_category_and_group) - allow(view).to receive(:tracking_label).with(user) + allow(view).to receive(:tracking_label) end context 'with ability to invite members' do @@ -20,8 +20,8 @@ RSpec.describe 'layouts/header/_new_dropdown' do subject expect(view).to have_received(:experiment_tracking_category_and_group) - .with(:invite_members_new_dropdown, subject: user) - expect(view).to have_received(:tracking_label).with(user) + .with(:invite_members_new_dropdown) + expect(view).to have_received(:tracking_label) end end diff --git a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb index c5b56b15431..e34d8b91b38 100644 --- a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb +++ b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb @@ -48,7 +48,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do end describe 'Packages' do - let(:user) { create(:user) } + let_it_be(:user) { create(:user) } let_it_be(:package_menu_name) { 'Packages & Registries' } let_it_be(:package_entry_name) { 'Package Registry' } diff --git a/spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb new file mode 100644 index 00000000000..d3fb35bff6d --- /dev/null +++ b/spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'layouts/nav/sidebar/_project_security_link' do + let_it_be_with_reload(:project) { create(:project) } + context 'on security configuration' do + before do + assign(:project, project) + allow(controller).to receive(:controller_name).and_return('configuration') + allow(controller).to receive(:controller_path).and_return('projects/security/configuration') + allow(controller).to receive(:action_name).and_return('show') + allow(view).to receive(:any_project_nav_tab?).and_return(true) + allow(view).to receive(:project_nav_tab?).and_return(true) + end + + it 'activates Security & Compliance tab' do + render + + expect(rendered).to have_css('li.active', text: 'Security & Compliance') + end + + it 'activates Configuration sub tab' do + render + + expect(rendered).to have_css('.sidebar-sub-level-items > li.active', text: 'Configuration') + end + end +end diff --git a/spec/views/projects/_home_panel.html.haml_spec.rb b/spec/views/projects/_home_panel.html.haml_spec.rb index 548dba7874a..cc0eb9919da 100644 --- a/spec/views/projects/_home_panel.html.haml_spec.rb +++ b/spec/views/projects/_home_panel.html.haml_spec.rb @@ -9,6 +9,7 @@ RSpec.describe 'projects/_home_panel' do let(:project) { create(:project) } before do + stub_feature_flags(vue_notification_dropdown: false) assign(:project, project) allow(view).to receive(:current_user).and_return(user) diff --git a/spec/views/projects/empty.html.haml_spec.rb b/spec/views/projects/empty.html.haml_spec.rb index de83722160e..6762dcd22d5 100644 --- a/spec/views/projects/empty.html.haml_spec.rb +++ b/spec/views/projects/empty.html.haml_spec.rb @@ -79,4 +79,41 @@ RSpec.describe 'projects/empty' do it_behaves_like 'no invite member info' end end + + context 'when rendering with the layout' do + subject(:render_page) { render template: 'projects/empty.html.haml', layout: 'layouts/project' } + + describe 'invite team members' do + before do + allow(view).to receive(:session).and_return({}) + allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(user)) + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:experiment_enabled?).and_return(false) + end + + context 'when invite team members is not available in sidebar' do + before do + allow(view).to receive(:can_invite_members_for_project?).and_return(false) + end + + it 'does not display the js-invite-members-trigger' do + render_page + + expect(rendered).not_to have_selector('.js-invite-members-trigger') + end + end + + context 'when invite team members is available' do + before do + allow(view).to receive(:can_invite_members_for_project?).and_return(true) + end + + it 'includes the div for js-invite-members-trigger' do + render_page + + expect(rendered).to have_selector('.js-invite-members-trigger') + end + end + end + end end diff --git a/spec/views/projects/show.html.haml_spec.rb b/spec/views/projects/show.html.haml_spec.rb new file mode 100644 index 00000000000..995e31e83af --- /dev/null +++ b/spec/views/projects/show.html.haml_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'projects/show.html.haml' do + let_it_be(:user) { build(:user) } + let_it_be(:project) { ProjectPresenter.new(create(:project, :repository), current_user: user) } + + before do + assign(:project, project) + end + + context 'when rendering with the layout' do + subject(:render_page) { render template: 'projects/show.html.haml', layout: 'layouts/project' } + + describe 'invite team members' do + before do + allow(view).to receive(:event_filter_link) + allow(view).to receive(:session).and_return({}) + allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(user)) + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:experiment_enabled?).and_return(false) + allow(view).to receive(:add_page_startup_graphql_call) + end + + context 'when invite team members is not available in sidebar' do + before do + allow(view).to receive(:can_invite_members_for_project?).and_return(false) + end + + it 'does not display the js-invite-members-trigger' do + render_page + + expect(rendered).not_to have_selector('.js-invite-members-trigger') + end + end + + context 'when invite team members is available' do + before do + allow(view).to receive(:can_invite_members_for_project?).and_return(true) + end + + it 'includes the div for js-invite-members-trigger' do + render_page + + expect(rendered).to have_selector('.js-invite-members-trigger') + end + end + end + end +end diff --git a/spec/views/projects/tree/_tree_row.html.haml_spec.rb b/spec/views/projects/tree/_tree_row.html.haml_spec.rb deleted file mode 100644 index 43a37934afd..00000000000 --- a/spec/views/projects/tree/_tree_row.html.haml_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'projects/tree/_tree_row' do - let(:project) { create(:project, :repository) } - let(:repository) { project.repository } - - # rubocop: disable Rails/FindBy - # This is not ActiveRecord where..first - let(:blob_item) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files/ruby').first } - # rubocop: enable Rails/FindBy - - before do - assign(:project, project) - assign(:repository, repository) - assign(:id, File.join('master', '')) - assign(:lfs_blob_ids, []) - end - - it 'renders blob item' do - render_partial(blob_item) - - expect(rendered).to have_content(blob_item.name) - expect(rendered).not_to have_selector('.label-lfs', text: 'LFS') - end - - describe 'LFS blob' do - before do - assign(:lfs_blob_ids, [blob_item].map(&:id)) - - render_partial(blob_item) - end - - it 'renders LFS badge' do - expect(rendered).to have_selector('.label-lfs', text: 'LFS') - end - end - - def render_partial(items) - render partial: 'projects/tree/tree_row', collection: [items].flatten - end -end diff --git a/spec/views/search/_filter.html.haml_spec.rb b/spec/views/search/_filter.html.haml_spec.rb deleted file mode 100644 index 868408f7beb..00000000000 --- a/spec/views/search/_filter.html.haml_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'search/_filter' do - context 'when the search page is opened' do - it 'displays the correct elements' do - render - - expect(rendered).to have_selector('label[for="dashboard_search_group"]') - expect(rendered).to have_selector('input#js-search-group-dropdown') - - expect(rendered).to have_selector('label[for="dashboard_search_project"]') - expect(rendered).to have_selector('input#js-search-project-dropdown') - end - end -end diff --git a/spec/views/search/_form.html.haml_spec.rb b/spec/views/search/_form.html.haml_spec.rb deleted file mode 100644 index 073a39e4ed6..00000000000 --- a/spec/views/search/_form.html.haml_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'search/_form' do - context 'when the search page is opened' do - it 'displays the correct elements' do - render - - expect(rendered).to have_selector('.search-field-holder.form-group') - expect(rendered).to have_selector('label[for="dashboard_search"]') - end - end -end diff --git a/spec/views/shared/ssh_keys/_key_details.html.haml_spec.rb b/spec/views/shared/ssh_keys/_key_details.html.haml_spec.rb new file mode 100644 index 00000000000..400319a42b7 --- /dev/null +++ b/spec/views/shared/ssh_keys/_key_details.html.haml_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'shared/ssh_keys/_key_delete.html.haml' do + context 'when the text parameter is used' do + it 'has text' do + render 'shared/ssh_keys/key_delete.html.haml', text: 'Button', html_class: '', button_data: '' + + expect(rendered).to have_button('Button') + end + end + + context 'when the text parameter is not used' do + it 'does not have text' do + render 'shared/ssh_keys/key_delete.html.haml', html_class: '', button_data: '' + + expect(rendered).to have_button('Delete') + end + end +end |