diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-28 15:10:28 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-28 15:10:28 +0000 |
commit | fcfd395a4b4d60f017a4512418a3a9e12cdc5e3a (patch) | |
tree | 6fe7879f93d1cbe3b93007911787caec92a90cde /spec/features | |
parent | 0d8df625a2ee3562cf1b2bdac46a429f69b06daf (diff) | |
download | gitlab-ce-fcfd395a4b4d60f017a4512418a3a9e12cdc5e3a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/features')
-rw-r--r-- | spec/features/projects/branches/user_deletes_branch_spec.rb | 33 | ||||
-rw-r--r-- | spec/features/projects/branches/user_views_branches_spec.rb | 11 | ||||
-rw-r--r-- | spec/features/projects/branches_spec.rb | 69 | ||||
-rw-r--r-- | spec/features/projects/environments/environment_spec.rb | 22 | ||||
-rw-r--r-- | spec/features/protected_branches_spec.rb | 50 |
5 files changed, 153 insertions, 32 deletions
diff --git a/spec/features/projects/branches/user_deletes_branch_spec.rb b/spec/features/projects/branches/user_deletes_branch_spec.rb index a5217007f3c..3b8f49accc5 100644 --- a/spec/features/projects/branches/user_deletes_branch_spec.rb +++ b/spec/features/projects/branches/user_deletes_branch_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "User deletes branch", :js do sign_in(user) end - it "deletes branch" do + it "deletes branch", :js do visit(project_branches_path(project)) branch_search = find('input[data-testid="branch-search"]') @@ -21,11 +21,38 @@ RSpec.describe "User deletes branch", :js do branch_search.native.send_keys(:enter) page.within(".js-branch-improve\\/awesome") do - accept_alert { click_link(title: 'Delete branch') } + find('.js-delete-branch-button').click + end + + page.within '.modal-footer' do + click_button 'Yes, delete branch' end wait_for_requests - expect(page).to have_css(".js-branch-improve\\/awesome", visible: :hidden) + expect(page).to have_content('Branch was deleted') + end + + context 'when the feature flag :delete_branch_confirmation_modals is disabled' do + before do + stub_feature_flags(delete_branch_confirmation_modals: false) + end + + it "deletes branch" do + visit(project_branches_path(project)) + + branch_search = find('input[data-testid="branch-search"]') + + branch_search.set('improve/awesome') + branch_search.native.send_keys(:enter) + + page.within(".js-branch-improve\\/awesome") do + accept_alert { click_link(title: 'Delete branch') } + end + + wait_for_requests + + expect(page).to have_css(".js-branch-improve\\/awesome", visible: :hidden) + end end end diff --git a/spec/features/projects/branches/user_views_branches_spec.rb b/spec/features/projects/branches/user_views_branches_spec.rb index 19d96579785..d0c0a0860d9 100644 --- a/spec/features/projects/branches/user_views_branches_spec.rb +++ b/spec/features/projects/branches/user_views_branches_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe "User views branches" do +RSpec.describe "User views branches", :js do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { project.owner } @@ -10,9 +10,12 @@ RSpec.describe "User views branches" do sign_in(user) end - context "all branches" do + context "all branches", :js do before do visit(project_branches_path(project)) + branch_search = find('input[data-testid="branch-search"]') + branch_search.set('master') + branch_search.native.send_keys(:enter) end it "shows branches" do @@ -20,6 +23,10 @@ RSpec.describe "User views branches" do expect(page.all(".graph-side")).to all( have_content(/\d+/) ) end + + it "displays a disabled button with a tooltip for the default branch that cannot be deleted", :js do + expect(page).to have_button('The default branch cannot be deleted', disabled: true) + end end context "protected branches" do diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb index 0c89ee28f30..0a79719f14a 100644 --- a/spec/features/projects/branches_spec.rb +++ b/spec/features/projects/branches_spec.rb @@ -88,10 +88,7 @@ RSpec.describe 'Branches' do it 'shows filtered branches', :js do visit project_branches_path(project) - branch_search = find('input[data-testid="branch-search"]') - - branch_search.set('fix') - branch_search.native.send_keys(:enter) + search_for_branch('fix') expect(page).to have_content('fix') expect(find('.all-branches')).to have_selector('li', count: 1) @@ -103,11 +100,10 @@ RSpec.describe 'Branches' do visit project_branches_filtered_path(project, state: 'all') expect(all('.all-branches').last).to have_selector('li', count: 20) - accept_confirm do - within('.js-branch-item', match: :first) { click_link(title: 'Delete branch') } - end - expect(all('.all-branches').last).to have_selector('li', count: 19) + delete_branch_and_confirm + + expect(page).to have_content('Branch was deleted') end end @@ -153,10 +149,7 @@ RSpec.describe 'Branches' do it 'shows filtered branches', :js do visit project_branches_filtered_path(project, state: 'all') - branch_search = find('input[data-testid="branch-search"]') - - branch_search.set('fix') - branch_search.native.send_keys(:enter) + search_for_branch('fix') expect(page).to have_content('fix') expect(find('.all-branches')).to have_selector('li', count: 1) @@ -167,19 +160,39 @@ RSpec.describe 'Branches' do it 'removes branch after confirmation', :js do visit project_branches_filtered_path(project, state: 'all') - branch_search = find('input[data-testid="branch-search"]') + search_for_branch('fix') - branch_search.set('fix') - branch_search.native.send_keys(:enter) + expect(all('.all-branches').last).to have_selector('li', count: 1) - expect(page).to have_content('fix') - expect(find('.all-branches')).to have_selector('li', count: 1) - accept_confirm do - within('.js-branch-fix') { click_link(title: 'Delete branch') } - end + delete_branch_and_confirm + + expect(page).to have_content('Branch was deleted') + + page.refresh + + search_for_branch('fix') expect(page).not_to have_content('fix') - expect(find('.all-branches')).to have_selector('li', count: 0) + expect(all('.all-branches').last).to have_selector('li', count: 0) + end + + context 'when the delete_branch_confirmation_modals feature flag is disabled' do + it 'removes branch after confirmation', :js do + stub_feature_flags(delete_branch_confirmation_modals: false) + + visit project_branches_filtered_path(project, state: 'all') + + search_for_branch('fix') + + expect(page).to have_content('fix') + expect(find('.all-branches')).to have_selector('li', count: 1) + accept_confirm do + within('.js-branch-item', match: :first) { click_link(title: 'Delete branch') } + end + + expect(page).not_to have_content('fix') + expect(find('.all-branches')).to have_selector('li', count: 0) + end end end @@ -327,4 +340,18 @@ RSpec.describe 'Branches' do def create_file(message: 'message', branch_name:) repository.create_file(user, generate(:branch), 'content', message: message, branch_name: branch_name) end + + def search_for_branch(name) + branch_search = find('input[data-testid="branch-search"]') + branch_search.set(name) + branch_search.native.send_keys(:enter) + end + + def delete_branch_and_confirm + find('.js-delete-branch-button', match: :first).click + + within '.modal-footer' do + click_button 'Yes, delete branch' + end + end end diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb index bc2ea540879..fea054de64e 100644 --- a/spec/features/projects/environments/environment_spec.rb +++ b/spec/features/projects/environments/environment_spec.rb @@ -329,11 +329,11 @@ RSpec.describe 'Environment' do expect(page).to have_button('Stop') end - it 'user deletes the branch with running environment' do + it 'user deletes the branch with running environment', :js do visit project_branches_filtered_path(project, state: 'all', search: 'feature') remove_branch_with_hooks(project, user, 'feature') do - within('.js-branch-feature') { click_link(title: 'Delete branch') } + page.within('.js-branch-feature') { find('.js-delete-branch-button').click } end visit_environment(environment) @@ -341,6 +341,24 @@ RSpec.describe 'Environment' do expect(page).not_to have_button('Stop') end + context 'when the feature flag :delete_branch_confirmation_modals is disabled' do + before do + stub_feature_flags(delete_branch_confirmation_modals: false) + end + + it 'user deletes the branch with running environment' do + visit project_branches_filtered_path(project, state: 'all', search: 'feature') + + remove_branch_with_hooks(project, user, 'feature') do + within('.js-branch-feature') { click_link(title: 'Delete branch') } + end + + visit_environment(environment) + + expect(page).not_to have_button('Stop') + end + end + ## # This is a workaround for problem described in #24543 # diff --git a/spec/features/protected_branches_spec.rb b/spec/features/protected_branches_spec.rb index 2436132297e..6fbed21acdb 100644 --- a/spec/features/protected_branches_spec.rb +++ b/spec/features/protected_branches_spec.rb @@ -27,7 +27,22 @@ RSpec.describe 'Protected Branches', :js do find('input[data-testid="branch-search"]').set('fix') find('input[data-testid="branch-search"]').native.send_keys(:enter) - expect(page).to have_selector('button[data-testid="remove-protected-branch"][disabled]') + expect(page).to have_button('Only a project maintainer or owner can delete a protected branch', disabled: true) + end + + context 'when feature flag :delete_branch_confirmation_modals is disabled' do + before do + stub_feature_flags(delete_branch_confirmation_modals: false) + end + + it 'does not allow developer to remove protected branch' do + visit project_branches_path(project) + + find('input[data-testid="branch-search"]').set('fix') + find('input[data-testid="branch-search"]').native.send_keys(:enter) + + expect(page).to have_selector('button[data-testid="remove-protected-branch"][disabled]') + end end end end @@ -52,17 +67,44 @@ RSpec.describe 'Protected Branches', :js do expect(page).to have_content('fix') expect(find('.all-branches')).to have_selector('li', count: 1) - page.find('[data-target="#modal-delete-branch"]').click - expect(page).to have_css('.js-delete-branch[disabled]') + expect(page).to have_button('Delete protected branch', disabled: false) + + page.find('.js-delete-branch-button').click fill_in 'delete_branch_input', with: 'fix' - click_link 'Delete protected branch' + click_button 'Yes, delete protected branch' find('input[data-testid="branch-search"]').set('fix') find('input[data-testid="branch-search"]').native.send_keys(:enter) expect(page).to have_content('No branches to show') end + + context 'when the feature flag :delete_branch_confirmation_modals is disabled' do + before do + stub_feature_flags(delete_branch_confirmation_modals: false) + end + + it 'removes branch after modal confirmation' do + visit project_branches_path(project) + + find('input[data-testid="branch-search"]').set('fix') + find('input[data-testid="branch-search"]').native.send_keys(:enter) + + expect(page).to have_content('fix') + expect(find('.all-branches')).to have_selector('li', count: 1) + page.find('[data-target="#modal-delete-branch"]').click + + expect(page).to have_css('.js-delete-branch[disabled]') + fill_in 'delete_branch_input', with: 'fix' + click_link 'Delete protected branch' + + find('input[data-testid="branch-search"]').set('fix') + find('input[data-testid="branch-search"]').native.send_keys(:enter) + + expect(page).to have_content('No branches to show') + end + end end end |