2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Environment > Metrics', feature_category: :projects do
|
2017-08-17 22:00:37 +05:30
|
|
|
include PrometheusHelpers
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:user) { create(:user) }
|
2022-11-25 23:54:43 +05:30
|
|
|
let(:project) { create(:project, :with_prometheus_integration, :repository) }
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
let(:environment) { create(:environment, project: project) }
|
|
|
|
let(:current_time) { Time.now.utc }
|
2019-09-30 21:07:59 +05:30
|
|
|
let!(:staging) { create(:environment, name: 'staging', project: project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
project.add_developer(user)
|
2019-09-30 21:07:59 +05:30
|
|
|
stub_any_prometheus_request
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
around do |example|
|
2021-02-22 17:27:13 +05:30
|
|
|
travel_to(current_time) { example.run }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
shared_examples 'has environment selector' do
|
|
|
|
it 'has a working environment selector', :js do
|
2022-05-07 20:08:51 +05:30
|
|
|
visit_environment(environment)
|
2021-10-27 15:23:28 +05:30
|
|
|
click_link 'Monitoring'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: environment.id))
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(page).to have_css('[data-testid="environments-dropdown"]')
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
within('[data-testid="environments-dropdown"]') do
|
2019-09-30 21:07:59 +05:30
|
|
|
# Click on the dropdown
|
|
|
|
click_on(environment.name)
|
|
|
|
|
|
|
|
# Select the staging environment
|
|
|
|
click_on(staging.name)
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: staging.id))
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without deployments' do
|
|
|
|
it_behaves_like 'has environment selector'
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'with deployments and related deployable present' do
|
2019-09-30 21:07:59 +05:30
|
|
|
before do
|
|
|
|
create(:deployment, environment: environment, deployable: build)
|
|
|
|
end
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
it 'shows metrics', :js do
|
2022-05-07 20:08:51 +05:30
|
|
|
visit_environment(environment)
|
2021-10-27 15:23:28 +05:30
|
|
|
click_link 'Monitoring'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(page).to have_css('[data-testid="prometheus-graphs"]')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
it_behaves_like 'has environment selector'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def visit_environment(environment)
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_environment_path(environment.project, environment)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|