debian-mirror-gitlab/spec/features/projects/environments/environment_metrics_spec.rb

75 lines
1.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Environment > Metrics' do
2017-08-17 22:00:37 +05:30
include PrometheusHelpers
2018-11-08 19:23:39 +05:30
let(:user) { create(:user) }
2020-03-13 15:44:24 +05:30
let(:project) { create(:prometheus_project, :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
visit_environment(environment)
end
around do |example|
Timecop.freeze(current_time) { example.run }
end
2019-09-30 21:07:59 +05:30
shared_examples 'has environment selector' do
it 'has a working environment selector', :js do
click_link('See metrics')
expect(page).to have_metrics_path(environment)
2020-03-13 15:44:24 +05:30
expect(page).to have_css('[data-qa-selector="environments_dropdown"]')
2019-09-30 21:07:59 +05:30
2020-03-13 15:44:24 +05:30
within('[data-qa-selector="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
expect(page).to have_metrics_path(staging)
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
2018-11-08 19:23:39 +05:30
it 'shows metrics' do
2017-08-17 22:00:37 +05:30
click_link('See metrics')
2017-09-10 17:25:29 +05:30
expect(page).to have_css('div#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
2019-09-30 21:07:59 +05:30
def have_metrics_path(environment)
have_current_path(metrics_project_environment_path(project, id: environment.id))
end
2017-08-17 22:00:37 +05:30
end