Commit dbd38caa authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Ash McKenzie

Add feature test for grafana embeds

Creates a feature test for embedding grafana metrics charts
in GFM. Includes some additional helpers and fixtures.
parent 16dcfa3a
......@@ -4,6 +4,7 @@ require 'spec_helper'
describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidekiq_might_not_need_inline do
include PrometheusHelpers
include GrafanaApiHelpers
let(:user) { create(:user) }
let(:project) { create(:prometheus_project) }
......@@ -14,11 +15,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
before do
configure_host
import_common_metrics
stub_any_prometheus_request_with_response
project.add_developer(user)
sign_in(user)
end
......@@ -26,6 +23,12 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
restore_host
end
context 'internal metrics embeds' do
before do
import_common_metrics
stub_any_prometheus_request_with_response
end
it 'shows embedded metrics' do
visit project_issue_path(project, issue)
......@@ -45,7 +48,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
}
end
it 'shows embedded metrics for the specifiec chart' do
it 'shows embedded metrics for the specific chart' do
visit project_issue_path(project, issue)
expect(page).to have_css('div.prometheus-graph')
......@@ -53,6 +56,27 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
expect(page).to have_text(chart_params[:y_label])
end
end
end
context 'grafana metrics embeds' do
let(:grafana_integration) { create(:grafana_integration, project: project) }
let(:grafana_base_url) { grafana_integration.grafana_url }
let(:metrics_url) { valid_grafana_dashboard_link(grafana_base_url) }
before do
stub_dashboard_request(grafana_base_url)
stub_datasource_request(grafana_base_url)
stub_all_grafana_proxy_requests(grafana_base_url)
end
it 'shows embedded metrics' do
visit project_issue_path(project, issue)
expect(page).to have_css('div.prometheus-graph')
expect(page).to have_text('Expired / Evicted')
expect(page).to have_text('expired - test-attribute-value')
end
end
def import_common_metrics
::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute
......
......@@ -424,7 +424,7 @@
"format": "time_series",
"interval": "1m",
"intervalFactor": 2,
"legendFormat": "expired",
"legendFormat": "expired - {{ test_attribute }}",
"metric": "",
"refId": "A",
"step": 240,
......
This diff is collapsed.
......@@ -29,4 +29,13 @@ module GrafanaApiHelpers
headers: { 'Content-Type' => 'application/json' }
)
end
def stub_all_grafana_proxy_requests(base_url)
stub_request(:any, /#{base_url}\/api\/datasources\/proxy/)
.to_return(
status: 200,
body: fixture_file('grafana/proxy_response.json'),
headers: { 'Content-Type' => 'application/json' }
)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment