diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/views | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/views')
12 files changed, 341 insertions, 88 deletions
diff --git a/spec/views/admin/dashboard/index.html.haml_spec.rb b/spec/views/admin/dashboard/index.html.haml_spec.rb index 70fb77944cc..e9223c84674 100644 --- a/spec/views/admin/dashboard/index.html.haml_spec.rb +++ b/spec/views/admin/dashboard/index.html.haml_spec.rb @@ -37,7 +37,7 @@ RSpec.describe 'admin/dashboard/index.html.haml' do render expect(rendered).not_to have_content "Users in License" - expect(rendered).not_to have_content "Active Users" + expect(rendered).not_to have_content "Billable Users" expect(rendered).not_to have_content "Maximum Users" expect(rendered).not_to have_content "Users over License" end diff --git a/spec/views/groups/edit.html.haml_spec.rb b/spec/views/groups/edit.html.haml_spec.rb index 83623ea7bb4..f40b03fda2a 100644 --- a/spec/views/groups/edit.html.haml_spec.rb +++ b/spec/views/groups/edit.html.haml_spec.rb @@ -26,7 +26,7 @@ RSpec.describe 'groups/edit.html.haml' do expect(rendered).to have_content("Prevent sharing a project within #{test_group.name} with other groups") expect(rendered).to have_css('.js-descr', text: 'help text here') - expect(rendered).to have_field('group_share_with_group_lock', checkbox_options) + expect(rendered).to have_field('group_share_with_group_lock', **checkbox_options) end end diff --git a/spec/views/jira_connect/subscriptions/index.html.haml_spec.rb b/spec/views/jira_connect/subscriptions/index.html.haml_spec.rb new file mode 100644 index 00000000000..dcc36c93327 --- /dev/null +++ b/spec/views/jira_connect/subscriptions/index.html.haml_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'jira_connect/subscriptions/index.html.haml' do + let(:user) { build_stubbed(:user) } + + before do + allow(view).to receive(:current_user).and_return(user) + assign(:subscriptions, []) + end + + context 'when the user is signed in' do + it 'shows link to user profile' do + render + + expect(rendered).to have_link(user.to_reference) + end + end + + context 'when the user is not signed in' do + let(:user) { nil } + + it 'shows "Sign in" link' do + render + + expect(rendered).to have_link('Sign in to GitLab') + end + end +end diff --git a/spec/views/layouts/nav/sidebar/_admin.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_admin.html.haml_spec.rb index 777dc0c8571..2c37565328a 100644 --- a/spec/views/layouts/nav/sidebar/_admin.html.haml_spec.rb +++ b/spec/views/layouts/nav/sidebar/_admin.html.haml_spec.rb @@ -92,7 +92,11 @@ RSpec.describe 'layouts/nav/sidebar/_admin' do end context 'on settings' do + let(:gitlab_com?) { false } + before do + allow(::Gitlab).to receive(:com?) { gitlab_com? } + render end @@ -100,6 +104,20 @@ RSpec.describe 'layouts/nav/sidebar/_admin' do expect(rendered).to have_link('General', href: general_admin_application_settings_path) end + context 'when GitLab.com' do + let(:gitlab_com?) { true } + + it 'does not include Integrations link' do + expect(rendered).not_to have_link('Integrations', href: integrations_admin_application_settings_path) + end + end + + context 'when not GitLab.com' do + it 'includes Integrations link' do + expect(rendered).to have_link('Integrations', href: integrations_admin_application_settings_path) + end + end + context 'when GitLab FOSS' do it 'does not include Templates link' do expect(rendered).not_to have_link('Templates', href: '/admin/application_settings/templates') 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 bf5b5785b8d..3fb9fb54b01 100644 --- a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb +++ b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'layouts/nav/sidebar/_project' do - let(:project) { create(:project, :repository) } + let_it_be_with_reload(:project) { create(:project, :repository) } before do assign(:project, project) @@ -246,6 +246,30 @@ RSpec.describe 'layouts/nav/sidebar/_project' do end end + describe 'Tracing' do + it 'is not visible to unauthorized user' do + allow(view).to receive(:can?).and_return(false) + + render + + expect(rendered).not_to have_text 'Tracing' + end + + it 'links to Tracing page' do + render + + expect(rendered).to have_link('Tracing', href: project_tracing_path(project)) + end + + context 'without project.tracing_external_url' do + it 'links to Tracing page' do + render + + expect(rendered).to have_link('Tracing', href: project_tracing_path(project)) + end + end + end + describe 'Alert Management' do it 'shows the Alerts sidebar entry' do render @@ -299,10 +323,10 @@ RSpec.describe 'layouts/nav/sidebar/_project' do allow(Gitlab).to receive(:com?).and_return(true) end - it 'does not display "Access Tokens" nav item' do + it 'displays "Access Tokens" nav item' do render - expect(rendered).not_to have_link('Access Tokens', href: project_settings_access_tokens_path(project)) + expect(rendered).to have_link('Access Tokens', href: project_settings_access_tokens_path(project)) end end end diff --git a/spec/views/profiles/preferences/show.html.haml_spec.rb b/spec/views/profiles/preferences/show.html.haml_spec.rb index 1b8b28367c1..aab50209953 100644 --- a/spec/views/profiles/preferences/show.html.haml_spec.rb +++ b/spec/views/profiles/preferences/show.html.haml_spec.rb @@ -20,6 +20,14 @@ RSpec.describe 'profiles/preferences/show' do it 'has an id for anchoring' do expect(rendered).to have_css('#navigation-theme') end + + it 'has correct stylesheet tags' do + Gitlab::Themes.each do |theme| + next unless theme.css_filename + + expect(rendered).to have_selector("link[href*=\"themes/#{theme.css_filename}\"]", visible: false) + end + end end context 'syntax highlighting theme' do @@ -67,7 +75,7 @@ RSpec.describe 'profiles/preferences/show' do end def have_integrations_section - have_css('#integrations.profile-settings-sidebar', { text: 'Integrations' }) + have_css('#integrations.profile-settings-sidebar', text: 'Integrations') end before do diff --git a/spec/views/projects/merge_requests/diffs/_diffs.html.haml_spec.rb b/spec/views/projects/merge_requests/diffs/_diffs.html.haml_spec.rb deleted file mode 100644 index 7cdc817d784..00000000000 --- a/spec/views/projects/merge_requests/diffs/_diffs.html.haml_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'projects/merge_requests/diffs/_diffs.html.haml' do - include Devise::Test::ControllerHelpers - - let(:user) { create(:user) } - let(:project) { create(:project, :public, :repository) } - let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project, author: user) } - - before do - allow(view).to receive(:url_for).and_return(controller.request.fullpath) - - assign(:merge_request, merge_request) - assign(:environment, merge_request.environments_for(user).last) - assign(:diffs, merge_request.diffs) - assign(:merge_request_diffs, merge_request.diffs) - assign(:diff_notes_disabled, true) # disable note creation - assign(:use_legacy_diff_notes, false) - assign(:grouped_diff_discussions, {}) - assign(:notes, []) - end - - context 'for a commit' do - let(:commit) { merge_request.commits.last } - - before do - assign(:commit, commit) - end - - it "shows the commit scope" do - render - - expect(rendered).to have_content "Only comments from the following commit are shown below" - end - end -end diff --git a/spec/views/projects/settings/operations/show.html.haml_spec.rb b/spec/views/projects/settings/operations/show.html.haml_spec.rb index b4d20da0a5c..24ab64b20f5 100644 --- a/spec/views/projects/settings/operations/show.html.haml_spec.rb +++ b/spec/views/projects/settings/operations/show.html.haml_spec.rb @@ -6,37 +6,85 @@ RSpec.describe 'projects/settings/operations/show' do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } + let_it_be(:error_tracking_setting) do + create(:project_error_tracking_setting, project: project) + end + + let_it_be_with_reload(:tracing_setting) do + create(:project_tracing_setting, project: project) + end + + let_it_be(:prometheus_service) { create(:prometheus_service, project: project) } + let_it_be(:alerts_service) { create(:alerts_service, project: project) } + let(:operations_show_locals) do { - prometheus_service: project.find_or_initialize_service('prometheus'), - alerts_service: project.find_or_initialize_service('alerts') + prometheus_service: prometheus_service, + alerts_service: alerts_service } end + before_all do + project.add_reporter(user) + end + before do assign :project, project + + allow(view).to receive(:error_tracking_setting) + .and_return(error_tracking_setting) + allow(view).to receive(:tracing_setting) + .and_return(tracing_setting) + allow(view).to receive(:current_user).and_return(user) end describe 'Operations > Error Tracking' do - before do - project.add_reporter(user) + context 'Settings page ' do + it 'renders the Operations Settings page' do + render template: 'projects/settings/operations/show', locals: operations_show_locals - allow(view).to receive(:error_tracking_setting) - .and_return(error_tracking_setting) - allow(view).to receive(:current_user).and_return(user) - allow(view).to receive(:incident_management_available?) { false } + expect(rendered).to have_content _('Error tracking') + expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token') + end end + end - let_it_be(:error_tracking_setting) do - create(:project_error_tracking_setting, project: project) + describe 'Operations > Tracing' do + context 'with project.tracing_external_url' do + it 'links to project.tracing_external_url' do + render template: 'projects/settings/operations/show', locals: operations_show_locals + + expect(rendered).to have_link('Tracing', href: tracing_setting.external_url) + end + + context 'with malicious external_url' do + let(:malicious_tracing_url) { "https://replaceme.com/'><script>alert(document.cookie)</script>" } + let(:cleaned_url) { "https://replaceme.com/'>" } + + before do + tracing_setting.update_column(:external_url, malicious_tracing_url) + end + + it 'sanitizes external_url' do + render template: 'projects/settings/operations/show', locals: operations_show_locals + + expect(tracing_setting.external_url).to eq(malicious_tracing_url) + expect(rendered).to have_link('Tracing', href: cleaned_url) + end + end end - context 'Settings page ' do - it 'renders the Operations Settings page' do + context 'without project.tracing_external_url' do + let(:tracing_setting) { build(:project_tracing_setting, project: project) } + + before do + tracing_setting.external_url = nil + end + + it 'links to Tracing page' do render template: 'projects/settings/operations/show', locals: operations_show_locals - expect(rendered).to have_content _('Error tracking') - expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token') + expect(rendered).to have_link('Tracing', href: project_tracing_path(project)) end end end diff --git a/spec/views/projects/tracing/show.html.haml_spec.rb b/spec/views/projects/tracing/show.html.haml_spec.rb new file mode 100644 index 00000000000..96dc6a18fc7 --- /dev/null +++ b/spec/views/projects/tracing/show.html.haml_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'projects/tracings/show' do + let_it_be_with_reload(:project) { create(:project) } + let_it_be(:error_tracking_setting) { create(:project_error_tracking_setting, project: project) } + + before do + assign(:project, project) + allow(view).to receive(:error_tracking_setting) + .and_return(error_tracking_setting) + end + + context 'with project.tracing_external_url' do + let_it_be(:tracing_url) { 'https://tracing.url' } + let_it_be(:tracing_setting) { create(:project_tracing_setting, project: project, external_url: tracing_url) } + + before do + allow(view).to receive(:can?).and_return(true) + allow(view).to receive(:tracing_setting).and_return(tracing_setting) + end + + it 'renders iframe' do + render + + expect(rendered).to match(/iframe/) + end + + context 'with malicious external_url' do + let(:malicious_tracing_url) { "https://replaceme.com/'><script>alert(document.cookie)</script>" } + let(:cleaned_url) { "https://replaceme.com/'>" } + + before do + tracing_setting.update_column(:external_url, malicious_tracing_url) + end + + it 'sanitizes external_url' do + render + + expect(tracing_setting.external_url).to eq(malicious_tracing_url) + expect(rendered).to have_xpath("//iframe[@src=\"#{cleaned_url}\"]") + end + end + end + + context 'without project.tracing_external_url' do + before do + allow(view).to receive(:can?).and_return(true) + end + + it 'renders empty state' do + render + + expect(rendered).to have_link('Add Jaeger URL') + expect(rendered).not_to match(/iframe/) + end + end +end diff --git a/spec/views/search/_results.html.haml_spec.rb b/spec/views/search/_results.html.haml_spec.rb index 9e95dc40ff8..033b2304e33 100644 --- a/spec/views/search/_results.html.haml_spec.rb +++ b/spec/views/search/_results.html.haml_spec.rb @@ -60,6 +60,28 @@ RSpec.describe 'search/_results' do expect(rendered).to have_selector('#js-search-filter-by-state') end + + context 'Feature search_filter_by_confidential' do + context 'when disabled' do + before do + stub_feature_flags(search_filter_by_confidential: false) + end + + it 'does not render the confidential drop down' do + render + + expect(rendered).not_to have_selector('#js-search-filter-by-confidential') + end + end + + context 'when enabled' do + it 'renders the confidential drop down' do + render + + expect(rendered).to have_selector('#js-search-filter-by-confidential') + end + end + end end end end diff --git a/spec/views/shared/_label_row.html.haml_spec.rb b/spec/views/shared/_label_row.html.haml_spec.rb index 8f8aa3072e2..e9a0bfdcd4e 100644 --- a/spec/views/shared/_label_row.html.haml_spec.rb +++ b/spec/views/shared/_label_row.html.haml_spec.rb @@ -2,43 +2,126 @@ require 'spec_helper' RSpec.describe 'shared/_label_row.html.haml' do - label_types = { - 'project label': :label, - 'group label': :group_label - } + let_it_be(:group) { create(:group) } + let(:label) { build_stubbed(:group_label, group: group).present(issuable_subject: group) } - label_types.each do |label_type, label_factory| - let!(:label) do - label_record = create(label_factory) # rubocop: disable Rails/SaveBang - label_record.present(issuable_subject: label_record.subject) + before do + allow(view).to receive(:label) { label } + end + + context 'with a project context' do + let_it_be(:project) { create(:project, group: group) } + let(:label) { build_stubbed(:label, project: project).present(issuable_subject: project) } + + before do + assign(:project, label.project) + + render + end + + it 'has label title' do + expect(rendered).to have_text(label.title) + end + + it 'has a non-linked label title' do + expect(rendered).not_to have_link(label.title) + end + + it 'has Issues link' do + expect(rendered).to have_link('Issues') + end + + it 'has Merge request link' do + expect(rendered).to have_link('Merge requests') + end + + it 'shows the path from where the label was created' do + expect(rendered).to have_css('.label-badge', text: project.full_name) + end + end + + context 'with a subgroup context' do + let_it_be(:subgroup) { create(:group, parent: group) } + let(:label) { build_stubbed(:group_label, group: subgroup).present(issuable_subject: subgroup) } + + before do + assign(:group, label.group) + + render + end + + it 'has label title' do + expect(rendered).to have_text(label.title) + end + + it 'has a non-linked label title' do + expect(rendered).not_to have_link(label.title) + end + + it 'has Issues link' do + expect(rendered).to have_link('Issues') + end + + it 'has Merge request link' do + expect(rendered).to have_link('Merge requests') + end + + it 'shows the path from where the label was created' do + expect(rendered).to have_css('.label-badge', text: subgroup.full_name) + end + end + + context 'with a group context' do + before do + assign(:group, label.group) + + render + end + + it 'has label title' do + expect(rendered).to have_text(label.title) + end + + it 'has a non-linked label title' do + expect(rendered).not_to have_link(label.title) + end + + it 'has Issues link' do + expect(rendered).to have_link('Issues') end - context "for a #{label_type}" do - before do - if label.project_label? - @project = label.project - else - @group = label.group - end - end + it 'has Merge request link' do + expect(rendered).to have_link('Merge requests') + end + + it 'does not show a path from where the label was created' do + expect(rendered).not_to have_css('.label-badge') + end + end - it 'has a non-linked label title' do - render 'shared/label_row', label: label + context 'with an admin context' do + before do + render + end - expect(rendered).not_to have_css('a', text: label.title) - end + it 'has label title' do + expect(rendered).to have_text(label.title) + end - it "has Issues link for #{label_type}" do - render 'shared/label_row', label: label + it 'has a non-linked label title' do + expect(rendered).not_to have_link(label.title) + end - expect(rendered).to have_css('a', text: 'Issues') - end + it 'does not show Issues link' do + expect(rendered).not_to have_link('Issues') + end - it "has Merge request link for #{label_type}" do - render 'shared/label_row', label: label + it 'does not show Merge request link' do + expect(rendered).not_to have_link('Merge requests') + end - expect(rendered).to have_css('a', text: 'Merge requests') - end + it 'does not show a path from where the label was created' do + expect(rendered).not_to have_css('.label-badge') end end end diff --git a/spec/views/shared/milestones/_issuables.html.haml_spec.rb b/spec/views/shared/milestones/_issuables.html.haml_spec.rb index 70ab6914580..5eed2c96a45 100644 --- a/spec/views/shared/milestones/_issuables.html.haml_spec.rb +++ b/spec/views/shared/milestones/_issuables.html.haml_spec.rb @@ -6,8 +6,7 @@ RSpec.describe 'shared/milestones/_issuables.html.haml' do let(:issuables_size) { 100 } before do - allow(view).to receive_messages(title: nil, id: nil, show_project_name: nil, - show_full_project_name: nil, dom_class: '', + allow(view).to receive_messages(title: nil, id: nil, show_project_name: nil, dom_class: '', issuables: double(length: issuables_size).as_null_object) stub_template 'shared/milestones/_issuable.html.haml' => '' |