Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-19 03:09:15 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-19 03:09:15 +0300
commit60f63d15794e62c4bac9756445f618cd9acb8654 (patch)
tree30c2b2dc678995dd332b32672f9faa460fabdb79 /spec/lib/banzai
parent93d7441cc98c1db55797a2181a3d9f4b3d26d82c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r--spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb26
-rw-r--r--spec/lib/banzai/filter/inline_metrics_filter_spec.rb79
-rw-r--r--spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb27
3 files changed, 28 insertions, 104 deletions
diff --git a/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb b/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb
index fd6f8816b63..9ac06a90efd 100644
--- a/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb
+++ b/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb
@@ -8,40 +8,26 @@ describe Banzai::Filter::InlineGrafanaMetricsFilter do
let_it_be(:project) { create(:project) }
let_it_be(:grafana_integration) { create(:grafana_integration, project: project) }
- let(:input) { %(<a href="#{url}">example</a>) }
+ let(:input) { %(<a href="#{trigger_url}">example</a>) }
let(:doc) { filter(input) }
-
- let(:url) { grafana_integration.grafana_url + dashboard_path }
let(:dashboard_path) do
'/d/XDaNK6amz/gitlab-omnibus-redis' \
'?from=1570397739557&to=1570484139557' \
'&var-instance=All&panelId=14'
end
- it 'appends a metrics charts placeholder with dashboard url after metrics links' do
- node = doc.at_css('.js-render-metrics')
- expect(node).to be_present
-
- dashboard_url = urls.project_grafana_api_metrics_dashboard_url(
+ let(:trigger_url) { grafana_integration.grafana_url + dashboard_path }
+ let(:dashboard_url) do
+ urls.project_grafana_api_metrics_dashboard_url(
project,
embedded: true,
- grafana_url: url,
+ grafana_url: trigger_url,
start: "2019-10-06T21:35:39Z",
end: "2019-10-07T21:35:39Z"
)
-
- expect(node.attribute('data-dashboard-url').to_s).to eq(dashboard_url)
end
- context 'when the dashboard link is part of a paragraph' do
- let(:paragraph) { %(This is an <a href="#{url}">example</a> of metrics.) }
- let(:input) { %(<p>#{paragraph}</p>) }
-
- it 'appends the charts placeholder after the enclosing paragraph' do
- expect(unescape(doc.at_css('p').to_s)).to include(paragraph)
- expect(doc.at_css('.js-render-metrics')).to be_present
- end
- end
+ it_behaves_like 'a metrics embed filter'
context 'when grafana is not configured' do
before do
diff --git a/spec/lib/banzai/filter/inline_metrics_filter_spec.rb b/spec/lib/banzai/filter/inline_metrics_filter_spec.rb
index 66bbcbf7292..1546a5e88ed 100644
--- a/spec/lib/banzai/filter/inline_metrics_filter_spec.rb
+++ b/spec/lib/banzai/filter/inline_metrics_filter_spec.rb
@@ -5,66 +5,31 @@ require 'spec_helper'
describe Banzai::Filter::InlineMetricsFilter do
include FilterSpecHelper
- let(:input) { %(<a href="#{url}">example</a>) }
- let(:doc) { filter(input) }
-
- context 'when the document has an external link' do
- let(:url) { 'https://foo.com' }
-
- it 'leaves regular non-metrics links unchanged' do
- expect(doc.to_s).to eq(input)
- end
- end
-
- context 'when the document has a metrics dashboard link' do
- let(:params) { ['foo', 'bar', 12] }
- let(:url) { urls.metrics_namespace_project_environment_url(*params) }
-
- it 'leaves the original link unchanged' do
- expect(doc.at_css('a').to_s).to eq(input)
- end
-
- it 'appends a metrics charts placeholder with dashboard url after metrics links' do
- node = doc.at_css('.js-render-metrics')
- expect(node).to be_present
-
- dashboard_url = urls.metrics_dashboard_namespace_project_environment_url(*params, embedded: true)
- expect(node.attribute('data-dashboard-url').to_s).to eq(dashboard_url)
+ let(:params) { ['foo', 'bar', 12] }
+ let(:query_params) { {} }
+
+ let(:trigger_url) { urls.metrics_namespace_project_environment_url(*params, query_params) }
+ let(:dashboard_url) { urls.metrics_dashboard_namespace_project_environment_url(*params, **query_params, embedded: true) }
+
+ it_behaves_like 'a metrics embed filter'
+
+ context 'with query params specified' do
+ let(:query_params) do
+ {
+ dashboard: 'config/prometheus/common_metrics.yml',
+ group: 'System metrics (Kubernetes)',
+ title: 'Core Usage (Pod Average)',
+ y_label: 'Cores per Pod'
+ }
end
- context 'when the metrics dashboard link is part of a paragraph' do
- let(:paragraph) { %(This is an <a href="#{url}">example</a> of metrics.) }
- let(:input) { %(<p>#{paragraph}</p>) }
-
- it 'appends the charts placeholder after the enclosing paragraph' do
- expect(doc.at_css('p').to_s).to include(paragraph)
- expect(doc.at_css('.js-render-metrics')).to be_present
- end
- end
-
- context 'with dashboard params specified' do
- let(:params) do
- [
- 'foo',
- 'bar',
- 12,
- {
- embedded: true,
- dashboard: 'config/prometheus/common_metrics.yml',
- group: 'System metrics (Kubernetes)',
- title: 'Core Usage (Pod Average)',
- y_label: 'Cores per Pod'
- }
- ]
- end
+ it_behaves_like 'a metrics embed filter'
+ end
- it 'appends a metrics charts placeholder with dashboard url after metrics links' do
- node = doc.at_css('.js-render-metrics')
- expect(node).to be_present
+ it 'leaves links to other dashboards unchanged' do
+ url = urls.namespace_project_grafana_api_metrics_dashboard_url('foo', 'bar')
+ input = %(<a href="#{url}">example</a>)
- dashboard_url = urls.metrics_dashboard_namespace_project_environment_url(*params)
- expect(node.attribute('data-dashboard-url').to_s).to eq(dashboard_url)
- end
- end
+ expect(filter(input).to_s).to eq(input)
end
end
diff --git a/spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb b/spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
index e2615ea5069..f91927412cb 100644
--- a/spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
+++ b/spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
@@ -18,33 +18,6 @@ describe Banzai::Filter::InlineMetricsRedactorFilter do
end
context 'with a metrics charts placeholder' do
- shared_examples_for 'a supported metrics dashboard url' do
- context 'no user is logged in' do
- it 'redacts the placeholder' do
- expect(doc.to_s).to be_empty
- end
- end
-
- context 'the user does not have permission do see charts' do
- let(:doc) { filter(input, current_user: build(:user)) }
-
- it 'redacts the placeholder' do
- expect(doc.to_s).to be_empty
- end
- end
-
- context 'the user has requisite permissions' do
- let(:user) { create(:user) }
- let(:doc) { filter(input, current_user: user) }
-
- it 'leaves the placeholder' do
- project.add_maintainer(user)
-
- expect(doc.to_s).to eq input
- end
- end
- end
-
let(:input) { %(<div class="js-render-metrics" data-dashboard-url="#{url}"></div>) }
it_behaves_like 'a supported metrics dashboard url'