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:
authorSarah Yasonik <syasonik@gitlab.com>2019-07-10 14:27:25 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2019-07-10 14:27:25 +0300
commit7d393bd85233bd6c8f003aec638e93c01deb9f8a (patch)
tree0dcad0bc26766b82f0d8d55762b768e65a41f186 /spec/lib/gitlab/metrics/dashboard
parent476c9f0bb6bb629d36efc7b62fcb12eda6ceee2d (diff)
Expose metrics element for FE consumption
Adds GFM Pipline filters to insert a placeholder in the generated HTML from GFM based on the presence of a metrics dashboard link. The front end should look for the class 'js-render-metrics' to determine if it should replace the element with metrics charts. The data element 'data-dashboard-url' should be the endpoint the front end should hit in order to obtain a dashboard layout in order to appropriately render the charts.
Diffstat (limited to 'spec/lib/gitlab/metrics/dashboard')
-rw-r--r--spec/lib/gitlab/metrics/dashboard/url_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/url_spec.rb b/spec/lib/gitlab/metrics/dashboard/url_spec.rb
new file mode 100644
index 00000000000..34bc6359414
--- /dev/null
+++ b/spec/lib/gitlab/metrics/dashboard/url_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Metrics::Dashboard::Url do
+ describe '#regex' do
+ it 'returns a regular expression' do
+ expect(described_class.regex).to be_a Regexp
+ end
+
+ it 'matches a metrics dashboard link with named params' do
+ url = Gitlab::Routing.url_helpers.metrics_namespace_project_environment_url('foo', 'bar', 1, start: 123345456, anchor: 'title')
+
+ expected_params = {
+ 'url' => url,
+ 'namespace' => 'foo',
+ 'project' => 'bar',
+ 'environment' => '1',
+ 'query' => '?start=123345456',
+ 'anchor' => '#title'
+ }
+
+ expect(described_class.regex).to match url
+
+ described_class.regex.match(url) do |m|
+ expect(m.named_captures).to eq expected_params
+ end
+ end
+
+ it 'does not match other gitlab urls that contain the term metrics' do
+ url = Gitlab::Routing.url_helpers.active_common_namespace_project_prometheus_metrics_url('foo', 'bar', :json)
+
+ expect(described_class.regex).not_to match url
+ end
+
+ it 'does not match other gitlab urls' do
+ url = Gitlab.config.gitlab.url
+
+ expect(described_class.regex).not_to match url
+ end
+
+ it 'does not match non-gitlab urls' do
+ url = 'https://www.super_awesome_site.com/'
+
+ expect(described_class.regex).not_to match url
+ end
+ end
+
+ describe '#build_dashboard_url' do
+ it 'builds the url for the dashboard endpoint' do
+ url = described_class.build_dashboard_url('foo', 'bar', 1)
+
+ expect(url).to match described_class.regex
+ end
+ end
+end