diff options
Diffstat (limited to 'spec/features/merge_request/user_sees_deployment_widget_spec.rb')
-rw-r--r-- | spec/features/merge_request/user_sees_deployment_widget_spec.rb | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/spec/features/merge_request/user_sees_deployment_widget_spec.rb b/spec/features/merge_request/user_sees_deployment_widget_spec.rb index f744d7941f5..74290c0fff9 100644 --- a/spec/features/merge_request/user_sees_deployment_widget_spec.rb +++ b/spec/features/merge_request/user_sees_deployment_widget_spec.rb @@ -1,45 +1,88 @@ require 'rails_helper' describe 'Merge request > User sees deployment widget', :js do - describe 'when deployed to an environment' do + describe 'when merge request has associated environments' do let(:user) { create(:user) } - let(:project) { merge_request.target_project } - let(:merge_request) { create(:merge_request, :merged) } + let(:project) { create(:project, :repository) } + let(:merge_request) { create(:merge_request, :merged, source_project: project) } let(:environment) { create(:environment, project: project) } let(:role) { :developer } - let(:sha) { project.commit('master').id } - let!(:deployment) { create(:deployment, environment: environment, sha: sha) } + let(:ref) { merge_request.target_branch } + let(:sha) { project.commit(ref).id } + let(:pipeline) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: ref) } let!(:manual) { } before do + merge_request.update!(merge_commit_sha: sha) project.add_user(user, role) sign_in(user) - visit project_merge_request_path(project, merge_request) - wait_for_requests end - it 'displays that the environment is deployed' do - wait_for_requests + context 'when deployment succeeded' do + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :succeed, environment: environment, sha: sha, ref: ref, deployable: build) } - expect(page).to have_content("Deployed to #{environment.name}") - expect(find('.js-deploy-time')['data-original-title']).to eq(deployment.created_at.to_time.in_time_zone.to_s(:medium)) + it 'displays that the environment is deployed' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Deployed to #{environment.name}") + expect(find('.js-deploy-time')['data-original-title']).to eq(deployment.created_at.to_time.in_time_zone.to_s(:medium)) + end + end + + context 'when deployment failed' do + let(:build) { create(:ci_build, :failed, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :failed, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'displays that the deployment failed' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Failed to deploy to #{environment.name}") + expect(page).not_to have_css('.js-deploy-time') + end + end + + context 'when deployment running' do + let(:build) { create(:ci_build, :running, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :running, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'displays that the running deployment' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Deploying to #{environment.name}") + expect(page).not_to have_css('.js-deploy-time') + end + end + + context 'when deployment will happen' do + let(:build) { create(:ci_build, :created, pipeline: pipeline) } + let!(:deployment) { create(:deployment, environment: environment, sha: sha, ref: ref, deployable: build) } + + it 'displays that the environment name' do + visit project_merge_request_path(project, merge_request) + wait_for_requests + + expect(page).to have_content("Deploying to #{environment.name}") + expect(page).not_to have_css('.js-deploy-time') + end end context 'with stop action' do - let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build) { create(:ci_build, pipeline: pipeline) } + let(:build) { create(:ci_build, :success, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :succeed, environment: environment, sha: sha, ref: ref, deployable: build) } let(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') } - let(:deployment) do - create(:deployment, environment: environment, ref: merge_request.target_branch, - sha: sha, deployable: build, on_stop: 'close_app') - end before do + deployment.update!(on_stop: manual.name) + visit project_merge_request_path(project, merge_request) wait_for_requests end it 'does start build when stop button clicked' do - accept_confirm { click_button('Stop environment') } + accept_confirm { find('.js-stop-env').click } expect(page).to have_content('close_app') end @@ -48,7 +91,7 @@ describe 'Merge request > User sees deployment widget', :js do let(:role) { :reporter } it 'does not show stop button' do - expect(page).not_to have_button('Stop environment') + expect(page).not_to have_selector('.js-stop-env') end end end |