BigW Consortium Gitlab

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

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

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

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
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 32
    end

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 38
    end
  end

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
      end
55 56 57 58

      context 'for available environment' do
        given(:environment) { create(:environment, project: project, state: :available) }

Kamil Trzcinski committed
59 60
        scenario 'does not shows stop button' do
          expect(page).not_to have_selector('.stop-env-link')
61 62 63 64 65 66 67
        end
      end

      context 'for stopped environment' do
        given(:environment) { create(:environment, project: project, state: :stopped) }

        scenario 'does not shows stop button' do
Kamil Trzcinski committed
68
          expect(page).not_to have_selector('.stop-env-link')
69 70
        end
      end
71 72 73
    end

    context 'with deployments' do
74
      given(:project) { create(:project) }
75

76
      given(:deployment) do
77 78
        create(:deployment, environment: environment,
                            sha: project.commit.id)
79
      end
80

81
      scenario 'does show deployment SHA' do
82 83 84
        expect(page).to have_link(deployment.short_sha)
      end

85 86
      scenario 'does show deployment internal id' do
        expect(page).to have_content(deployment.iid)
87 88
      end

89
      context 'with build and manual actions' do
90 91
        given(:pipeline) { create(:ci_pipeline, project: project) }
        given(:build) { create(:ci_build, pipeline: pipeline) }
92

93 94
        given(:manual) do
          create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production')
95 96
        end

97 98
        given(:deployment) do
          create(:deployment, environment: environment,
99
                              deployable: build,
100
                              sha: project.commit.id)
101
        end
102

103
        scenario 'does show a play button' do
Filipa Lacerda committed
104
          find('.js-dropdown-play-icon-container').click
105
          expect(page).to have_content(manual.name.humanize)
106 107
        end

108 109
        scenario 'does allow to play manual action', js: true do
          expect(manual).to be_skipped
110

Filipa Lacerda committed
111
          find('.js-dropdown-play-icon-container').click
112
          expect(page).to have_content(manual.name.humanize)
113

114 115
          expect { click_link(manual.name.humanize) }
            .not_to change { Ci::Pipeline.count }
Kamil Trzcinski committed
116

117 118
          expect(manual.reload).to be_pending
        end
119

120 121 122
        scenario 'does show build name and id' do
          expect(page).to have_link("#{build.name} ##{build.id}")
        end
123

124 125 126
        scenario 'does not show stop button' do
          expect(page).not_to have_selector('.stop-env-link')
        end
127

128 129 130
        scenario 'does not show external link button' do
          expect(page).not_to have_css('external-url')
        end
131

132 133 134 135
        scenario 'does not show terminal button' do
          expect(page).not_to have_terminal_button
        end

136 137 138 139
        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) }
140

141 142
          scenario 'does show an external link button' do
            expect(page).to have_link(nil, href: environment.external_url)
143
          end
144
        end
145

146 147 148
        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') }
149

150 151
          scenario 'does show stop button' do
            expect(page).to have_selector('.stop-env-link')
152
          end
Kamil Trzcinski committed
153

154 155
          scenario 'starts build when stop button clicked' do
            find('.stop-env-link').click
156

157
            expect(page).to have_content('close_app')
158
          end
159

160 161
          context 'for reporter' do
            let(:role) { :reporter }
162

163 164
            scenario 'does not show stop button' do
              expect(page).not_to have_selector('.stop-env-link')
165
            end
Filipa Lacerda committed
166
          end
167
        end
168

169 170 171 172 173
        context 'with terminal' do
          let(:project) { create(:kubernetes_project, :test_repo) }

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

175 176
            scenario 'it shows the terminal button' do
              expect(page).to have_terminal_button
177
            end
178
          end
179

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

183 184
            scenario 'does not show terminal button' do
              expect(page).not_to have_terminal_button
185
            end
Filipa Lacerda committed
186
          end
187
        end
188 189 190 191
      end
    end
  end

192 193
  scenario 'does have a New environment button' do
    expect(page).to have_link('New environment')
194
  end
195

196 197
  describe 'when creating a new environment' do
    before do
198
      visit_environments(project)
199
    end
200 201

    context 'when logged as developer' do
202 203 204
      before do
        click_link 'New environment'
      end
205 206 207

      context 'for valid name' do
        before do
208
          fill_in('Name', with: 'production')
209
          click_on 'Save'
210 211
        end

212
        scenario 'does create a new pipeline' do
213
          expect(page).to have_content('production')
214 215 216 217 218
        end
      end

      context 'for invalid name' do
        before do
219
          fill_in('Name', with: 'name,with,commas')
220
          click_on 'Save'
221 222
        end

223 224 225
        scenario 'does show errors' do
          expect(page).to have_content('Name can contain only letters')
        end
226 227 228 229
      end
    end

    context 'when logged as reporter' do
230
      given(:role) { :reporter }
231

232
      scenario 'does not have a New environment link' do
233 234 235 236
        expect(page).not_to have_link('New environment')
      end
    end
  end
237

238 239 240 241
  def have_terminal_button
    have_link(nil, href: terminal_namespace_project_environment_path(project.namespace, project, environment))
  end

242 243 244
  def visit_environments(project)
    visit namespace_project_environments_path(project.namespace, project)
  end
245
end