Commit e2d6427c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor environments spec and remove mystery guests

parent 9e74d936
...@@ -10,26 +10,23 @@ feature 'Environments page', :js do ...@@ -10,26 +10,23 @@ feature 'Environments page', :js do
sign_in(user) sign_in(user)
end end
given!(:environment) { } describe 'page tabs' do
given!(:deployment) { } it 'shows "Available" and "Stopped" tab with links' do
given!(:action) { }
before do
visit_environments(project) visit_environments(project)
end
describe 'page tabs' do
scenario 'shows "Available" and "Stopped" tab with links' do
expect(page).to have_link('Available') expect(page).to have_link('Available')
expect(page).to have_link('Stopped') expect(page).to have_link('Stopped')
end end
describe 'with one available environment' do describe 'with one available environment' do
given(:environment) { create(:environment, project: project, state: :available) } before do
create(:environment, project: project, state: :available)
end
describe 'in available tab page' do describe 'in available tab page' do
it 'should show one environment' do it 'should show one environment' do
visit project_environments_path(project, scope: 'available') visit_environments(project, scope: 'available')
expect(page).to have_css('.environments-container') expect(page).to have_css('.environments-container')
expect(page.all('.environment-name').length).to eq(1) expect(page.all('.environment-name').length).to eq(1)
end end
...@@ -37,7 +34,8 @@ feature 'Environments page', :js do ...@@ -37,7 +34,8 @@ feature 'Environments page', :js do
describe 'in stopped tab page' do describe 'in stopped tab page' do
it 'should show no environments' do it 'should show no environments' do
visit project_environments_path(project, scope: 'stopped') visit_environments(project, scope: 'stopped')
expect(page).to have_css('.environments-container') expect(page).to have_css('.environments-container')
expect(page).to have_content('You don\'t have any environments right now') expect(page).to have_content('You don\'t have any environments right now')
end end
...@@ -45,11 +43,14 @@ feature 'Environments page', :js do ...@@ -45,11 +43,14 @@ feature 'Environments page', :js do
end end
describe 'with one stopped environment' do describe 'with one stopped environment' do
given(:environment) { create(:environment, project: project, state: :stopped) } before do
create(:environment, project: project, state: :stopped)
end
describe 'in available tab page' do describe 'in available tab page' do
it 'should show no environments' do it 'should show no environments' do
visit project_environments_path(project, scope: 'available') visit_environments(project, scope: 'available')
expect(page).to have_css('.environments-container') expect(page).to have_css('.environments-container')
expect(page).to have_content('You don\'t have any environments right now') expect(page).to have_content('You don\'t have any environments right now')
end end
...@@ -57,7 +58,8 @@ feature 'Environments page', :js do ...@@ -57,7 +58,8 @@ feature 'Environments page', :js do
describe 'in stopped tab page' do describe 'in stopped tab page' do
it 'should show one environment' do it 'should show one environment' do
visit project_environments_path(project, scope: 'stopped') visit_environments(project, scope: 'stopped')
expect(page).to have_css('.environments-container') expect(page).to have_css('.environments-container')
expect(page.all('.environment-name').length).to eq(1) expect(page.all('.environment-name').length).to eq(1)
end end
...@@ -66,86 +68,85 @@ feature 'Environments page', :js do ...@@ -66,86 +68,85 @@ feature 'Environments page', :js do
end end
context 'without environments' do context 'without environments' do
scenario 'does show no environments' do before do
expect(page).to have_content('You don\'t have any environments right now.') visit_environments(project)
end end
scenario 'does show 0 as counter for environments in both tabs' do it 'does not show environments and counters are set to zero' do
expect(page).to have_content('You don\'t have any environments right now.')
expect(page.find('.js-available-environments-count').text).to eq('0') expect(page.find('.js-available-environments-count').text).to eq('0')
expect(page.find('.js-stopped-environments-count').text).to eq('0') expect(page.find('.js-stopped-environments-count').text).to eq('0')
end end
end end
describe 'when showing the environment' do describe 'environments table' do
given(:environment) { create(:environment, project: project) } given!(:environment) do
create(:environment, project: project, state: :available)
end
scenario 'does show environment name' do context 'when there are no deployments' do
expect(page).to have_link(environment.name) before do
visit_environments(project)
end end
scenario 'does show number of available and stopped environments' do it 'shows environments names and counters' do
expect(page).to have_link(environment.name)
expect(page.find('.js-available-environments-count').text).to eq('1') expect(page.find('.js-available-environments-count').text).to eq('1')
expect(page.find('.js-stopped-environments-count').text).to eq('0') expect(page.find('.js-stopped-environments-count').text).to eq('0')
end end
context 'without deployments' do it 'does not show deployments' do
scenario 'does show no deployments' do
expect(page).to have_content('No deployments yet') expect(page).to have_content('No deployments yet')
end end
context 'for available environment' do it 'does not show stip button when environment is not stoppable' do
given(:environment) { create(:environment, project: project, state: :available) }
scenario 'does not shows stop button' do
expect(page).not_to have_selector('.stop-env-link') expect(page).not_to have_selector('.stop-env-link')
end end
end end
context 'for stopped environment' do context 'when there are deployments' do
given(:environment) { create(:environment, project: project, state: :stopped) }
scenario 'does not shows stop button' do
expect(page).not_to have_selector('.stop-env-link')
end
end
end
context 'with deployments' do
given(:project) { create(:project, :repository) } given(:project) { create(:project, :repository) }
given(:deployment) do given!(:deployment) do
create(:deployment, environment: environment, create(:deployment, environment: environment,
sha: project.commit.id) sha: project.commit.id)
end
scenario 'does show deployment SHA' do
expect(page).to have_link(deployment.short_sha)
end end
scenario 'does show deployment internal id' do it 'shows deployment SHA and internal ID' do
visit_environments(project)
expect(page).to have_link(deployment.short_sha)
expect(page).to have_content(deployment.iid) expect(page).to have_content(deployment.iid)
end end
context 'with build and manual actions' do context 'when builds and manual actions are present' do
given(:pipeline) { create(:ci_pipeline, project: project) } given!(:pipeline) { create(:ci_pipeline, project: project) }
given(:build) { create(:ci_build, pipeline: pipeline) } given!(:build) { create(:ci_build, pipeline: pipeline) }
given(:action) do given!(:action) do
create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production') create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production')
end end
given(:deployment) do given!(:deployment) do
create(:deployment, environment: environment, create(:deployment, environment: environment,
deployable: build, deployable: build,
sha: project.commit.id) sha: project.commit.id)
end end
scenario 'does show a play button' do before do
visit_environments(project)
end
it 'shows a play button' do
find('.js-dropdown-play-icon-container').click find('.js-dropdown-play-icon-container').click
expect(page).to have_content(action.name.humanize) expect(page).to have_content(action.name.humanize)
end end
scenario 'does allow to play manual action', js: true do it 'allows to play a manual action', js: true do
expect(action).to be_manual expect(action).to be_manual
find('.js-dropdown-play-icon-container').click find('.js-dropdown-play-icon-container').click
...@@ -155,19 +156,19 @@ feature 'Environments page', :js do ...@@ -155,19 +156,19 @@ feature 'Environments page', :js do
.not_to change { Ci::Pipeline.count } .not_to change { Ci::Pipeline.count }
end end
scenario 'does show build name and id' do it 'shows build name and id' do
expect(page).to have_link("#{build.name} ##{build.id}") expect(page).to have_link("#{build.name} ##{build.id}")
end end
scenario 'does not show stop button' do it 'shows a stop button' do
expect(page).not_to have_selector('.stop-env-link') expect(page).not_to have_selector('.stop-env-link')
end end
scenario 'does not show external link button' do it 'does not show external link button' do
expect(page).not_to have_css('external-url') expect(page).not_to have_css('external-url')
end end
scenario 'does not show terminal button' do it 'does not show terminal button' do
expect(page).not_to have_terminal_button expect(page).not_to have_terminal_button
end end
...@@ -176,7 +177,7 @@ feature 'Environments page', :js do ...@@ -176,7 +177,7 @@ feature 'Environments page', :js do
given(:build) { create(:ci_build, pipeline: pipeline) } given(:build) { create(:ci_build, pipeline: pipeline) }
given(:deployment) { create(:deployment, environment: environment, deployable: build) } given(:deployment) { create(:deployment, environment: environment, deployable: build) }
scenario 'does show an external link button' do it 'shows an external link button' do
expect(page).to have_link(nil, href: environment.external_url) expect(page).to have_link(nil, href: environment.external_url)
end end
end end
...@@ -192,34 +193,34 @@ feature 'Environments page', :js do ...@@ -192,34 +193,34 @@ feature 'Environments page', :js do
on_stop: 'close_app') on_stop: 'close_app')
end end
scenario 'does show stop button' do it 'shows a stop button' do
expect(page).to have_selector('.stop-env-link') expect(page).to have_selector('.stop-env-link')
end end
context 'for reporter' do context 'when user is a reporter' do
let(:role) { :reporter } let(:role) { :reporter }
scenario 'does not show stop button' do it 'does not show stop button' do
expect(page).not_to have_selector('.stop-env-link') expect(page).not_to have_selector('.stop-env-link')
end end
end end
end end
context 'with terminal' do context 'when kubernetes terminal is available' do
let(:project) { create(:kubernetes_project, :test_repo) } let(:project) { create(:kubernetes_project, :test_repo) }
context 'for project master' do context 'for project master' do
let(:role) { :master } let(:role) { :master }
scenario 'it shows the terminal button' do it 'shows the terminal button' do
expect(page).to have_terminal_button expect(page).to have_terminal_button
end end
end end
context 'for developer' do context 'when user is a developer' do
let(:role) { :developer } let(:role) { :developer }
scenario 'does not show terminal button' do it 'does not show terminal button' do
expect(page).not_to have_terminal_button expect(page).not_to have_terminal_button
end end
end end
...@@ -228,49 +229,41 @@ feature 'Environments page', :js do ...@@ -228,49 +229,41 @@ feature 'Environments page', :js do
end end
end end
scenario 'does have a New environment button' do it 'does have a new environment button' do
visit_environments(project)
expect(page).to have_link('New environment') expect(page).to have_link('New environment')
end end
describe 'when creating a new environment' do describe 'creating a new environment' do
before do before do
visit_environments(project) visit_environments(project)
end end
context 'when logged as developer' do context 'user is a developer' do
before do given(:role) { :developer }
within(".top-area") do
click_link 'New environment'
end
end
context 'for valid name' do scenario 'developer creates a new environment with a valid name' do
before do within(".top-area") { click_link 'New environment' }
fill_in('Name', with: 'production') fill_in('Name', with: 'production')
click_on 'Save' click_on 'Save'
end
scenario 'does create a new pipeline' do
expect(page).to have_content('production') expect(page).to have_content('production')
end end
end
context 'for invalid name' do scenario 'developer creates a new environmetn with invalid name' do
before do within(".top-area") { click_link 'New environment' }
fill_in('Name', with: 'name,with,commas') fill_in('Name', with: 'name,with,commas')
click_on 'Save' click_on 'Save'
end
scenario 'does show errors' do
expect(page).to have_content('Name can contain only letters') expect(page).to have_content('Name can contain only letters')
end end
end end
end
context 'when logged as reporter' do context 'user is a reporter' do
given(:role) { :reporter } given(:role) { :reporter }
scenario 'does not have a New environment link' do scenario 'reporters tries to create a new environment' do
expect(page).not_to have_link('New environment') expect(page).not_to have_link('New environment')
end end
end end
...@@ -280,7 +273,7 @@ feature 'Environments page', :js do ...@@ -280,7 +273,7 @@ feature 'Environments page', :js do
have_link(nil, href: terminal_project_environment_path(project, environment)) have_link(nil, href: terminal_project_environment_path(project, environment))
end end
def visit_environments(project) def visit_environments(project, **opts)
visit project_environments_path(project) visit project_environments_path(project, **opts)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment