BigW Consortium Gitlab

environments_spec.rb 6.63 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Environments page', :feature, :js do
4 5 6 7
  given(:project) { create(:empty_project) }
  given(:user) { create(:user) }
  given(:role) { :developer }

8
  background do
9
    project.team << [user, role]
10
    login_as(user)
11
  end
Filipa Lacerda committed
12

13 14 15
  given!(:environment) { }
  given!(:deployment) { }
  given!(:manual) { }
16

17 18 19
  before do
    visit_environments(project)
  end
Kamil Trzcinski committed
20

21 22 23 24
  describe 'page tabs' do
    scenario 'shows "Available" and "Stopped" tab with links' do
      expect(page).to have_link('Available')
      expect(page).to have_link('Stopped')
25
    end
26
  end
Kamil Trzcinski committed
27

28 29 30
  context 'without environments' do
    scenario 'does show no environments' do
      expect(page).to have_content('You don\'t have any environments right now.')
31
    end
32

33 34 35
    scenario 'does show 0 as counter for environments in both tabs' do
      expect(page.find('.js-available-environments-count').text).to eq('0')
      expect(page.find('.js-stopped-environments-count').text).to eq('0')
36 37
    end
  end
38

39 40
  describe 'when showing the environment' do
    given(:environment) { create(:environment, project: project) }
41

42 43 44 45 46 47 48
    scenario 'does show environment name' do
      expect(page).to have_link(environment.name)
    end

    scenario 'does show number of available and stopped environments' do
      expect(page.find('.js-available-environments-count').text).to eq('1')
      expect(page.find('.js-stopped-environments-count').text).to eq('0')
49
    end
50 51

    context 'without deployments' do
52
      scenario 'does show no deployments' do
53
        expect(page).to have_content('No deployments yet')
54 55 56 57
      end
    end

    context 'with deployments' do
58
      given(:project) { create(:project) }
59

60
      given(:deployment) do
61 62
        create(:deployment, environment: environment,
                            sha: project.commit.id)
63
      end
64

65
      scenario 'does show deployment SHA' do
66 67 68
        expect(page).to have_link(deployment.short_sha)
      end

69 70
      scenario 'does show deployment internal id' do
        expect(page).to have_content(deployment.iid)
71 72
      end

73
      context 'with build and manual actions' do
74 75
        given(:pipeline) { create(:ci_pipeline, project: project) }
        given(:build) { create(:ci_build, pipeline: pipeline) }
76

77 78
        given(:manual) do
          create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production')
79 80
        end

81 82
        given(:deployment) do
          create(:deployment, environment: environment,
83
                              deployable: build,
84
                              sha: project.commit.id)
85
        end
86

87
        scenario 'does show a play button' do
Filipa Lacerda committed
88
          find('.js-dropdown-play-icon-container').click
89
          expect(page).to have_content(manual.name.humanize)
90 91
        end

92 93
        scenario 'does allow to play manual action', js: true do
          expect(manual).to be_skipped
94

Filipa Lacerda committed
95
          find('.js-dropdown-play-icon-container').click
96
          expect(page).to have_content(manual.name.humanize)
97

98 99
          expect { click_link(manual.name.humanize) }
            .not_to change { Ci::Pipeline.count }
Kamil Trzcinski committed
100

101 102
          expect(manual.reload).to be_pending
        end
103

104 105 106
        scenario 'does show build name and id' do
          expect(page).to have_link("#{build.name} ##{build.id}")
        end
107

108 109 110
        scenario 'does not show stop button' do
          expect(page).not_to have_selector('.stop-env-link')
        end
111

112 113 114
        scenario 'does not show external link button' do
          expect(page).not_to have_css('external-url')
        end
115

116 117 118 119
        scenario 'does not show terminal button' do
          expect(page).not_to have_terminal_button
        end

120 121 122 123
        context 'with external_url' do
          given(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') }
          given(:build) { create(:ci_build, pipeline: pipeline) }
          given(:deployment) { create(:deployment, environment: environment, deployable: build) }
124

125 126
          scenario 'does show an external link button' do
            expect(page).to have_link(nil, href: environment.external_url)
127
          end
128
        end
129

130 131 132
        context 'with stop action' do
          given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') }
          given(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') }
133

134 135
          scenario 'does show stop button' do
            expect(page).to have_selector('.stop-env-link')
Filipa Lacerda committed
136
          end
137

138 139
          scenario 'starts build when stop button clicked' do
            find('.stop-env-link').click
140

141
            expect(page).to have_content('close_app')
Filipa Lacerda committed
142
          end
143

144 145
          context 'for reporter' do
            let(:role) { :reporter }
146

147 148
            scenario 'does not show stop button' do
              expect(page).not_to have_selector('.stop-env-link')
149
            end
Filipa Lacerda committed
150
          end
151
        end
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

        context 'with terminal' do
          let(:project) { create(:kubernetes_project, :test_repo) }

          context 'for project master' do
            let(:role) { :master }

            scenario 'it shows the terminal button' do
              expect(page).to have_terminal_button
            end
          end

          context 'for developer' do
            let(:role) { :developer }

            scenario 'does not show terminal button' do
              expect(page).not_to have_terminal_button
            end
          end
        end
172 173 174 175
      end
    end
  end

176 177
  scenario 'does have a New environment button' do
    expect(page).to have_link('New environment')
178
  end
179

Filipa Lacerda committed
180 181
  describe 'when creating a new environment' do
    before do
182
      visit_environments(project)
Filipa Lacerda committed
183
    end
184

Filipa Lacerda committed
185 186 187 188
    context 'when logged as developer' do
      before do
        click_link 'New environment'
      end
189

Filipa Lacerda committed
190 191 192 193 194
      context 'for valid name' do
        before do
          fill_in('Name', with: 'production')
          click_on 'Save'
        end
195

Filipa Lacerda committed
196 197 198 199
        scenario 'does create a new pipeline' do
          expect(page).to have_content('Production')
        end
      end
200

Filipa Lacerda committed
201 202 203 204 205
      context 'for invalid name' do
        before do
          fill_in('Name', with: 'name,with,commas')
          click_on 'Save'
        end
206

Filipa Lacerda committed
207 208 209 210 211
        scenario 'does show errors' do
          expect(page).to have_content('Name can contain only letters')
        end
      end
    end
212

Filipa Lacerda committed
213 214
    context 'when logged as reporter' do
      given(:role) { :reporter }
215

Filipa Lacerda committed
216 217 218 219 220
      scenario 'does not have a New environment link' do
        expect(page).not_to have_link('New environment')
      end
    end
  end
221

222 223 224 225
  def have_terminal_button
    have_link(nil, href: terminal_namespace_project_environment_path(project.namespace, project, environment))
  end

226 227 228
  def visit_environments(project)
    visit namespace_project_environments_path(project.namespace, project)
  end
229
end