debian-mirror-gitlab/spec/lib/banzai/filter/inline_metrics_filter_spec.rb

71 lines
2.2 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
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
2019-10-12 21:52:04 +05:30
expect(doc.to_s).to eq(input)
2019-09-30 21:07:59 +05:30
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
2019-10-12 21:52:04 +05:30
expect(doc.at_css('a').to_s).to eq(input)
2019-09-30 21:07:59 +05:30
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)
2019-10-12 21:52:04 +05:30
expect(node.attribute('data-dashboard-url').to_s).to eq(dashboard_url)
2019-09-30 21:07:59 +05:30
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
2019-10-12 21:52:04 +05:30
expect(doc.at_css('p').to_s).to include(paragraph)
2019-09-30 21:07:59 +05:30
expect(doc.at_css('.js-render-metrics')).to be_present
end
2019-10-12 21:52:04 +05:30
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
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
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
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
dashboard_url = urls.metrics_dashboard_namespace_project_environment_url(*params)
expect(node.attribute('data-dashboard-url').to_s).to eq(dashboard_url)
2019-09-30 21:07:59 +05:30
end
end
end
end