2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-07 11:57:42 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Environment > Metrics' do
|
2017-03-07 11:57:42 -05:00
|
|
|
include PrometheusHelpers
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
let(:user) { create(:user) }
|
2019-12-20 22:07:37 -05:00
|
|
|
let(:project) { create(:prometheus_project, :repository) }
|
2018-07-05 02:32:05 -04:00
|
|
|
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-06-26 10:53:55 -04:00
|
|
|
let!(:staging) { create(:environment, name: 'staging', project: project) }
|
2017-03-07 11:57:42 -05:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2017-03-07 11:57:42 -05:00
|
|
|
project.add_developer(user)
|
2019-06-26 10:53:55 -04:00
|
|
|
stub_any_prometheus_request
|
2017-03-07 11:57:42 -05:00
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-03-07 11:57:42 -05:00
|
|
|
visit_environment(environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
around do |example|
|
|
|
|
Timecop.freeze(current_time) { example.run }
|
|
|
|
end
|
|
|
|
|
2019-06-26 10:53:55 -04:00
|
|
|
shared_examples 'has environment selector' do
|
|
|
|
it 'has a working environment selector', :js do
|
|
|
|
click_link('See metrics')
|
2020-08-12 23:10:13 -04:00
|
|
|
|
|
|
|
expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: environment.id))
|
2020-01-21 07:08:31 -05:00
|
|
|
expect(page).to have_css('[data-qa-selector="environments_dropdown"]')
|
2019-06-26 10:53:55 -04:00
|
|
|
|
2020-01-21 07:08:31 -05:00
|
|
|
within('[data-qa-selector="environments_dropdown"]') do
|
2019-06-26 10:53:55 -04:00
|
|
|
# Click on the dropdown
|
|
|
|
click_on(environment.name)
|
|
|
|
|
|
|
|
# Select the staging environment
|
|
|
|
click_on(staging.name)
|
|
|
|
end
|
|
|
|
|
2020-07-15 17:09:26 -04:00
|
|
|
expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: staging.id))
|
2019-06-26 10:53:55 -04:00
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without deployments' do
|
|
|
|
it_behaves_like 'has environment selector'
|
|
|
|
end
|
|
|
|
|
2017-03-07 11:57:42 -05:00
|
|
|
context 'with deployments and related deployable present' do
|
2019-06-26 10:53:55 -04:00
|
|
|
before do
|
|
|
|
create(:deployment, environment: environment, deployable: build)
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'shows metrics' do
|
2017-03-07 11:57:42 -05:00
|
|
|
click_link('See metrics')
|
|
|
|
|
2017-06-26 11:40:20 -04:00
|
|
|
expect(page).to have_css('div#prometheus-graphs')
|
2017-03-07 11:57:42 -05:00
|
|
|
end
|
2019-06-26 10:53:55 -04:00
|
|
|
|
|
|
|
it_behaves_like 'has environment selector'
|
2017-03-07 11:57:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def visit_environment(environment)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_environment_path(environment.project, environment)
|
2017-03-07 11:57:42 -05:00
|
|
|
end
|
|
|
|
end
|