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

517 lines
16 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 'Environments page', :js do
2022-05-07 20:08:51 +05:30
include Spec::Support::Helpers::ModalHelpers
2018-11-08 19:23:39 +05:30
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:role) { :developer }
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_role(user, role)
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
2021-02-22 17:27:13 +05:30
def actions_button_selector
'[data-testid="environment-actions-button"]'
end
def action_link_selector
'[data-testid="manual-action-link"]'
end
2018-11-18 11:00:15 +05:30
def stop_button_selector
2021-02-22 17:27:13 +05:30
'button[title="Stop environment"]'
end
def upcoming_deployment_content_selector
'[data-testid="upcoming-deployment-content"]'
2018-11-18 11:00:15 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'page tabs' do
2017-09-10 17:25:29 +05:30
it 'shows "Available" and "Stopped" tab with links' do
visit_environments(project)
2022-05-07 20:08:51 +05:30
expect(page).to have_link(_('Available'))
expect(page).to have_link(_('Stopped'))
2017-08-17 22:00:37 +05:30
end
describe 'with one available environment' do
2022-05-07 20:08:51 +05:30
let!(:environment) { create(:environment, project: project, state: :available) }
2017-08-17 22:00:37 +05:30
describe 'in available tab page' do
2019-07-07 11:18:12 +05:30
it 'shows one environment' do
2017-09-10 17:25:29 +05:30
visit_environments(project, scope: 'available')
2022-05-07 20:08:51 +05:30
expect(page).to have_link(environment.name, href: project_environment_path(project, environment))
2017-08-17 22:00:37 +05:30
end
end
2019-07-07 11:18:12 +05:30
describe 'with environments spanning multiple pages', :js do
before do
allow(Kaminari.config).to receive(:default_per_page).and_return(3)
create_list(:environment, 4, project: project, state: :available)
end
it 'renders second page of pipelines' do
visit_environments(project, scope: 'available')
2020-01-01 13:55:28 +05:30
find('.page-link.next-page-item').click
2019-07-07 11:18:12 +05:30
wait_for_requests
2020-01-01 13:55:28 +05:30
expect(page).to have_selector('.gl-pagination .page-link', count: 4)
expect(find('.gl-pagination .page-link.active').text).to eq("2")
2019-07-07 11:18:12 +05:30
end
end
2017-08-17 22:00:37 +05:30
describe 'in stopped tab page' do
2019-07-07 11:18:12 +05:30
it 'shows no environments' do
2017-09-10 17:25:29 +05:30
visit_environments(project, scope: 'stopped')
2022-06-21 17:19:12 +05:30
expect(page).to have_content(s_('Environments|You don\'t have any stopped environments.'))
2017-08-17 22:00:37 +05:30
end
end
2018-10-15 14:42:47 +05:30
context 'when cluster is not reachable' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
2021-09-04 01:27:46 +05:30
let!(:integration_prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
2018-10-15 14:42:47 +05:30
before do
2019-12-26 22:10:19 +05:30
allow_next_instance_of(Kubeclient::Client) do |instance|
allow(instance).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
end
2018-10-15 14:42:47 +05:30
end
2019-07-07 11:18:12 +05:30
it 'shows one environment without error' do
2018-10-15 14:42:47 +05:30
visit_environments(project, scope: 'available')
2022-05-07 20:08:51 +05:30
expect(page).to have_link(environment.name, href: project_environment_path(project, environment))
2018-10-15 14:42:47 +05:30
end
end
2017-08-17 22:00:37 +05:30
end
describe 'with one stopped environment' do
2022-05-07 20:08:51 +05:30
let!(:environment) { create(:environment, project: project, state: :stopped) }
2017-08-17 22:00:37 +05:30
describe 'in available tab page' do
2019-07-07 11:18:12 +05:30
it 'shows no environments' do
2017-09-10 17:25:29 +05:30
visit_environments(project, scope: 'available')
2022-06-21 17:19:12 +05:30
expect(page).to have_content(s_('Environments|You don\'t have any environments.'))
2017-08-17 22:00:37 +05:30
end
end
describe 'in stopped tab page' do
2019-07-07 11:18:12 +05:30
it 'shows one environment' do
2017-09-10 17:25:29 +05:30
visit_environments(project, scope: 'stopped')
2022-05-07 20:08:51 +05:30
expect(page).to have_link(environment.name, href: project_environment_path(project, environment))
2020-11-24 15:15:51 +05:30
expect(page.all('[data-testid="stop-icon"]').length).to eq(0)
2017-08-17 22:00:37 +05:30
end
end
end
end
context 'without environments' do
2017-09-10 17:25:29 +05:30
before do
visit_environments(project)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'does not show environments and counters are set to zero' do
2022-06-21 17:19:12 +05:30
expect(page).to have_content(s_('Environments|You don\'t have any environments.'))
2017-09-10 17:25:29 +05:30
2022-05-07 20:08:51 +05:30
expect(page).to have_link("#{_('Available')} 0")
expect(page).to have_link("#{_('Stopped')} 0")
2017-08-17 22:00:37 +05:30
end
end
2017-09-10 17:25:29 +05:30
describe 'environments table' do
2018-11-08 19:23:39 +05:30
let!(:environment) do
2017-09-10 17:25:29 +05:30
create(:environment, project: project, state: :available)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
context 'when there are no deployments' do
before do
visit_environments(project)
2022-05-07 20:08:51 +05:30
page.click_button _('Expand')
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'shows environments names and counters' do
2022-05-07 20:08:51 +05:30
expect(page).to have_link(environment.name, href: project_environment_path(project, environment))
2017-08-17 22:00:37 +05:30
2022-05-07 20:08:51 +05:30
expect(page).to have_link("#{_('Available')} 1")
expect(page).to have_link("#{_('Stopped')} 0")
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'does not show deployments' do
2022-05-07 20:08:51 +05:30
expect(page).to have_content(s_('Environments|There are no deployments for this environment yet. Learn more about setting up deployments.'))
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
it 'shows stop button when environment is not stoppable' do
2022-05-07 20:08:51 +05:30
expect(page).to have_button('Stop')
2017-08-17 22:00:37 +05:30
end
end
2018-12-13 13:39:08 +05:30
context 'when there are successful deployments' do
2018-11-08 19:23:39 +05:30
let(:project) { create(:project, :repository) }
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
let!(:deployment) do
2018-12-13 13:39:08 +05:30
create(:deployment, :success,
environment: environment,
2017-08-17 22:00:37 +05:30
sha: project.commit.id)
end
2017-09-10 17:25:29 +05:30
it 'shows deployment SHA and internal ID' do
visit_environments(project)
2022-05-07 20:08:51 +05:30
page.click_button _('Expand')
2017-08-17 22:00:37 +05:30
2022-05-07 20:08:51 +05:30
expect(page).to have_text(deployment.short_sha)
expect(page).to have_link(deployment.commit.full_title)
2017-08-17 22:00:37 +05:30
expect(page).to have_content(deployment.iid)
end
2017-09-10 17:25:29 +05:30
context 'when builds and manual actions are present' do
2018-11-08 19:23:39 +05:30
let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, pipeline: pipeline) }
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
let!(:action) do
2017-08-17 22:00:37 +05:30
create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production')
end
2018-11-08 19:23:39 +05:30
let!(:deployment) do
2018-12-13 13:39:08 +05:30
create(:deployment, :success,
environment: environment,
2017-08-17 22:00:37 +05:30
deployable: build,
sha: project.commit.id)
end
2017-09-10 17:25:29 +05:30
before do
visit_environments(project)
end
it 'shows a play button' do
2021-02-22 17:27:13 +05:30
find(actions_button_selector).click
2019-07-07 11:18:12 +05:30
expect(page).to have_content(action.name)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'allows to play a manual action', :js do
2017-08-17 22:00:37 +05:30
expect(action).to be_manual
2021-02-22 17:27:13 +05:30
find(actions_button_selector).click
2019-07-07 11:18:12 +05:30
expect(page).to have_content(action.name)
2017-08-17 22:00:37 +05:30
2021-02-22 17:27:13 +05:30
expect { find(action_link_selector).click }
2017-08-17 22:00:37 +05:30
.not_to change { Ci::Pipeline.count }
end
2017-09-10 17:25:29 +05:30
it 'shows a stop button' do
2020-01-01 13:55:28 +05:30
expect(page).to have_selector(stop_button_selector)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'does not show external link button' do
2017-08-17 22:00:37 +05:30
expect(page).not_to have_css('external-url')
end
2017-09-10 17:25:29 +05:30
it 'does not show terminal button' do
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button(_('More actions'))
2017-08-17 22:00:37 +05:30
expect(page).not_to have_terminal_button
end
context 'with external_url' do
2018-11-08 19:23:39 +05:30
let(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') }
let(:build) { create(:ci_build, pipeline: pipeline) }
2018-12-13 13:39:08 +05:30
let(:deployment) { create(:deployment, :success, environment: environment, deployable: build) }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
it 'shows an external link button' do
2017-08-17 22:00:37 +05:30
expect(page).to have_link(nil, href: environment.external_url)
end
end
context 'with stop action' do
2018-11-08 19:23:39 +05:30
let(:action) do
2017-08-17 22:00:37 +05:30
create(:ci_build, :manual, pipeline: pipeline, name: 'close_app')
end
2018-11-08 19:23:39 +05:30
let(:deployment) do
2018-12-13 13:39:08 +05:30
create(:deployment, :success,
environment: environment,
2017-08-17 22:00:37 +05:30
deployable: build,
on_stop: 'close_app')
end
2017-09-10 17:25:29 +05:30
it 'shows a stop button' do
2018-11-18 11:00:15 +05:30
expect(page).to have_selector(stop_button_selector)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
context 'when user is a reporter' do
2017-08-17 22:00:37 +05:30
let(:role) { :reporter }
2017-09-10 17:25:29 +05:30
it 'does not show stop button' do
2018-11-18 11:00:15 +05:30
expect(page).not_to have_selector(stop_button_selector)
2017-08-17 22:00:37 +05:30
end
end
end
2017-09-10 17:25:29 +05:30
context 'when kubernetes terminal is available' do
2019-09-04 21:01:54 +05:30
context 'when user configured kubernetes from CI/CD > Clusters' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [create(:project, :repository)]) }
let(:project) { cluster.project }
2018-11-18 11:00:15 +05:30
context 'for project maintainer' do
let(:role) { :maintainer }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'shows the terminal button' do
2021-11-18 22:05:49 +05:30
click_button(_('More actions'))
2018-03-17 18:26:18 +05:30
expect(page).to have_terminal_button
end
end
context 'when user is a developer' do
let(:role) { :developer }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'does not show terminal button' do
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button(_('More actions'))
2018-03-17 18:26:18 +05:30
expect(page).not_to have_terminal_button
end
2017-08-17 22:00:37 +05:30
end
end
end
end
2018-12-13 13:39:08 +05:30
context 'when there is a delayed job' do
let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:delayed_job) do
create(:ci_build, :scheduled,
pipeline: pipeline,
name: 'delayed job',
2019-02-15 15:39:39 +05:30
stage: 'test')
2018-12-13 13:39:08 +05:30
end
let!(:deployment) do
create(:deployment,
:success,
environment: environment,
deployable: build,
sha: project.commit.id)
end
before do
visit_environments(project)
end
it 'has a dropdown for actionable jobs' do
2021-02-22 17:27:13 +05:30
expect(page).to have_selector("#{actions_button_selector} [data-testid=\"play-icon\"]")
2018-12-13 13:39:08 +05:30
end
it "has link to the delayed job's action" do
2021-02-22 17:27:13 +05:30
find(actions_button_selector).click
2018-12-13 13:39:08 +05:30
2019-07-07 11:18:12 +05:30
expect(page).to have_button('delayed job')
2018-12-13 13:39:08 +05:30
expect(page).to have_content(/\d{2}:\d{2}:\d{2}/)
end
context 'when delayed job is expired already' do
let!(:delayed_job) do
create(:ci_build, :expired_scheduled,
pipeline: pipeline,
name: 'delayed job',
2019-02-15 15:39:39 +05:30
stage: 'test')
2018-12-13 13:39:08 +05:30
end
it "shows 00:00:00 as the remaining time" do
2021-02-22 17:27:13 +05:30
find(actions_button_selector).click
2018-12-13 13:39:08 +05:30
expect(page).to have_content("00:00:00")
end
end
context 'when user played a delayed job immediately' do
before do
2021-02-22 17:27:13 +05:30
find(actions_button_selector).click
2022-05-07 20:08:51 +05:30
accept_gl_confirm do
find(action_link_selector).click
end
2023-01-13 00:05:48 +05:30
# Wait for UI to transition to ensure we an GraphQL request has been made
within(actions_button_selector) { find('.gl-spinner') }
within(actions_button_selector) { find('[data-testid="play-icon"]') }
2018-12-13 13:39:08 +05:30
wait_for_requests
end
it 'enqueues the delayed job', :js do
expect(delayed_job.reload).to be_pending
end
end
end
end
context 'when there is a failed deployment' do
let(:project) { create(:project, :repository) }
let!(:deployment) do
create(:deployment, :failed,
environment: environment,
sha: project.commit.id)
end
it 'does not show deployments' do
visit_environments(project)
2022-05-07 20:08:51 +05:30
page.click_button _('Expand')
expect(page).to have_content(s_('Environments|There are no deployments for this environment yet. Learn more about setting up deployments.'))
2018-12-13 13:39:08 +05:30
end
2017-08-17 22:00:37 +05:30
end
2021-02-22 17:27:13 +05:30
context 'when there is an upcoming deployment' do
let_it_be(:project) { create(:project, :repository) }
let!(:deployment) do
create(:deployment, :running,
environment: environment,
sha: project.commit.id)
end
it "renders the upcoming deployment", :aggregate_failures do
visit_environments(project)
2022-05-07 20:08:51 +05:30
page.click_button _('Expand')
2021-02-22 17:27:13 +05:30
within(upcoming_deployment_content_selector) do
expect(page).to have_content("##{deployment.iid}")
expect(page).to have_link(href: /#{deployment.user.username}/)
end
end
end
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'does have a new environment button' do
visit_environments(project)
2017-08-17 22:00:37 +05:30
expect(page).to have_link('New environment')
end
2017-09-10 17:25:29 +05:30
describe 'creating a new environment' do
2017-08-17 22:00:37 +05:30
before do
visit_environments(project)
end
2017-09-10 17:25:29 +05:30
context 'user is a developer' do
2018-11-08 19:23:39 +05:30
let(:role) { :developer }
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
it 'developer creates a new environment with a valid name' do
2022-05-07 20:08:51 +05:30
click_link 'New environment'
2017-09-10 17:25:29 +05:30
fill_in('Name', with: 'production')
click_on 'Save'
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).to have_content('production')
2017-08-17 22:00:37 +05:30
end
2022-05-07 20:08:51 +05:30
it 'developer creates a new environment with invalid name' do
click_link 'New environment'
2017-09-10 17:25:29 +05:30
fill_in('Name', with: 'name,with,commas')
click_on 'Save'
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).to have_content('Name can contain only letters')
2017-08-17 22:00:37 +05:30
end
end
2017-09-10 17:25:29 +05:30
context 'user is a reporter' do
2018-11-08 19:23:39 +05:30
let(:role) { :reporter }
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
it 'reporters tries to create a new environment' do
2017-08-17 22:00:37 +05:30
expect(page).not_to have_link('New environment')
end
end
end
2017-09-10 17:25:29 +05:30
describe 'environments folders' do
2021-04-17 20:07:23 +05:30
describe 'available environments' do
before do
create(:environment, :will_auto_stop,
project: project,
name: 'staging/review-1',
state: :available)
create(:environment, :will_auto_stop,
project: project,
name: 'staging/review-2',
state: :available)
end
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
it 'users unfurls an environment folder' do
visit_environments(project)
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
expect(page).not_to have_content 'review-1'
expect(page).not_to have_content 'review-2'
expect(page).to have_content 'staging 2'
2017-09-10 17:25:29 +05:30
2022-05-07 20:08:51 +05:30
page.click_button _('Expand')
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_content 'review-1'
expect(page).to have_content 'review-2'
2022-05-07 20:08:51 +05:30
expect(page).to have_content 'Auto stop in'
2021-04-17 20:07:23 +05:30
end
end
describe 'stopped environments' do
before do
create(:environment, :will_auto_stop,
project: project,
name: 'staging/review-1',
state: :stopped)
create(:environment, :will_auto_stop,
project: project,
name: 'staging/review-2',
state: :stopped)
end
it 'users unfurls an environment folder' do
visit_environments(project, scope: 'stopped')
expect(page).not_to have_content 'review-1'
expect(page).not_to have_content 'review-2'
expect(page).to have_content 'staging 2'
2022-05-07 20:08:51 +05:30
page.click_button _('Expand')
2021-04-17 20:07:23 +05:30
expect(page).to have_content 'review-1'
expect(page).to have_content 'review-2'
2020-04-22 19:07:51 +05:30
end
2017-09-10 17:25:29 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe 'environments folders view' do
before do
create(:environment, project: project,
name: 'staging.review/review-1',
state: :available)
create(:environment, project: project,
name: 'staging.review/review-2',
state: :available)
end
2018-11-08 19:23:39 +05:30
it 'user opens folder view' do
2018-03-17 18:26:18 +05:30
visit folder_project_environments_path(project, 'staging.review')
wait_for_requests
expect(page).to have_content('Environments / staging.review')
expect(page).to have_content('review-1')
expect(page).to have_content('review-2')
end
end
2017-08-17 22:00:37 +05:30
def have_terminal_button
2021-11-18 22:05:49 +05:30
have_link(_('Terminal'), href: terminal_project_environment_path(project, environment))
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
def visit_environments(project, **opts)
visit project_environments_path(project, **opts)
2018-03-17 18:26:18 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
end