Commit c3f15d49 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'shl-e2e-forking-outside-of-group' into 'master'

Add end-to-end test for "Prevent forking outside of the group"

See merge request gitlab-org/gitlab!48677
parents f506606f 18963ba6
......@@ -85,6 +85,7 @@ export default {
v-model="filter"
:placeholder="$options.i18n.searchPlaceholder"
class="gl-align-self-center gl-ml-auto fork-filtered-search"
data-qa-selector="fork_groups_list_search_field"
/>
</template>
</gl-tabs>
......
......@@ -2,7 +2,7 @@
.form-group.gl-mb-3
.form-check
= f.check_box :prevent_forking_outside_group, checked: group.prevent_forking_outside_group?, class: 'form-check-input', disabled: !can_change_prevent_forking?(current_user, group)
= f.check_box :prevent_forking_outside_group, checked: group.prevent_forking_outside_group?, class: 'form-check-input', disabled: !can_change_prevent_forking?(current_user, group), data: { qa_selector: 'prevent_forking_outside_group_checkbox' }
= f.label :prevent_forking_outside_group, class: 'form-check-label' do
%span.gl-display-block= s_('GroupSettings|Prevent forking outside of the group')
%span.text-muted= s_('GroupSettings|This setting will prevent group members from forking projects outside of the group.')
......@@ -29,6 +29,10 @@ module QA
element :membership_lock_checkbox
end
view 'ee/app/views/groups/settings/_prevent_forking.html.haml' do
element :prevent_forking_outside_group_checkbox
end
view 'ee/app/views/shared/_repository_size_limit_setting.html.haml' do
element :repository_size_limit_field
end
......@@ -88,6 +92,18 @@ module QA
click_element :save_permissions_changes_button
end
def set_prevent_forking_outside_group_enabled
expand_content :permission_lfs_2fa_content
check_element :prevent_forking_outside_group_checkbox
click_element :save_permissions_changes_button
end
def set_prevent_forking_outside_group_disabled
expand_content :permission_lfs_2fa_content
uncheck_element :prevent_forking_outside_group_checkbox
click_element :save_permissions_changes_button
end
def set_repository_size_limit(limit)
find_element(:repository_size_limit_field).set limit
end
......
......@@ -9,9 +9,17 @@ module QA
element :fork_namespace_button
end
view 'app/assets/javascripts/pages/projects/forks/new/components/fork_groups_list.vue' do
element :fork_groups_list_search_field
end
def choose_namespace(namespace = Runtime::Namespace.path)
click_element(:fork_namespace_button, name: namespace)
end
def search_for_group(group_name)
find_element(:fork_groups_list_search_field).set(group_name)
end
end
end
end
......
......@@ -76,6 +76,19 @@ module QA
visibility: 'public'
}
end
def api_put_path
"/groups/#{id}"
end
def update_group_setting(group_setting:, value:)
put_body = { "#{group_setting}": value }
response = put Runtime::API::Request.new(api_client, api_put_path).url, put_body
unless response.code == HTTP_STATUS_OK
raise ResourceUpdateFailedError, "Could not update #{group_setting} to #{value}. Request returned (#{response.code}): `#{response}`."
end
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.describe 'Manage' do
describe 'prevent forking outside group' do
let!(:group_for_fork) do
Resource::Sandbox.fabricate_via_api! do |sandbox_group|
sandbox_group.path = "group_for_fork_#{SecureRandom.hex(8)}"
end
end
let(:project) do
Resource::Project.fabricate! do |project|
project.name = "project_to_fork"
project.initialize_with_readme = true
end
end
context 'when disabled' do
before do
set_prevent_forking_outside_group('disabled')
end
it 'allows forking outside of group', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1070' do
visit_project_and_search_group_for_fork
expect(page).to have_text(group_for_fork.path)
expect(page).to have_text('Select a namespace to fork the project')
end
end
context 'when enabled' do
before do
set_prevent_forking_outside_group('enabled')
end
it 'does not allow forking outside of group', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1107' do
visit_project_and_search_group_for_fork
expect(page).not_to have_text(group_for_fork.path)
expect(page).not_to have_text('Select a namespace to fork the project')
end
end
after do
project.group.sandbox.update_group_setting(group_setting: 'prevent_forking_outside_group', value: false)
project.remove_via_api!
group_for_fork.remove_via_api!
end
def set_prevent_forking_outside_group(enabled_or_disabled)
Flow::Login.sign_in
project.group.sandbox.visit!
Page::Group::Menu.perform(&:click_group_general_settings_item)
Page::Group::Settings::General.perform do |general_setting|
general_setting.send("set_prevent_forking_outside_group_#{enabled_or_disabled}")
end
end
def visit_project_and_search_group_for_fork
project.visit!
Page::Project::Show.perform(&:fork_project)
Page::Project::Fork::New.perform do |fork_new|
fork_new.search_for_group(group_for_fork.path)
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