diff options
Diffstat (limited to 'spec/helpers')
22 files changed, 463 insertions, 180 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 05231cc6d09..75377356445 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -278,7 +278,7 @@ describe ApplicationHelper do page: 'application', page_type_id: nil, find_file: nil, - group: '' + group: nil } ) end @@ -317,7 +317,7 @@ describe ApplicationHelper do page: 'application', page_type_id: nil, find_file: nil, - group: '', + group: nil, project_id: project.id, project: project.name, namespace_id: project.namespace.id @@ -325,6 +325,25 @@ describe ApplicationHelper do ) end + context 'when @project is owned by a group' do + let_it_be(:project) { create(:project, :repository, group: create(:group)) } + + it 'includes all possible body data elements and associates the project elements with project' do + expect(helper).to receive(:can?).with(nil, :download_code, project) + expect(helper.body_data).to eq( + { + page: 'application', + page_type_id: nil, + find_file: nil, + group: project.group.name, + project_id: project.id, + project: project.name, + namespace_id: project.namespace.id + } + ) + end + end + context 'when controller is issues' do before do stub_controller_method(:controller_path, 'projects:issues') @@ -342,7 +361,7 @@ describe ApplicationHelper do page: 'projects:issues:show', page_type_id: issue.id, find_file: nil, - group: '', + group: nil, project_id: issue.project.id, project: issue.project.name, namespace_id: issue.project.namespace.id diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index c2f3e26f97b..3fb754f1090 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -123,4 +123,27 @@ describe ApplicationSettingsHelper do end end end + + describe '.storage_weights' do + let(:application_setting) { build(:application_setting) } + + before do + helper.instance_variable_set(:@application_setting, application_setting) + stub_storage_settings({ 'default': {}, 'storage_1': {}, 'storage_2': {} }) + allow(ApplicationSetting).to receive(:repository_storages_weighted_attributes).and_return( + [:repository_storages_weighted_default, + :repository_storages_weighted_storage_1, + :repository_storages_weighted_storage_2]) + + stub_application_setting(repository_storages_weighted: { 'default' => 100, 'storage_1' => 50, 'storage_2' => nil }) + end + + it 'returns storages correctly' do + expect(helper.storage_weights).to eq([ + { name: :repository_storages_weighted_default, label: 'default', value: 100 }, + { name: :repository_storages_weighted_storage_1, label: 'storage_1', value: 50 }, + { name: :repository_storages_weighted_storage_2, label: 'storage_2', value: 0 } + ]) + end + end end diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb index d06548f1595..e0fecb0c159 100644 --- a/spec/helpers/auto_devops_helper_spec.rb +++ b/spec/helpers/auto_devops_helper_spec.rb @@ -13,7 +13,7 @@ describe AutoDevopsHelper do allow(helper).to receive(:can?).with(user, :admin_pipeline, project) { allowed } allow(helper).to receive(:current_user) { user } - Feature.get(:auto_devops_banner_disabled).disable + stub_feature_flags(auto_devops_banner_disabled: false) end subject { helper.show_auto_devops_callout?(project) } @@ -32,7 +32,7 @@ describe AutoDevopsHelper do context 'when the banner is disabled by feature flag' do before do - Feature.get(:auto_devops_banner_disabled).enable + stub_feature_flags(auto_devops_banner_disabled: true) end it { is_expected.to be_falsy } diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb index d40ed2248ce..c41d4f0ede7 100644 --- a/spec/helpers/clusters_helper_spec.rb +++ b/spec/helpers/clusters_helper_spec.rb @@ -59,6 +59,22 @@ describe ClustersHelper do end end + describe '#js_clusters_list_data' do + it 'displays endpoint path and images' do + js_data = helper.js_clusters_list_data('/path') + + expect(js_data[:endpoint]).to eq('/path') + + expect(js_data.dig(:img_tags, :aws, :path)).to match(%r(/illustrations/logos/amazon_eks|svg)) + expect(js_data.dig(:img_tags, :default, :path)).to match(%r(/illustrations/logos/kubernetes|svg)) + expect(js_data.dig(:img_tags, :gcp, :path)).to match(%r(/illustrations/logos/google_gke|svg)) + + expect(js_data.dig(:img_tags, :aws, :text)).to eq('Amazon EKS') + expect(js_data.dig(:img_tags, :default, :text)).to eq('Kubernetes Cluster') + expect(js_data.dig(:img_tags, :gcp, :text)).to eq('Google GKE') + end + end + describe '#provider_icon' do it 'will return GCP logo with gcp argument' do logo = helper.provider_icon('gcp') diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb index 0756e0162a5..48104dfc5a6 100644 --- a/spec/helpers/environments_helper_spec.rb +++ b/spec/helpers/environments_helper_spec.rb @@ -20,6 +20,7 @@ describe EnvironmentsHelper do expect(metrics_data).to include( 'settings-path' => edit_project_service_path(project, 'prometheus'), 'clusters-path' => project_clusters_path(project), + 'metrics-dashboard-base-path' => environment_metrics_path(environment), 'current-environment-name' => environment.name, 'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'), 'empty-getting-started-svg-path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'), @@ -39,7 +40,8 @@ describe EnvironmentsHelper do 'validate-query-path' => validate_query_project_prometheus_metrics_path(project), 'custom-metrics-available' => 'true', 'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), - 'prometheus-alerts-available' => 'true' + 'prometheus-alerts-available' => 'true', + 'custom-dashboard-base-path' => Metrics::Dashboard::CustomDashboardService::DASHBOARD_ROOT ) end diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index 12519390137..6f24308757d 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -150,6 +150,21 @@ describe EventsHelper do expect(helper.event_wiki_page_target_url(event)).to eq(url) end + + context 'there is no canonical slug' do + let(:event) { create(:wiki_page_event, project: project) } + + before do + event.target.slugs.update_all(canonical: false) + event.target.clear_memoization(:canonical_slug) + end + + it 'links to the home page' do + url = helper.project_wiki_url(project, Wiki::HOMEPAGE) + + expect(helper.event_wiki_page_target_url(event)).to eq(url) + end + end end describe '#event_wiki_title_html' do diff --git a/spec/helpers/gitlab_routing_helper_spec.rb b/spec/helpers/gitlab_routing_helper_spec.rb index 1955927e2df..4def04f4284 100644 --- a/spec/helpers/gitlab_routing_helper_spec.rb +++ b/spec/helpers/gitlab_routing_helper_spec.rb @@ -121,6 +121,16 @@ describe GitlabRoutingHelper do it 'matches the Rails download path' do expect(fast_download_project_job_artifacts_path(project, job)).to eq(download_project_job_artifacts_path(project, job)) end + + context 'when given parameters' do + it 'adds them to the path' do + expect( + fast_download_project_job_artifacts_path(project, job, file_type: :dast) + ).to eq( + download_project_job_artifacts_path(project, job, file_type: :dast) + ) + end + end end describe '#fast_keep_project_job_artifacts_path' do @@ -228,5 +238,25 @@ describe GitlabRoutingHelper do expect(gitlab_toggle_award_emoji_snippet_url(personal_snippet)).to eq("http://test.host/snippets/#{personal_snippet.id}/toggle_award_emoji") end end + + describe '#gitlab_dashboard_snippets_path' do + it 'returns the personal snippets dashboard path' do + expect(gitlab_dashboard_snippets_path(personal_snippet)).to eq("/dashboard/snippets") + end + + it 'returns the project snippets dashboard path' do + expect(gitlab_dashboard_snippets_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/snippets") + end + end + end + + context 'wikis' do + let(:wiki) { create(:project_wiki) } + + describe '#wiki_page_path' do + it 'returns the url for the wiki page' do + expect(wiki_page_path(wiki, 'page')).to eq("/#{wiki.project.full_path}/-/wikis/page") + end + end end end diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index dad740d3b80..3ef6745958c 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -7,59 +7,6 @@ describe IssuesHelper do let(:issue) { create :issue, project: project } let(:ext_project) { create :redmine_project } - describe "url_for_issue" do - let(:issues_url) { ext_project.external_issue_tracker.issues_url} - let(:ext_expected) { issues_url.gsub(':id', issue.iid.to_s).gsub(':project_id', ext_project.id.to_s) } - let(:int_expected) { polymorphic_path([@project.namespace, @project, issue]) } - - it "returns internal path if used internal tracker" do - @project = project - - expect(url_for_issue(issue.iid)).to match(int_expected) - end - - it "returns path to external tracker" do - @project = ext_project - - expect(url_for_issue(issue.iid)).to match(ext_expected) - end - - it "returns path to internal issue when internal option passed" do - @project = ext_project - - expect(url_for_issue(issue.iid, ext_project, internal: true)).to match(int_expected) - end - - it "returns empty string if project nil" do - @project = nil - - expect(url_for_issue(issue.iid)).to eq "" - end - - it 'returns an empty string if issue_url is invalid' do - expect(project).to receive_message_chain('issues_tracker.issue_url') { 'javascript:alert("foo");' } - - expect(url_for_issue(issue.iid, project)).to eq '' - end - - it 'returns an empty string if issue_path is invalid' do - expect(project).to receive_message_chain('issues_tracker.issue_path') { 'javascript:alert("foo");' } - - expect(url_for_issue(issue.iid, project, only_path: true)).to eq '' - end - - describe "when external tracker was enabled and then config removed" do - before do - @project = ext_project - allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) - end - - it "returns external path" do - expect(url_for_issue(issue.iid)).to match(ext_expected) - end - end - end - describe '#award_user_list' do it "returns a comma-separated list of the first X users" do user = build_stubbed(:user, name: 'Joe') diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index b2df543d651..1fc79a9762a 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -317,7 +317,7 @@ describe MarkupHelper do let(:wiki_repository) { double('Repository') } let(:context) do { - pipeline: :wiki, project: project, project_wiki: wiki, + pipeline: :wiki, project: project, wiki: wiki, page_slug: 'nested/page', issuable_state_filter_enabled: true, repository: wiki_repository } @@ -327,7 +327,7 @@ describe MarkupHelper do expect(wiki).to receive(:content).and_return('wiki content') expect(wiki).to receive(:slug).and_return('nested/page') expect(wiki).to receive(:repository).and_return(wiki_repository) - helper.instance_variable_set(:@project_wiki, wiki) + helper.instance_variable_set(:@wiki, wiki) end context 'when file is Markdown' do diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 36465069311..ebce296d7c2 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -174,4 +174,96 @@ describe NamespacesHelper do end end end + + describe '#namespace_storage_alert' do + subject { helper.namespace_storage_alert(namespace) } + + let(:namespace) { build(:namespace) } + + let(:payload) do + { + alert_level: :info, + usage_message: "Usage", + explanation_message: "Explanation", + root_namespace: namespace + } + end + + before do + allow(helper).to receive(:current_user).and_return(admin) + allow_next_instance_of(Namespaces::CheckStorageSizeService, namespace, admin) do |check_storage_size_service| + expect(check_storage_size_service).to receive(:execute).and_return(ServiceResponse.success(payload: payload)) + end + end + + context 'when payload is not empty and no cookie is set' do + it { is_expected.to eq(payload) } + end + + context 'when there is no current_user' do + before do + allow(helper).to receive(:current_user).and_return(nil) + end + + it { is_expected.to eq({}) } + end + + context 'when payload is empty' do + let(:payload) { {} } + + it { is_expected.to eq({}) } + end + + context 'when cookie is set' do + before do + helper.request.cookies["hide_storage_limit_alert_#{namespace.id}_info"] = 'true' + end + + it { is_expected.to eq({}) } + end + + context 'when payload is empty and cookie is set' do + let(:payload) { {} } + + before do + helper.request.cookies["hide_storage_limit_alert_#{namespace.id}_info"] = 'true' + end + + it { is_expected.to eq({}) } + end + end + + describe '#namespace_storage_alert_style' do + using RSpec::Parameterized::TableSyntax + + subject { helper.namespace_storage_alert_style(alert_level) } + + where(:alert_level, :result) do + :info | 'info' + :warning | 'warning' + :error | 'danger' + :alert | 'danger' + end + + with_them do + it { is_expected.to eq(result) } + end + end + + describe '#namespace_storage_alert_icon' do + using RSpec::Parameterized::TableSyntax + + subject { helper.namespace_storage_alert_icon(alert_level) } + + where(:alert_level, :result) do + :info | 'information-o' + :warning | 'warning' + :error | 'error' + :alert | 'error' + end + + with_them do + it { is_expected.to eq(result) } + end + end end diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index f074a918e7f..543a9081779 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -24,6 +24,36 @@ describe NotesHelper do project.add_guest(guest) end + describe '#note_target_title' do + context 'note does not exist' do + it 'returns nil' do + expect(helper.note_target_title(nil)).to be_blank + end + end + + context 'target does not exist' do + it 'returns nil' do + note = Note.new + expect(helper.note_target_title(note)).to be_blank + end + end + + context 'when given a design target' do + it 'returns nil' do + note = build_stubbed(:note_on_design) + expect(helper.note_target_title(note)).to be_blank + end + end + + context 'when given a non-design target' do + it 'returns the issue title' do + issue = build_stubbed(:issue, title: 'Issue 1') + note = build_stubbed(:note, noteable: issue) + expect(helper.note_target_title(note)).to eq('Issue 1') + end + end + end + describe "#notes_max_access_for_users" do it 'returns access levels' do expect(helper.note_max_access_for_user(owner_note)).to eq(Gitlab::Access::OWNER) diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb index 7e851a1af01..55f743ac683 100644 --- a/spec/helpers/page_layout_helper_spec.rb +++ b/spec/helpers/page_layout_helper_spec.rb @@ -117,4 +117,19 @@ describe PageLayoutHelper do expect(tags).to include(%q{content="foo" http-equiv="refresh"}) end end + + describe '#search_context' do + subject(:search_context) { helper.search_context } + + describe 'a bare controller' do + it 'returns an empty context' do + expect(search_context).to have_attributes(project: nil, + group: nil, + snippets: [], + project_metadata: {}, + group_metadata: {}, + search_url: '/search') + end + end + end end diff --git a/spec/helpers/projects/alert_management_helper_spec.rb b/spec/helpers/projects/alert_management_helper_spec.rb index 078759de39c..49b64b316e7 100644 --- a/spec/helpers/projects/alert_management_helper_spec.rb +++ b/spec/helpers/projects/alert_management_helper_spec.rb @@ -69,13 +69,13 @@ describe Projects::AlertManagementHelper do describe '#alert_management_detail_data' do let(:alert_id) { 1 } - let(:new_issue_path) { new_project_issue_path(project) } + let(:issues_path) { project_issues_path(project) } it 'returns detail page configuration' do expect(helper.alert_management_detail_data(project, alert_id)).to eq( 'alert-id' => alert_id, 'project-path' => project_path, - 'new-issue-path' => new_issue_path + 'project-issues-path' => issues_path ) end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 189ab1a8354..4e072f02ae0 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -5,6 +5,9 @@ require 'spec_helper' describe ProjectsHelper do include ProjectForksHelper + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + describe '#project_incident_management_setting' do let(:project) { create(:project) } @@ -29,8 +32,8 @@ describe ProjectsHelper do setting = helper.project_incident_management_setting expect(setting).not_to be_persisted + expect(setting.create_issue).to be_falsey expect(setting.send_email).to be_falsey - expect(setting.create_issue).to be_truthy expect(setting.issue_template_key).to be_nil end end @@ -500,6 +503,23 @@ describe ProjectsHelper do end end + describe '#can_view_operations_tab?' do + before do + allow(helper).to receive(:current_user).and_return(user) + end + + subject { helper.send(:can_view_operations_tab?, user, project) } + + [:read_environment, :read_cluster, :metrics_dashboard].each do |ability| + it 'includes operations tab' do + allow(helper).to receive(:can?).and_return(false) + allow(helper).to receive(:can?).with(user, ability, project).and_return(true) + + is_expected.to be(true) + end + end + end + describe '#show_projects' do let(:projects) do create(:project) @@ -665,11 +685,11 @@ describe ProjectsHelper do end end - describe 'link_to_bfg' do - subject { helper.link_to_bfg } + describe 'link_to_filter_repo' do + subject { helper.link_to_filter_repo } - it 'generates a hardcoded link to the BFG Repo-Cleaner' do - result = helper.link_to_bfg + it 'generates a hardcoded link to git filter-repo' do + result = helper.link_to_filter_repo doc = Nokogiri::HTML.fragment(result) expect(doc.children.size).to eq(1) @@ -682,8 +702,8 @@ describe ProjectsHelper do expect(link.name).to eq('a') expect(link[:target]).to eq('_blank') expect(link[:rel]).to eq('noopener noreferrer') - expect(link[:href]).to eq('https://rtyley.github.io/bfg-repo-cleaner/') - expect(link.inner_html).to eq('BFG') + expect(link[:href]).to eq('https://github.com/newren/git-filter-repo') + expect(link.inner_html).to eq('git filter-repo') expect(result).to be_html_safe end diff --git a/spec/helpers/recaptcha_experiment_helper_spec.rb b/spec/helpers/recaptcha_experiment_helper_spec.rb index 775c2caa082..a5b233e28a0 100644 --- a/spec/helpers/recaptcha_experiment_helper_spec.rb +++ b/spec/helpers/recaptcha_experiment_helper_spec.rb @@ -3,6 +3,12 @@ require 'spec_helper' describe RecaptchaExperimentHelper, type: :helper do + let(:session) { {} } + + before do + allow(helper).to receive(:session) { session } + end + describe '.show_recaptcha_sign_up?' do context 'when reCAPTCHA is disabled' do it 'returns false' do diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 6a06b012c6c..b209ed869bf 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -8,99 +8,6 @@ describe SearchHelper do str end - describe 'search_autocomplete_opts' do - context "with no current user" do - before do - allow(self).to receive(:current_user).and_return(nil) - end - - it "returns nil" do - expect(search_autocomplete_opts("q")).to be_nil - end - end - - context "with a standard user" do - let(:user) { create(:user) } - - before do - allow(self).to receive(:current_user).and_return(user) - end - - it "includes Help sections" do - expect(search_autocomplete_opts("hel").size).to eq(9) - end - - it "includes default sections" do - expect(search_autocomplete_opts("dash").size).to eq(1) - end - - it "does not include admin sections" do - expect(search_autocomplete_opts("admin").size).to eq(0) - end - - it "does not allow regular expression in search term" do - expect(search_autocomplete_opts("(webhooks|api)").size).to eq(0) - end - - it "includes the user's groups" do - create(:group).add_owner(user) - expect(search_autocomplete_opts("gro").size).to eq(1) - end - - it "includes nested group" do - create(:group, :nested, name: 'foo').add_owner(user) - expect(search_autocomplete_opts('foo').size).to eq(1) - end - - it "includes the user's projects" do - project = create(:project, namespace: create(:namespace, owner: user)) - expect(search_autocomplete_opts(project.name).size).to eq(1) - end - - it "includes the required project attrs" do - project = create(:project, namespace: create(:namespace, owner: user)) - result = search_autocomplete_opts(project.name).first - - expect(result.keys).to match_array(%i[category id value label url avatar_url]) - end - - it "includes the required group attrs" do - create(:group).add_owner(user) - result = search_autocomplete_opts("gro").first - - expect(result.keys).to match_array(%i[category id label url avatar_url]) - end - - it "does not include the public group" do - group = create(:group) - expect(search_autocomplete_opts(group.name).size).to eq(0) - end - - context "with a current project" do - before do - @project = create(:project, :repository) - end - - it "includes project-specific sections" do - expect(search_autocomplete_opts("Files").size).to eq(1) - expect(search_autocomplete_opts("Commits").size).to eq(1) - end - end - end - - context 'with an admin user' do - let(:admin) { create(:admin) } - - before do - allow(self).to receive(:current_user).and_return(admin) - end - - it "includes admin sections" do - expect(search_autocomplete_opts("admin").size).to eq(1) - end - end - end - describe 'search_entries_info' do using RSpec::Parameterized::TableSyntax diff --git a/spec/helpers/subscribable_banner_helper_spec.rb b/spec/helpers/subscribable_banner_helper_spec.rb new file mode 100644 index 00000000000..75f2e32d7d8 --- /dev/null +++ b/spec/helpers/subscribable_banner_helper_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe SubscribableBannerHelper do + describe '#display_subscription_banner!' do + it 'is over-written in EE' do + expect { helper.display_subscription_banner! }.not_to raise_error + end + end +end diff --git a/spec/helpers/milestones_helper_spec.rb b/spec/helpers/timeboxes_helper_spec.rb index 4ce7143bdf0..6fe738914ce 100644 --- a/spec/helpers/milestones_helper_spec.rb +++ b/spec/helpers/timeboxes_helper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MilestonesHelper do +describe TimeboxesHelper do describe '#milestones_filter_dropdown_path' do let(:project) { create(:project) } let(:project2) { create(:project) } @@ -39,23 +39,34 @@ describe MilestonesHelper do end end - describe "#milestone_date_range" do - def result_for(*args) - milestone_date_range(build(:milestone, *args)) - end - + describe "#timebox_date_range" do let(:yesterday) { Date.yesterday } let(:tomorrow) { yesterday + 2 } let(:format) { '%b %-d, %Y' } let(:yesterday_formatted) { yesterday.strftime(format) } let(:tomorrow_formatted) { tomorrow.strftime(format) } - it { expect(result_for(due_date: nil, start_date: nil)).to be_nil } - it { expect(result_for(due_date: tomorrow)).to eq("expires on #{tomorrow_formatted}") } - it { expect(result_for(due_date: yesterday)).to eq("expired on #{yesterday_formatted}") } - it { expect(result_for(start_date: tomorrow)).to eq("starts on #{tomorrow_formatted}") } - it { expect(result_for(start_date: yesterday)).to eq("started on #{yesterday_formatted}") } - it { expect(result_for(start_date: yesterday, due_date: tomorrow)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}") } + context 'milestone' do + def result_for(*args) + timebox_date_range(build(:milestone, *args)) + end + + it { expect(result_for(due_date: nil, start_date: nil)).to be_nil } + it { expect(result_for(due_date: tomorrow)).to eq("expires on #{tomorrow_formatted}") } + it { expect(result_for(due_date: yesterday)).to eq("expired on #{yesterday_formatted}") } + it { expect(result_for(start_date: tomorrow)).to eq("starts on #{tomorrow_formatted}") } + it { expect(result_for(start_date: yesterday)).to eq("started on #{yesterday_formatted}") } + it { expect(result_for(start_date: yesterday, due_date: tomorrow)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}") } + end + + context 'iteration' do + # Iterations always have start and due dates, so only A-B format is expected + it 'formats properly' do + iteration = build(:iteration, start_date: yesterday, due_date: tomorrow) + + expect(timebox_date_range(iteration)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}") + end + end end describe '#milestone_counts' do diff --git a/spec/helpers/milestones_routing_helper_spec.rb b/spec/helpers/timeboxes_routing_helper_spec.rb index 4da589a5007..1b0eb2c0ad2 100644 --- a/spec/helpers/milestones_routing_helper_spec.rb +++ b/spec/helpers/timeboxes_routing_helper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MilestonesRoutingHelper do +describe TimeboxesRoutingHelper do let(:project) { build_stubbed(:project) } let(:group) { build_stubbed(:group) } diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb index b09e1e2b83b..0811c2af891 100644 --- a/spec/helpers/todos_helper_spec.rb +++ b/spec/helpers/todos_helper_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' describe TodosHelper do let_it_be(:user) { create(:user) } let_it_be(:author) { create(:user) } - let_it_be(:issue) { create(:issue) } + let_it_be(:issue) { create(:issue, title: 'Issue 1') } let_it_be(:design) { create(:design, issue: issue) } let_it_be(:note) do create(:note, @@ -20,6 +20,10 @@ describe TodosHelper do author: author, note: note) end + let_it_be(:alert_todo) do + alert = create(:alert_management_alert, iid: 1001) + create(:todo, target: alert) + end describe '#todos_count_format' do it 'shows fuzzy count for 100 or more items' do @@ -68,6 +72,41 @@ describe TodosHelper do end end + describe '#todo_target_title' do + context 'when the target does not exist' do + let(:todo) { double('Todo', target: nil) } + + it 'returns an empty string' do + title = helper.todo_target_title(todo) + expect(title).to eq("") + end + end + + context 'when given a design todo' do + let(:todo) { design_todo } + + it 'returns an empty string' do + title = helper.todo_target_title(todo) + expect(title).to eq("") + end + end + + context 'when given a non-design todo' do + let(:todo) do + build_stubbed(:todo, :assigned, + user: user, + project: issue.project, + target: issue, + author: author) + end + + it 'returns the title' do + title = helper.todo_target_title(todo) + expect(title).to eq("\"Issue 1\"") + end + end + end + describe '#todo_target_path' do context 'when given a design' do let(:todo) { design_todo } @@ -80,6 +119,18 @@ describe TodosHelper do expect(path).to eq("#{issue_path}/designs/#{design.filename}##{dom_id(design_todo.note)}") end end + + context 'when given an alert' do + let(:todo) { alert_todo } + + it 'responds with an appropriate path' do + path = helper.todo_target_path(todo) + + expect(path).to eq( + "/#{todo.project.full_path}/-/alert_management/#{todo.target.iid}/details" + ) + end + end end describe '#todo_target_type_name' do @@ -92,6 +143,16 @@ describe TodosHelper do expect(name).to eq('design') end end + + context 'when given an alert todo' do + let(:todo) { alert_todo } + + it 'responds with an appropriate target type name' do + name = helper.todo_target_type_name(todo) + + expect(name).to eq('alert') + end + end end describe '#todo_types_options' do diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb index b7a88ee5010..3b4d82c65ac 100644 --- a/spec/helpers/visibility_level_helper_spec.rb +++ b/spec/helpers/visibility_level_helper_spec.rb @@ -184,6 +184,84 @@ describe VisibilityLevelHelper do end end + shared_examples_for 'available visibility level' do + using RSpec::Parameterized::TableSyntax + + let(:user) { create(:user) } + + subject { helper.available_visibility_levels(form_model) } + + public_vis = Gitlab::VisibilityLevel::PUBLIC + internal_vis = Gitlab::VisibilityLevel::INTERNAL + private_vis = Gitlab::VisibilityLevel::PRIVATE + + where(:restricted_visibility_levels, :expected) do + [] | [private_vis, internal_vis, public_vis] + [private_vis] | [internal_vis, public_vis] + [private_vis, internal_vis] | [public_vis] + [private_vis, public_vis] | [internal_vis] + [internal_vis] | [private_vis, public_vis] + [internal_vis, private_vis] | [public_vis] + [internal_vis, public_vis] | [private_vis] + [public_vis] | [private_vis, internal_vis] + [public_vis, private_vis] | [internal_vis] + [public_vis, internal_vis] | [private_vis] + end + + before do + allow(helper).to receive(:current_user) { user } + end + + with_them do + before do + stub_application_setting(restricted_visibility_levels: restricted_visibility_levels) + end + + it { is_expected.to eq(expected) } + end + + it 'excludes disallowed visibility levels' do + stub_application_setting(restricted_visibility_levels: []) + allow(helper).to receive(:disallowed_visibility_level?).with(form_model, private_vis) { true } + allow(helper).to receive(:disallowed_visibility_level?).with(form_model, internal_vis) { false } + allow(helper).to receive(:disallowed_visibility_level?).with(form_model, public_vis) { false } + + expect(subject).to eq([internal_vis, public_vis]) + end + end + + describe '#available_visibility_levels' do + it_behaves_like 'available visibility level' do + let(:form_model) { project_snippet } + end + + it_behaves_like 'available visibility level' do + let(:form_model) { personal_snippet } + end + + it_behaves_like 'available visibility level' do + let(:form_model) { project } + end + + it_behaves_like 'available visibility level' do + let(:form_model) { group } + end + end + + describe '#snippets_selected_visibility_level' do + let(:available_levels) { [Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL] } + + it 'returns the selected visibility level' do + expect(helper.snippets_selected_visibility_level(available_levels, Gitlab::VisibilityLevel::PUBLIC)) + .to eq(Gitlab::VisibilityLevel::PUBLIC) + end + + it "fallbacks using the lowest available visibility level when selected level isn't available" do + expect(helper.snippets_selected_visibility_level(available_levels, Gitlab::VisibilityLevel::PRIVATE)) + .to eq(Gitlab::VisibilityLevel::INTERNAL) + end + end + describe 'multiple_visibility_levels_restricted?' do using RSpec::Parameterized::TableSyntax diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb index 1aab01281c6..4b53823aaed 100644 --- a/spec/helpers/wiki_helper_spec.rb +++ b/spec/helpers/wiki_helper_spec.rb @@ -22,12 +22,12 @@ describe WikiHelper do end describe '#wiki_sort_controls' do - let(:project) { create(:project) } - let(:wiki_link) { helper.wiki_sort_controls(project, sort, direction) } + let(:wiki) { create(:project_wiki) } + let(:wiki_link) { helper.wiki_sort_controls(wiki, sort, direction) } let(:classes) { "btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort" } def expected_link(sort, direction, icon_class) - path = "/#{project.full_path}/-/wikis/pages?direction=#{direction}&sort=#{sort}" + path = "/#{wiki.project.full_path}/-/wikis/pages?direction=#{direction}&sort=#{sort}" helper.link_to(path, type: 'button', class: classes, title: 'Sort direction') do helper.sprite_icon("sort-#{icon_class}", size: 16) |