diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/presenters | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/alert_management/alert_presenter_spec.rb | 25 | ||||
-rw-r--r-- | spec/presenters/alert_management/prometheus_alert_presenter_spec.rb | 23 | ||||
-rw-r--r-- | spec/presenters/blob_presenter_spec.rb | 11 | ||||
-rw-r--r-- | spec/presenters/clusters/cluster_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/commit_presenter_spec.rb | 4 | ||||
-rw-r--r-- | spec/presenters/event_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/packages/detail/package_presenter_spec.rb | 45 | ||||
-rw-r--r-- | spec/presenters/project_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/projects/prometheus/alert_presenter_spec.rb | 13 | ||||
-rw-r--r-- | spec/presenters/prometheus_alert_presenter_spec.rb | 32 | ||||
-rw-r--r-- | spec/presenters/snippet_blob_presenter_spec.rb | 77 | ||||
-rw-r--r-- | spec/presenters/snippet_presenter_spec.rb | 8 | ||||
-rw-r--r-- | spec/presenters/tree_entry_presenter_spec.rb | 4 | ||||
-rw-r--r-- | spec/presenters/user_presenter_spec.rb | 16 |
14 files changed, 221 insertions, 43 deletions
diff --git a/spec/presenters/alert_management/alert_presenter_spec.rb b/spec/presenters/alert_management/alert_presenter_spec.rb index b1bf7029f3e..394007a802f 100644 --- a/spec/presenters/alert_management/alert_presenter_spec.rb +++ b/spec/presenters/alert_management/alert_presenter_spec.rb @@ -4,17 +4,22 @@ require 'spec_helper' RSpec.describe AlertManagement::AlertPresenter do let_it_be(:project) { create(:project) } + let_it_be(:generic_payload) do { 'title' => 'Alert title', 'start_time' => '2020-04-27T10:10:22.265949279Z', - 'custom' => { 'param' => 73 } + 'custom' => { 'param' => 73 }, + 'runbook' => 'https://runbook.com' } end + let_it_be(:alert) do create(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: generic_payload) end + let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" } + subject(:presenter) { described_class.new(alert) } describe '#issue_description' do @@ -30,11 +35,13 @@ RSpec.describe AlertManagement::AlertPresenter do **Service:** #{alert.service}#{markdown_line_break} **Monitoring tool:** #{alert.monitoring_tool}#{markdown_line_break} **Hosts:** #{alert.hosts.join(' ')}#{markdown_line_break} - **Description:** #{alert.description} + **Description:** #{alert.description}#{markdown_line_break} + **GitLab alert:** #{alert_url} #### Alert Details - **custom.param:** 73 + **custom.param:** 73#{markdown_line_break} + **runbook:** https://runbook.com MARKDOWN ) end @@ -45,4 +52,16 @@ RSpec.describe AlertManagement::AlertPresenter do expect(presenter.metrics_dashboard_url).to be_nil end end + + describe '#runbook' do + it 'shows the runbook from the payload' do + expect(presenter.runbook).to eq('https://runbook.com') + end + end + + describe '#details_url' do + it 'returns the details URL' do + expect(presenter.details_url).to match(%r{#{project.web_url}/-/alert_management/#{alert.iid}/details}) + end + end end diff --git a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb b/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb index 95246914140..3cfff3c1b2f 100644 --- a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb +++ b/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe AlertManagement::PrometheusAlertPresenter do let_it_be(:project) { create(:project) } - let_it_be(:payload) do + let(:payload) do { 'annotations' => { 'title' => 'Alert title', @@ -15,10 +15,13 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do 'generatorURL' => 'http://8d467bd4607a:9090/graph?g0.expr=vector%281%29&g0.tab=1' } end - let(:alert) do + + let!(:alert) do create(:alert_management_alert, :prometheus, project: project, payload: payload) end + let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" } + subject(:presenter) { described_class.new(alert) } describe '#issue_description' do @@ -32,7 +35,8 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do **Start time:** #{presenter.start_time}#{markdown_line_break} **Severity:** #{presenter.severity}#{markdown_line_break} **full_query:** `vector(1)`#{markdown_line_break} - **Monitoring tool:** Prometheus + **Monitoring tool:** Prometheus#{markdown_line_break} + **GitLab alert:** #{alert_url} #### Alert Details @@ -65,4 +69,17 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do it { is_expected.to eq(dashboard_url_for_alert) } end end + + describe '#runbook' do + subject { presenter.runbook } + + it { is_expected.to be_nil } + + context 'with runbook in payload' do + let(:expected_runbook) { 'https://awesome-runbook.com' } + let(:payload) { { 'annotations' => { 'runbook' => expected_runbook } } } + + it { is_expected.to eq(expected_runbook) } + end + end end diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb index bf926ce62b3..47402fea2b5 100644 --- a/spec/presenters/blob_presenter_spec.rb +++ b/spec/presenters/blob_presenter_spec.rb @@ -12,6 +12,7 @@ RSpec.describe BlobPresenter, :seed_helper do 'files/ruby/regex.rb' ) end + let(:blob) { Blob.new(git_blob) } describe '.web_url' do @@ -24,6 +25,16 @@ RSpec.describe BlobPresenter, :seed_helper do it { expect(subject.web_url).to eq("http://localhost/#{project.full_path}/-/blob/#{blob.commit_id}/#{blob.path}") } end + describe '#web_path' do + let(:project) { create(:project, :repository) } + let(:repository) { project.repository } + let(:blob) { Gitlab::Graphql::Representation::TreeEntry.new(repository.tree.blobs.first, repository) } + + subject { described_class.new(blob) } + + it { expect(subject.web_path).to eq("/#{project.full_path}/-/blob/#{blob.commit_id}/#{blob.path}") } + end + describe '#highlight' do subject { described_class.new(blob) } diff --git a/spec/presenters/clusters/cluster_presenter_spec.rb b/spec/presenters/clusters/cluster_presenter_spec.rb index 5b75b281297..e99b04fda8d 100644 --- a/spec/presenters/clusters/cluster_presenter_spec.rb +++ b/spec/presenters/clusters/cluster_presenter_spec.rb @@ -265,7 +265,7 @@ RSpec.describe Clusters::ClusterPresenter do is_expected.to include('clusters-path': clusterable_presenter.index_path, 'dashboard-endpoint': clusterable_presenter.metrics_dashboard_path(cluster), 'documentation-path': help_page_path('user/project/clusters/index', anchor: 'monitoring-your-kubernetes-cluster-ultimate'), - 'add-dashboard-documentation-path': help_page_path('user/project/integrations/prometheus.md', anchor: 'adding-a-new-dashboard-to-your-project'), + 'add-dashboard-documentation-path': help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), 'empty-getting-started-svg-path': match_asset_path('/assets/illustrations/monitoring/getting_started.svg'), 'empty-loading-svg-path': match_asset_path('/assets/illustrations/monitoring/loading.svg'), 'empty-no-data-svg-path': match_asset_path('/assets/illustrations/monitoring/no_data.svg'), diff --git a/spec/presenters/commit_presenter_spec.rb b/spec/presenters/commit_presenter_spec.rb index bc6be07f415..b221c9ca8f7 100644 --- a/spec/presenters/commit_presenter_spec.rb +++ b/spec/presenters/commit_presenter_spec.rb @@ -8,6 +8,10 @@ RSpec.describe CommitPresenter do let(:user) { create(:user) } let(:presenter) { described_class.new(commit, current_user: user) } + describe '#web_path' do + it { expect(presenter.web_path).to eq("/#{project.full_path}/-/commit/#{commit.sha}") } + end + describe '#status_for' do subject { presenter.status_for('ref') } diff --git a/spec/presenters/event_presenter_spec.rb b/spec/presenters/event_presenter_spec.rb index 2d4872ea29e..6798be21d28 100644 --- a/spec/presenters/event_presenter_spec.rb +++ b/spec/presenters/event_presenter_spec.rb @@ -35,7 +35,7 @@ RSpec.describe EventPresenter do context 'with project label' do subject { project_event.present.target_link_options } - it { is_expected.to eq([group.becomes(Namespace), project, target]) } + it { is_expected.to eq([project, target]) } end end end diff --git a/spec/presenters/packages/detail/package_presenter_spec.rb b/spec/presenters/packages/detail/package_presenter_spec.rb index 34582957364..3a13aca6c7a 100644 --- a/spec/presenters/packages/detail/package_presenter_spec.rb +++ b/spec/presenters/packages/detail/package_presenter_spec.rb @@ -9,15 +9,18 @@ RSpec.describe ::Packages::Detail::PackagePresenter do let(:presenter) { described_class.new(package) } let_it_be(:user_info) { { name: user.name, avatar_url: user.avatar_url } } + let!(:expected_package_files) do - npm_file = package.package_files.first - [{ - created_at: npm_file.created_at, - download_path: npm_file.download_path, - file_name: npm_file.file_name, - size: npm_file.size - }] + package.package_files.map do |file| + { + created_at: file.created_at, + download_path: file.download_path, + file_name: file.file_name, + size: file.size + } + end end + let(:pipeline_info) do pipeline = package.build_info.pipeline { @@ -29,11 +32,15 @@ RSpec.describe ::Packages::Detail::PackagePresenter do user: user_info, project: { name: pipeline.project.name, - web_url: pipeline.project.web_url + web_url: pipeline.project.web_url, + pipeline_url: include("pipelines/#{pipeline.id}"), + commit_url: include("commit/#{pipeline.sha}") } } end + let!(:dependency_links) { [] } + let!(:expected_package_details) do { id: package.id, @@ -55,7 +62,7 @@ RSpec.describe ::Packages::Detail::PackagePresenter do let(:expected_package_details) { super().merge(pipeline: pipeline_info) } it 'returns details with pipeline' do - expect(presenter.detail_view).to eq expected_package_details + expect(presenter.detail_view).to match expected_package_details end end @@ -67,6 +74,24 @@ RSpec.describe ::Packages::Detail::PackagePresenter do end end + context 'with conan metadata' do + let(:package) { create(:conan_package, project: project) } + let(:expected_package_details) { super().merge(conan_metadatum: package.conan_metadatum) } + + it 'returns conan_metadatum' do + expect(presenter.detail_view).to eq expected_package_details + end + end + + context 'with composer metadata' do + let(:package) { create(:composer_package, :with_metadatum, sha: '123', project: project) } + let(:expected_package_details) { super().merge(composer_metadatum: package.composer_metadatum) } + + it 'returns composer_metadatum' do + expect(presenter.detail_view).to eq expected_package_details + end + end + context 'with nuget_metadatum' do let_it_be(:package) { create(:nuget_package, project: project) } let_it_be(:nuget_metadatum) { create(:nuget_metadatum, package: package) } @@ -81,6 +106,7 @@ RSpec.describe ::Packages::Detail::PackagePresenter do let_it_be(:package) { create(:nuget_package, project: project) } let_it_be(:dependency_link) { create(:packages_dependency_link, package: package) } let_it_be(:nuget_dependency) { create(:nuget_dependency_link_metadatum, dependency_link: dependency_link) } + let_it_be(:expected_link) do { name: dependency_link.dependency.name, @@ -88,6 +114,7 @@ RSpec.describe ::Packages::Detail::PackagePresenter do target_framework: nuget_dependency.target_framework } end + let_it_be(:dependency_links) { [expected_link] } it 'returns the correct dependency link' do diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index eb1ff628d14..4b4d8ee85db 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -525,7 +525,7 @@ RSpec.describe ProjectPresenter do end describe '#statistics_buttons' do - let(:project) { build(:project) } + let(:project) { build_stubbed(:project) } it 'orders the items correctly' do allow(project.repository).to receive(:readme).and_return(double(name: 'readme')) diff --git a/spec/presenters/projects/prometheus/alert_presenter_spec.rb b/spec/presenters/projects/prometheus/alert_presenter_spec.rb index 89c5438b074..2d58a7f2cfa 100644 --- a/spec/presenters/projects/prometheus/alert_presenter_spec.rb +++ b/spec/presenters/projects/prometheus/alert_presenter_spec.rb @@ -293,6 +293,19 @@ RSpec.describe Projects::Prometheus::AlertPresenter do end end + describe '#details_url' do + subject { presenter.details_url } + + it { is_expected.to eq(nil) } + + context 'alert management alert present' do + let_it_be(:am_alert) { create(:alert_management_alert, project: project) } + let(:alert) { create(:alerting_alert, project: project, payload: payload, am_alert: am_alert) } + + it { is_expected.to eq("http://localhost/#{project.full_path}/-/alert_management/#{am_alert.iid}/details") } + end + end + context 'with gitlab alert' do include_context 'gitlab alert' diff --git a/spec/presenters/prometheus_alert_presenter_spec.rb b/spec/presenters/prometheus_alert_presenter_spec.rb new file mode 100644 index 00000000000..b9f18e2be28 --- /dev/null +++ b/spec/presenters/prometheus_alert_presenter_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe PrometheusAlertPresenter do + let_it_be(:project) { create(:project) } + let_it_be(:environment) { create(:environment, project: project) } + + let(:presenter) { described_class.new(prometheus_alert) } + + describe '#humanized_text' do + subject { presenter.humanized_text } + + let_it_be(:prometheus_metric) { create(:prometheus_metric, project: project) } + let(:prometheus_alert) { create(:prometheus_alert, operator: operator, project: project, environment: environment, prometheus_metric: prometheus_metric) } + let(:operator) { :gt } + + it { is_expected.to eq('exceeded 1.0m/s') } + + context 'when operator is eq' do + let(:operator) { :eq } + + it { is_expected.to eq('is equal to 1.0m/s') } + end + + context 'when operator is lt' do + let(:operator) { :lt } + + it { is_expected.to eq('is less than 1.0m/s') } + end + end +end diff --git a/spec/presenters/snippet_blob_presenter_spec.rb b/spec/presenters/snippet_blob_presenter_spec.rb index 7464c0ac15b..915f43fe572 100644 --- a/spec/presenters/snippet_blob_presenter_spec.rb +++ b/spec/presenters/snippet_blob_presenter_spec.rb @@ -13,13 +13,14 @@ RSpec.describe SnippetBlobPresenter do subject { described_class.new(snippet.blob).rich_data } context 'with PersonalSnippet' do - let(:raw_url) { "http://127.0.0.1:3000/snippets/#{snippet.id}/raw" } - let(:snippet) { build(:personal_snippet) } + let(:snippet) { create(:personal_snippet, :repository) } - it 'returns nil when the snippet blob is binary' do - allow(snippet.blob).to receive(:binary?).and_return(true) + context 'when blob is binary' do + it 'returns the HTML associated with the binary' do + allow(snippet).to receive(:blob).and_return(snippet.repository.blob_at('master', 'files/images/logo-black.png')) - expect(subject).to be_nil + expect(subject).to include('file-content image_file') + end end context 'with markdown format' do @@ -40,7 +41,7 @@ RSpec.describe SnippetBlobPresenter do let(:snippet) { create(:personal_snippet, file_name: 'test.ipynb') } it 'returns rich notebook content' do - expect(subject.strip).to eq %Q(<div class="file-content" data-endpoint="/snippets/#{snippet.id}/raw" id="js-notebook-viewer"></div>) + expect(subject.strip).to eq %Q(<div class="file-content" data-endpoint="/-/snippets/#{snippet.id}/raw" id="js-notebook-viewer"></div>) end end @@ -48,7 +49,7 @@ RSpec.describe SnippetBlobPresenter do let(:snippet) { create(:personal_snippet, file_name: 'openapi.yml') } it 'returns rich openapi content' do - expect(subject).to eq %Q(<div class="file-content" data-endpoint="/snippets/#{snippet.id}/raw" id="js-openapi-viewer"></div>\n) + expect(subject).to eq %Q(<div class="file-content" data-endpoint="/-/snippets/#{snippet.id}/raw" id="js-openapi-viewer"></div>\n) end end @@ -108,7 +109,7 @@ RSpec.describe SnippetBlobPresenter do end end - describe '#raw_path' do + describe 'route helpers' do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) } @@ -118,28 +119,62 @@ RSpec.describe SnippetBlobPresenter do project.add_developer(user) end - subject { described_class.new(snippet.blobs.first, current_user: user).raw_path } + describe '#raw_path' do + subject { described_class.new(snippet.blobs.first, current_user: user).raw_path } + + it_behaves_like 'snippet blob raw path' + + context 'with snippet_multiple_files feature disabled' do + before do + stub_feature_flags(snippet_multiple_files: false) + end + + context 'with ProjectSnippet' do + let(:snippet) { project_snippet } + + it 'returns the raw path' do + expect(subject).to eq "/#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw" + end + end + + context 'with PersonalSnippet' do + let(:snippet) { personal_snippet } - it_behaves_like 'snippet blob raw path' + it 'returns the raw path' do + expect(subject).to eq "/-/snippets/#{snippet.id}/raw" + end + end + end + end + + describe '#raw_url' do + subject { described_class.new(snippet.blobs.first, current_user: user).raw_url } - context 'with snippet_multiple_files feature disabled' do before do - stub_feature_flags(snippet_multiple_files: false) + stub_default_url_options(host: 'test.host') end - context 'with ProjectSnippet' do - let(:snippet) { project_snippet } + it_behaves_like 'snippet blob raw url' - it 'returns the raw path' do - expect(subject).to eq "/#{snippet.project.full_path}/snippets/#{snippet.id}/raw" + context 'with snippet_multiple_files feature disabled' do + before do + stub_feature_flags(snippet_multiple_files: false) + end + + context 'with ProjectSnippet' do + let(:snippet) { project_snippet } + + it 'returns the raw project snippet url' do + expect(subject).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw") + end end - end - context 'with PersonalSnippet' do - let(:snippet) { personal_snippet } + context 'with PersonalSnippet' do + let(:snippet) { personal_snippet } - it 'returns the raw path' do - expect(subject).to eq "/snippets/#{snippet.id}/raw" + it 'returns the raw personal snippet url' do + expect(subject).to eq("http://test.host/-/snippets/#{personal_snippet.id}/raw") + end end end end diff --git a/spec/presenters/snippet_presenter_spec.rb b/spec/presenters/snippet_presenter_spec.rb index 98c291bdd02..681564ed2b0 100644 --- a/spec/presenters/snippet_presenter_spec.rb +++ b/spec/presenters/snippet_presenter_spec.rb @@ -23,7 +23,7 @@ RSpec.describe SnippetPresenter do let(:snippet) { personal_snippet } it 'returns snippet web url' do - expect(subject).to match "/snippets/#{snippet.id}" + expect(subject).to match "/-/snippets/#{snippet.id}" end end @@ -31,7 +31,7 @@ RSpec.describe SnippetPresenter do let(:snippet) { project_snippet } it 'returns snippet web url' do - expect(subject).to match "/#{project.full_path}/snippets/#{snippet.id}" + expect(subject).to match "/#{project.full_path}/-/snippets/#{snippet.id}" end end end @@ -43,7 +43,7 @@ RSpec.describe SnippetPresenter do let(:snippet) { personal_snippet } it 'returns snippet web url' do - expect(subject).to match "/snippets/#{snippet.id}/raw" + expect(subject).to match "/-/snippets/#{snippet.id}/raw" end end @@ -51,7 +51,7 @@ RSpec.describe SnippetPresenter do let(:snippet) { project_snippet } it 'returns snippet web url' do - expect(subject).to match "/#{project.full_path}/snippets/#{snippet.id}/raw" + expect(subject).to match "/#{project.full_path}/-/snippets/#{snippet.id}/raw" end end end diff --git a/spec/presenters/tree_entry_presenter_spec.rb b/spec/presenters/tree_entry_presenter_spec.rb index d29a7a6ab04..de84f36c5e6 100644 --- a/spec/presenters/tree_entry_presenter_spec.rb +++ b/spec/presenters/tree_entry_presenter_spec.rb @@ -13,4 +13,8 @@ RSpec.describe TreeEntryPresenter do describe '.web_url' do it { expect(presenter.web_url).to eq("http://localhost/#{project.full_path}/-/tree/#{tree.commit_id}/#{tree.path}") } end + + describe '#web_path' do + it { expect(presenter.web_path).to eq("/#{project.full_path}/-/tree/#{tree.commit_id}/#{tree.path}") } + end end diff --git a/spec/presenters/user_presenter_spec.rb b/spec/presenters/user_presenter_spec.rb new file mode 100644 index 00000000000..fdc20216a02 --- /dev/null +++ b/spec/presenters/user_presenter_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe UserPresenter do + let_it_be(:user) { create(:user) } + subject(:presenter) { described_class.new(user) } + + describe '#web_path' do + it { expect(presenter.web_path).to eq("/#{user.username}") } + end + + describe '#web_url' do + it { expect(presenter.web_url).to eq("http://localhost/#{user.username}") } + end +end |