Commit c485d2a0 authored by Mark Lapierre's avatar Mark Lapierre

Merge branch '15013-fork-project-form-spec' into 'master'

Extract fork spec into legacy and new fork form

See merge request gitlab-org/gitlab!55461
parents ac532636 149da90b
...@@ -9,49 +9,30 @@ RSpec.describe 'Project fork' do ...@@ -9,49 +9,30 @@ RSpec.describe 'Project fork' do
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
before do before do
stub_feature_flags(fork_project_form: false)
sign_in(user) sign_in(user)
end end
it 'allows user to fork project from the project page' do shared_examples 'fork button on project page' do
visit project_path(project) it 'allows user to fork project from the project page' do
expect(page).not_to have_css('a.disabled', text: 'Fork')
end
context 'user has exceeded personal project limit' do
before do
user.update!(projects_limit: 0)
end
it 'disables fork button on project page' do
visit project_path(project) visit project_path(project)
expect(page).to have_css('a.disabled', text: 'Fork') expect(page).not_to have_css('a.disabled', text: 'Fork')
end end
context 'with a group to fork to' do context 'user has exceeded personal project limit' do
let!(:group) { create(:group).tap { |group| group.add_owner(user) } } before do
user.update!(projects_limit: 0)
it 'enables fork button on project page' do
visit project_path(project)
expect(page).not_to have_css('a.disabled', text: 'Fork')
end end
it 'allows user to fork only to the group on fork page', :js do it 'disables fork button on project page' do
visit new_project_fork_path(project) visit project_path(project)
to_personal_namespace = find('[data-qa-selector=fork_namespace_button].disabled')
to_group = find(".fork-groups button[data-qa-name=#{group.name}]")
expect(to_personal_namespace).not_to be_nil expect(page).to have_css('a.disabled', text: 'Fork')
expect(to_group).not_to be_disabled
end end
end end
end end
context 'forking enabled / disabled in project settings' do shared_examples 'create fork page' do |fork_page_text|
before do before do
project.project_feature.update_attribute( project.project_feature.update_attribute(
:forking_access_level, forking_access_level) :forking_access_level, forking_access_level)
...@@ -71,7 +52,7 @@ RSpec.describe 'Project fork' do ...@@ -71,7 +52,7 @@ RSpec.describe 'Project fork' do
visit new_project_fork_path(project) visit new_project_fork_path(project)
expect(page.status_code).to eq(200) expect(page.status_code).to eq(200)
expect(page).to have_text(' Select a namespace to fork the project ') expect(page).to have_text(fork_page_text)
end end
end end
...@@ -128,92 +109,88 @@ RSpec.describe 'Project fork' do ...@@ -128,92 +109,88 @@ RSpec.describe 'Project fork' do
visit new_project_fork_path(project) visit new_project_fork_path(project)
expect(page.status_code).to eq(200) expect(page.status_code).to eq(200)
expect(page).to have_text(' Select a namespace to fork the project ') expect(page).to have_text(fork_page_text)
end end
end end
end end
end end
it 'forks the project', :sidekiq_might_not_need_inline do it_behaves_like 'fork button on project page'
visit project_path(project) it_behaves_like 'create fork page', 'Fork project'
click_link 'Fork'
page.within '.fork-thumbnail-container' do context 'with fork_project_form feature flag disabled' do
click_link 'Select' before do
stub_feature_flags(fork_project_form: false)
sign_in(user)
end end
expect(page).to have_content 'Forked from' it_behaves_like 'fork button on project page'
visit project_path(project) context 'user has exceeded personal project limit' do
before do
user.update!(projects_limit: 0)
end
expect(page).to have_content(/new merge request/i) context 'with a group to fork to' do
let!(:group) { create(:group).tap { |group| group.add_owner(user) } }
page.within '.nav-sidebar' do it 'allows user to fork only to the group on fork page', :js do
first(:link, 'Merge Requests').click visit new_project_fork_path(project)
end
expect(page).to have_content(/new merge request/i) to_personal_namespace = find('[data-qa-selector=fork_namespace_button].disabled')
to_group = find(".fork-groups button[data-qa-name=#{group.name}]")
page.within '#content-body' do expect(to_personal_namespace).not_to be_nil
click_link('New merge request') expect(to_group).not_to be_disabled
end
end
end end
expect(current_path).to have_content(/#{user.namespace.path}/i) it_behaves_like 'create fork page', ' Select a namespace to fork the project '
end
it 'shows avatars when Gravatar is disabled' do it 'forks the project', :sidekiq_might_not_need_inline do
stub_application_setting(gravatar_enabled: false) visit project_path(project)
visit project_path(project) click_link 'Fork'
click_link 'Fork' page.within '.fork-thumbnail-container' do
click_link 'Select'
end
page.within('.fork-thumbnail-container') do expect(page).to have_content 'Forked from'
expect(page).to have_css('div.identicon')
end
end
it 'shows the forked project on the list' do visit project_path(project)
visit project_path(project)
click_link 'Fork' expect(page).to have_content(/new merge request/i)
page.within '.fork-thumbnail-container' do page.within '.nav-sidebar' do
click_link 'Select' first(:link, 'Merge Requests').click
end end
visit project_forks_path(project) expect(page).to have_content(/new merge request/i)
forked_project = user.fork_of(project.reload) page.within '#content-body' do
click_link('New merge request')
end
page.within('.js-projects-list-holder') do expect(current_path).to have_content(/#{user.namespace.path}/i)
expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
end end
forked_project.update!(path: 'test-crappy-path') it 'shows avatars when Gravatar is disabled' do
stub_application_setting(gravatar_enabled: false)
visit project_forks_path(project)
page.within('.js-projects-list-holder') do visit project_path(project)
expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
end
end
context 'when the project is private' do click_link 'Fork'
let(:project) { create(:project, :repository) }
let(:another_user) { create(:user, name: 'Mike') }
before do page.within('.fork-thumbnail-container') do
project.add_reporter(user) expect(page).to have_css('div.identicon')
project.add_reporter(another_user) end
end end
it 'renders private forks of the project' do it 'shows the forked project on the list' do
visit project_path(project) visit project_path(project)
another_project_fork = Projects::ForkService.new(project, another_user).execute
click_link 'Fork' click_link 'Fork'
page.within '.fork-thumbnail-container' do page.within '.fork-thumbnail-container' do
...@@ -222,79 +199,117 @@ RSpec.describe 'Project fork' do ...@@ -222,79 +199,117 @@ RSpec.describe 'Project fork' do
visit project_forks_path(project) visit project_forks_path(project)
forked_project = user.fork_of(project.reload)
page.within('.js-projects-list-holder') do page.within('.js-projects-list-holder') do
user_project_fork = user.fork_of(project.reload) expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
expect(page).to have_content("#{user_project_fork.namespace.human_name} / #{user_project_fork.name}")
end end
expect(page).not_to have_content("#{another_project_fork.namespace.human_name} / #{another_project_fork.name}") forked_project.update!(path: 'test-crappy-path')
end
end
context 'when the user already forked the project' do visit project_forks_path(project)
before do
create(:project, :repository, name: project.name, namespace: user.namespace)
end
it 'renders error' do page.within('.js-projects-list-holder') do
visit project_path(project) expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
end
end
click_link 'Fork' context 'when the project is private' do
let(:project) { create(:project, :repository) }
let(:another_user) { create(:user, name: 'Mike') }
page.within '.fork-thumbnail-container' do before do
click_link 'Select' project.add_reporter(user)
project.add_reporter(another_user)
end end
expect(page).to have_content "Name has already been taken" it 'renders private forks of the project' do
end visit project_path(project)
end
context 'maintainer in group' do another_project_fork = Projects::ForkService.new(project, another_user).execute
let(:group) { create(:group) }
before do click_link 'Fork'
group.add_maintainer(user)
end
it 'allows user to fork project to group or to user namespace', :js do page.within '.fork-thumbnail-container' do
visit project_path(project) click_link 'Select'
wait_for_requests end
expect(page).not_to have_css('a.disabled', text: 'Fork') visit project_forks_path(project)
click_link 'Fork' page.within('.js-projects-list-holder') do
user_project_fork = user.fork_of(project.reload)
expect(page).to have_content("#{user_project_fork.namespace.human_name} / #{user_project_fork.name}")
end
expect(page).to have_css('.fork-thumbnail') expect(page).not_to have_content("#{another_project_fork.namespace.human_name} / #{another_project_fork.name}")
expect(page).to have_css('.group-row') end
expect(page).not_to have_css('.fork-thumbnail.disabled')
end end
it 'allows user to fork project to group and not user when exceeded project limit', :js do context 'when the user already forked the project' do
user.projects_limit = 0 before do
user.save! create(:project, :repository, name: project.name, namespace: user.namespace)
end
visit project_path(project) it 'renders error' do
wait_for_requests visit project_path(project)
expect(page).not_to have_css('a.disabled', text: 'Fork') click_link 'Fork'
click_link 'Fork' page.within '.fork-thumbnail-container' do
click_link 'Select'
end
expect(page).to have_css('.fork-thumbnail.disabled') expect(page).to have_content "Name has already been taken"
expect(page).to have_css('.group-row') end
end end
it 'links to the fork if the project was already forked within that namespace', :sidekiq_might_not_need_inline, :js do context 'maintainer in group' do
forked_project = fork_project(project, user, namespace: group, repository: true) let(:group) { create(:group) }
before do
group.add_maintainer(user)
end
it 'allows user to fork project to group or to user namespace', :js do
visit project_path(project)
wait_for_requests
expect(page).not_to have_css('a.disabled', text: 'Fork')
click_link 'Fork'
expect(page).to have_css('.fork-thumbnail')
expect(page).to have_css('.group-row')
expect(page).not_to have_css('.fork-thumbnail.disabled')
end
it 'allows user to fork project to group and not user when exceeded project limit', :js do
user.projects_limit = 0
user.save!
visit project_path(project)
wait_for_requests
expect(page).not_to have_css('a.disabled', text: 'Fork')
visit new_project_fork_path(project) click_link 'Fork'
wait_for_requests
expect(page).to have_css('.group-row a.btn', text: 'Go to fork') expect(page).to have_css('.fork-thumbnail.disabled')
expect(page).to have_css('.group-row')
end
it 'links to the fork if the project was already forked within that namespace', :sidekiq_might_not_need_inline, :js do
forked_project = fork_project(project, user, namespace: group, repository: true)
visit new_project_fork_path(project)
wait_for_requests
expect(page).to have_css('.group-row a.btn', text: 'Go to fork')
click_link 'Go to fork' click_link 'Go to fork'
expect(current_path).to eq(project_path(forked_project)) expect(current_path).to eq(project_path(forked_project))
end
end end
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