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
sign_in(user)
end
given!(:environment) { }
given!(:deployment) { }
given!(:action) { }
before do
describe 'page tabs' do
it 'shows "Available" and "Stopped" tab with links' do
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('Stopped')
end
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
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.all('.environment-name').length).to eq(1)
end
......@@ -37,7 +34,8 @@ feature 'Environments page', :js do
describe 'in stopped tab page' 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_content('You don\'t have any environments right now')
end
......@@ -45,11 +43,14 @@ feature 'Environments page', :js do
end
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
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_content('You don\'t have any environments right now')
end
......@@ -57,7 +58,8 @@ feature 'Environments page', :js do
describe 'in stopped tab page' 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.all('.environment-name').length).to eq(1)
end
......@@ -66,86 +68,85 @@ feature 'Environments page', :js do
end
context 'without environments' do
scenario 'does show no environments' do
expect(page).to have_content('You don\'t have any environments right now.')
before do
visit_environments(project)
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-stopped-environments-count').text).to eq('0')
end
end
describe 'when showing the environment' do
given(:environment) { create(:environment, project: project) }
describe 'environments table' do
given!(:environment) do
create(:environment, project: project, state: :available)
end
scenario 'does show environment name' do
expect(page).to have_link(environment.name)
context 'when there are no deployments' do
before do
visit_environments(project)
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-stopped-environments-count').text).to eq('0')
end
context 'without deployments' do
scenario 'does show no deployments' do
it 'does not show deployments' do
expect(page).to have_content('No deployments yet')
end
context 'for available environment' do
given(:environment) { create(:environment, project: project, state: :available) }
scenario 'does not shows stop button' do
it 'does not show stip button when environment is not stoppable' do
expect(page).not_to have_selector('.stop-env-link')
end
end
context 'for stopped environment' 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
context 'when there are deployments' do
given(:project) { create(:project, :repository) }
given(:deployment) do
given!(:deployment) do
create(:deployment, environment: environment,
sha: project.commit.id)
end
scenario 'does show deployment SHA' do
expect(page).to have_link(deployment.short_sha)
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)
end
context 'with build and manual actions' do
given(:pipeline) { create(:ci_pipeline, project: project) }
given(:build) { create(:ci_build, pipeline: pipeline) }
context 'when builds and manual actions are present' do
given!(:pipeline) { create(:ci_pipeline, project: project) }
given!(:build) { create(:ci_build, pipeline: pipeline) }
given(:action) do
given!(:action) do
create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production')
end
given(:deployment) do
given!(:deployment) do
create(:deployment, environment: environment,
deployable: build,
sha: project.commit.id)
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
expect(page).to have_content(action.name.humanize)
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
find('.js-dropdown-play-icon-container').click
......@@ -155,19 +156,19 @@ feature 'Environments page', :js do
.not_to change { Ci::Pipeline.count }
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}")
end
scenario 'does not show stop button' do
it 'shows a stop button' do
expect(page).not_to have_selector('.stop-env-link')
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')
end
scenario 'does not show terminal button' do
it 'does not show terminal button' do
expect(page).not_to have_terminal_button
end
......@@ -176,7 +177,7 @@ feature 'Environments page', :js do
given(:build) { create(:ci_build, pipeline: pipeline) }
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)
end
end
......@@ -192,34 +193,34 @@ feature 'Environments page', :js do
on_stop: 'close_app')
end
scenario 'does show stop button' do
it 'shows a stop button' do
expect(page).to have_selector('.stop-env-link')
end
context 'for reporter' do
context 'when user is a reporter' do
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')
end
end
end
context 'with terminal' do
context 'when kubernetes terminal is available' do
let(:project) { create(:kubernetes_project, :test_repo) }
context 'for project master' do
let(:role) { :master }
scenario 'it shows the terminal button' do
it 'shows the terminal button' do
expect(page).to have_terminal_button
end
end
context 'for developer' do
context 'when user is a developer' do
let(:role) { :developer }
scenario 'does not show terminal button' do
it 'does not show terminal button' do
expect(page).not_to have_terminal_button
end
end
......@@ -228,49 +229,41 @@ feature 'Environments page', :js do
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')
end
describe 'when creating a new environment' do
describe 'creating a new environment' do
before do
visit_environments(project)
end
context 'when logged as developer' do
before do
within(".top-area") do
click_link 'New environment'
end
end
context 'user is a developer' do
given(:role) { :developer }
context 'for valid name' do
before do
scenario 'developer creates a new environment with a valid name' do
within(".top-area") { click_link 'New environment' }
fill_in('Name', with: 'production')
click_on 'Save'
end
scenario 'does create a new pipeline' do
expect(page).to have_content('production')
end
end
context 'for invalid name' do
before do
scenario 'developer creates a new environmetn with invalid name' do
within(".top-area") { click_link 'New environment' }
fill_in('Name', with: 'name,with,commas')
click_on 'Save'
end
scenario 'does show errors' do
expect(page).to have_content('Name can contain only letters')
end
end
end
context 'when logged as reporter' do
context 'user is a reporter' do
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')
end
end
......@@ -280,7 +273,7 @@ feature 'Environments page', :js do
have_link(nil, href: terminal_project_environment_path(project, environment))
end
def visit_environments(project)
visit project_environments_path(project)
def visit_environments(project, **opts)
visit project_environments_path(project, **opts)
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