summaryrefslogtreecommitdiff
path: root/spec/features/merge_requests/widget_deployments_spec.rb
blob: c0221525c9f10688ea48713c00b4ded9cb861d7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'spec_helper'

feature 'Widget Deployments Header', js: true do
  describe 'when deployed to an environment' do
    given(:user) { create(:user) }
    given(:project) { merge_request.target_project }
    given(:merge_request) { create(:merge_request, :merged) }
    given(:environment) { create(:environment, project: project) }
    given(:role) { :developer }
    given(:sha) { project.commit('master').id }
    given!(:deployment) { create(:deployment, environment: environment, sha: sha) }
    given!(:manual) { }

    background do
      sign_in(user)
      project.team << [user, role]
      visit project_merge_request_path(project, merge_request)
    end

    scenario 'displays that the environment is deployed' do
      wait_for_requests

      expect(page).to have_content("Deployed to #{environment.name}")
      expect(find('.js-deploy-time')['data-title']).to eq(deployment.created_at.to_time.in_time_zone.to_s(:medium))
    end

    context 'with stop action' do
      given(:pipeline) { create(:ci_pipeline, project: project) }
      given(:build) { create(:ci_build, pipeline: pipeline) }
      given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') }
      given(:deployment) do
        create(:deployment, environment: environment, ref: merge_request.target_branch,
                            sha: sha, deployable: build, on_stop: 'close_app')
      end

      background do
        wait_for_requests
      end

      scenario 'does show stop button' do
        expect(page).to have_button('Stop environment')
      end

      scenario 'does start build when stop button clicked' do
        click_button('Stop environment')

        expect(page).to have_content('close_app')
      end

      context 'for reporter' do
        given(:role) { :reporter }

        scenario 'does not show stop button' do
          expect(page).not_to have_button('Stop environment')
        end
      end
    end
  end
end