From 18aa62babba9f105f05efb0b94d39a013fc4ee10 Mon Sep 17 00:00:00 2001 From: rpereira2 <rpereira@gitlab.com> Date: Tue, 7 Jul 2020 12:51:17 +0530 Subject: [PATCH] Mark the self_monitoring dashboard as system dashboard Set `system_dashboard` to true for the self monitoring dashboard so that the "Add metric" button is made visible on the dashboard. Also add some jest specs for the "Add metric" button. --- .../self_monitoring_dashboard_service.rb | 2 +- ...-metrics-button-self-monitor-dashboard.yml | 5 ++ .../components/dashboard_header_spec.js | 68 +++++++++++++++++++ spec/frontend/monitoring/mock_data.js | 2 +- .../gitlab/metrics/dashboard/finder_spec.rb | 2 +- .../self_monitoring_dashboard_service_spec.rb | 2 +- 6 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/rp-add-metrics-button-self-monitor-dashboard.yml diff --git a/app/services/metrics/dashboard/self_monitoring_dashboard_service.rb b/app/services/metrics/dashboard/self_monitoring_dashboard_service.rb index f1f5cd7d77e..9097caade4b 100644 --- a/app/services/metrics/dashboard/self_monitoring_dashboard_service.rb +++ b/app/services/metrics/dashboard/self_monitoring_dashboard_service.rb @@ -29,7 +29,7 @@ module Metrics path: DASHBOARD_PATH, display_name: _(DASHBOARD_NAME), default: true, - system_dashboard: false, + system_dashboard: true, out_of_the_box_dashboard: out_of_the_box_dashboard? }] end diff --git a/changelogs/unreleased/rp-add-metrics-button-self-monitor-dashboard.yml b/changelogs/unreleased/rp-add-metrics-button-self-monitor-dashboard.yml new file mode 100644 index 00000000000..5d9320285bc --- /dev/null +++ b/changelogs/unreleased/rp-add-metrics-button-self-monitor-dashboard.yml @@ -0,0 +1,5 @@ +--- +title: Make Add metrics button visible on self monitoring dashboard +merge_request: 36169 +author: +type: fixed diff --git a/spec/frontend/monitoring/components/dashboard_header_spec.js b/spec/frontend/monitoring/components/dashboard_header_spec.js index 9b78947d146..69e0b08f2b7 100644 --- a/spec/frontend/monitoring/components/dashboard_header_spec.js +++ b/spec/frontend/monitoring/components/dashboard_header_spec.js @@ -349,4 +349,72 @@ describe('Dashboard header', () => { }); }); }); + + describe('Add metric button', () => { + const findAddMetricButton = () => wrapper.find('[data-qa-selector="add_metric_button"]'); + + it('is not rendered when custom metrics are not available', () => { + store.state.monitoringDashboard.emptyState = false; + + createShallowWrapper({ + customMetricsAvailable: false, + }); + + setupAllDashboards(store, dashboardGitResponse[0].path); + + return wrapper.vm.$nextTick(() => { + expect(findAddMetricButton().exists()).toBe(false); + }); + }); + + it('is not rendered when displaying empty state', () => { + store.state.monitoringDashboard.emptyState = true; + + createShallowWrapper({ + customMetricsAvailable: true, + }); + + setupAllDashboards(store, dashboardGitResponse[0].path); + + return wrapper.vm.$nextTick(() => { + expect(findAddMetricButton().exists()).toBe(false); + }); + }); + + describe('system dashboards', () => { + const systemDashboards = [ + dashboardGitResponse[0].path, + selfMonitoringDashboardGitResponse[0].path, + ]; + const nonSystemDashboards = [ + dashboardGitResponse[1].path, + dashboardGitResponse[2].path, + selfMonitoringDashboardGitResponse[1].path, + ]; + + beforeEach(() => { + store.state.monitoringDashboard.emptyState = false; + + createShallowWrapper({ + customMetricsAvailable: true, + }); + }); + + test.each(systemDashboards)('is rendered for system dashboards', dashboardPath => { + setupAllDashboards(store, dashboardPath); + + return wrapper.vm.$nextTick(() => { + expect(findAddMetricButton().exists()).toBe(true); + }); + }); + + test.each(nonSystemDashboards)('is not rendered for non-system dashboards', dashboardPath => { + setupAllDashboards(store, dashboardPath); + + return wrapper.vm.$nextTick(() => { + expect(findAddMetricButton().exists()).toBe(false); + }); + }); + }); + }); }); diff --git a/spec/frontend/monitoring/mock_data.js b/spec/frontend/monitoring/mock_data.js index 11e6eb2e86f..cd7f93f6876 100644 --- a/spec/frontend/monitoring/mock_data.js +++ b/spec/frontend/monitoring/mock_data.js @@ -209,7 +209,7 @@ export const selfMonitoringDashboardGitResponse = [ default: true, display_name: 'Default', can_edit: false, - system_dashboard: false, + system_dashboard: true, out_of_the_box_dashboard: true, project_blob_path: null, path: 'config/prometheus/self_monitoring_default.yml', diff --git a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb index 60e1e29d4c5..ee54a45f648 100644 --- a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb @@ -165,7 +165,7 @@ RSpec.describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store path: self_monitoring_dashboard_path, display_name: 'Default dashboard', default: true, - system_dashboard: false, + system_dashboard: true, out_of_the_box_dashboard: true } end diff --git a/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb b/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb index aea3e41a013..33b7e3c85cd 100644 --- a/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb +++ b/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb @@ -50,7 +50,7 @@ RSpec.describe Metrics::Dashboard::SelfMonitoringDashboardService, :use_clean_ra path: described_class::DASHBOARD_PATH, display_name: described_class::DASHBOARD_NAME, default: true, - system_dashboard: false, + system_dashboard: true, out_of_the_box_dashboard: true }] ) -- 2.30.9