Commit 66dccd28 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Fix transfer project qa tests

Updates the namespace selector used for
the transfer project qa tests

Fix broken controller specs

Ensures we redirect back to the edit
project page after transferring a project

Fix broken qa selector

Fix broken project settings rspec tests

Ensure we dont access the transfer project dataset
if there is no element mounted.

Fix broken jest test

Minor cleanup namespaces helper
parent 69de4417
...@@ -44,6 +44,7 @@ export default { ...@@ -44,6 +44,7 @@ export default {
<div> <div>
<gl-form-group> <gl-form-group>
<namespace-select <namespace-select
class="qa-namespaces-list"
data-testid="transfer-project-namespace" data-testid="transfer-project-namespace"
:full-width="true" :full-width="true"
:data="namespaces" :data="namespaces"
...@@ -52,6 +53,7 @@ export default { ...@@ -52,6 +53,7 @@ export default {
/> />
</gl-form-group> </gl-form-group>
<confirm-danger <confirm-danger
qa-button-class="qa-transfer-button"
:disabled="!hasSelectedNamespace" :disabled="!hasSelectedNamespace"
:phrase="confirmationPhrase" :phrase="confirmationPhrase"
:button-text="confirmButtonText" :button-text="confirmButtonText"
......
...@@ -12,6 +12,10 @@ const prepareNamespaces = (rawNamespaces = '') => { ...@@ -12,6 +12,10 @@ const prepareNamespaces = (rawNamespaces = '') => {
export default () => { export default () => {
const el = document.querySelector('.js-transfer-project-form'); const el = document.querySelector('.js-transfer-project-form');
if (!el) {
return false;
}
const { const {
targetFormId = null, targetFormId = null,
targetHiddenInputId = null, targetHiddenInputId = null,
...@@ -21,10 +25,6 @@ export default () => { ...@@ -21,10 +25,6 @@ export default () => {
namespaces = '', namespaces = '',
} = el.dataset; } = el.dataset;
if (!el) {
return false;
}
return new Vue({ return new Vue({
el, el,
provide: { provide: {
......
...@@ -36,6 +36,11 @@ export default { ...@@ -36,6 +36,11 @@ export default {
required: false, required: false,
default: 'confirm-danger-button', default: 'confirm-danger-button',
}, },
qaButtonClass: {
type: String,
required: false,
default: '',
},
}, },
modalId: CONFIRM_DANGER_MODAL_ID, modalId: CONFIRM_DANGER_MODAL_ID,
}; };
......
...@@ -47,7 +47,7 @@ export default { ...@@ -47,7 +47,7 @@ export default {
actionPrimary() { actionPrimary() {
return { return {
text: this.confirmButtonText, text: this.confirmButtonText,
attributes: [{ variant: 'danger', disabled: !this.isValid }], attributes: [{ variant: 'danger', disabled: !this.isValid, class: 'qa-confirm-button' }],
}; };
}, },
}, },
...@@ -95,7 +95,7 @@ export default { ...@@ -95,7 +95,7 @@ export default {
<gl-form-input <gl-form-input
id="confirm_name_input" id="confirm_name_input"
v-model="confirmationPhrase" v-model="confirmationPhrase"
class="form-control" class="form-control qa-confirm-input"
data-testid="confirm-danger-input" data-testid="confirm-danger-input"
type="text" type="text"
/> />
......
...@@ -68,22 +68,28 @@ export default { ...@@ -68,22 +68,28 @@ export default {
<gl-search-box-by-type v-model.trim="searchTerm" /> <gl-search-box-by-type v-model.trim="searchTerm" />
</template> </template>
<template v-if="hasGroupNamespaces"> <template v-if="hasGroupNamespaces">
<gl-dropdown-section-header>{{ __('Groups') }}</gl-dropdown-section-header> <div class="qa-namespaces-list-groups">
<gl-dropdown-item <gl-dropdown-section-header>{{ __('Groups') }}</gl-dropdown-section-header>
v-for="item in filteredGroupNamespaces" <gl-dropdown-item
:key="item.id" v-for="item in filteredGroupNamespaces"
@click="handleSelect(item)" :key="item.id"
>{{ item.humanName }}</gl-dropdown-item class="qa-namespaces-list-item"
> @click="handleSelect(item)"
>{{ item.humanName }}</gl-dropdown-item
>
</div>
</template> </template>
<template v-if="hasUserNamespaces"> <template v-if="hasUserNamespaces">
<gl-dropdown-section-header>{{ __('Users') }}</gl-dropdown-section-header> <div class="qa-namespaces-list-users">
<gl-dropdown-item <gl-dropdown-section-header>{{ __('Users') }}</gl-dropdown-section-header>
v-for="item in filteredUserNamespaces" <gl-dropdown-item
:key="item.id" v-for="item in filteredUserNamespaces"
@click="handleSelect(item)" :key="item.id"
>{{ item.humanName }}</gl-dropdown-item class="qa-namespaces-list-item"
> @click="handleSelect(item)"
>{{ item.humanName }}</gl-dropdown-item
>
</div>
</template> </template>
</gl-dropdown> </gl-dropdown>
</template> </template>
...@@ -120,6 +120,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -120,6 +120,8 @@ class ProjectsController < Projects::ApplicationController
if @project.errors[:new_namespace].present? if @project.errors[:new_namespace].present?
flash[:alert] = @project.errors[:new_namespace].first flash[:alert] = @project.errors[:new_namespace].first
end end
render_edit
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -90,8 +90,8 @@ module NamespacesHelper ...@@ -90,8 +90,8 @@ module NamespacesHelper
def namespaces_as_json(selected = :current_user) def namespaces_as_json(selected = :current_user)
{ {
group: formatted_namespaces(current_user.manageable_groups_with_routes, 'group'), group: formatted_namespaces(current_user.manageable_groups_with_routes),
user: formatted_namespaces([current_user.namespace], 'user') user: formatted_namespaces([current_user.namespace])
}.to_json }.to_json
end end
...@@ -127,17 +127,13 @@ module NamespacesHelper ...@@ -127,17 +127,13 @@ module NamespacesHelper
[group_label.camelize, elements] [group_label.camelize, elements]
end end
def formatted_namespaces(namespaces, type) def formatted_namespaces(namespaces)
namespaces.sort_by(&:human_name).map do |n| namespaces.sort_by(&:human_name).map! do |n|
{ {
id: n.id, id: n.id,
display_path: n.full_path, display_path: n.full_path,
human_name: n.human_name, human_name: n.human_name,
visibility_level: n.visibility_level_value, name: n.name
visibility: n.visibility,
name: n.name,
show_path: type == 'group' ? group_path(n) : user_path(n),
edit_path: type == 'group' ? edit_group_path(n) : nil
} }
end end
end end
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
.sub-section .sub-section
%h4.danger-title= _('Transfer project') %h4.danger-title= _('Transfer project')
= form_for @project, url: transfer_project_path(@project), method: :put, html: { class: "js-project-transfer-form", id: form_id } do |f| = form_for @project, url: transfer_project_path(@project), method: :put, html: { class: 'js-project-transfer-form', id: form_id } do |f|
.form-group .form-group
- link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/project/settings/index', anchor: 'transferring-an-existing-project-into-another-namespace') } - link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/project/settings/index', anchor: 'transferring-an-existing-project-into-another-namespace') }
%p= _("Transfer your project into another namespace. %{link_start}Learn more.%{link_end}").html_safe % { link_start: link_start, link_end: '</a>'.html_safe } %p= _("Transfer your project into another namespace. %{link_start}Learn more.%{link_end}").html_safe % { link_start: link_start, link_end: '</a>'.html_safe }
......
...@@ -5,16 +5,18 @@ module QA ...@@ -5,16 +5,18 @@ module QA
module Project module Project
module Settings module Settings
class Advanced < Page::Base class Advanced < Page::Base
include Component::Select2
include Component::ConfirmModal include Component::ConfirmModal
include Page::Component::DropdownFilter
view 'app/views/projects/edit.html.haml' do view 'app/views/projects/edit.html.haml' do
element :project_path_field element :project_path_field
element :change_path_button element :change_path_button
end end
view 'app/views/projects/_transfer.html.haml' do view "app/assets/javascripts/vue_shared/components/namespace_select/namespace_select.vue" do
element :transfer_button element :namespaces_list
element :namespaces_list_groups
element :namespaces_list_item
end end
view 'app/views/projects/settings/_archive.html.haml' do view 'app/views/projects/settings/_archive.html.haml' do
...@@ -42,16 +44,22 @@ module QA ...@@ -42,16 +44,22 @@ module QA
click_element :change_path_button click_element :change_path_button
end end
def select_namespace(item)
click_element :namespaces_list
within_element(:namespaces_list) do
find_element(:namespaces_list_item, text: item).click
end
end
def transfer_project!(project_name, namespace) def transfer_project!(project_name, namespace)
QA::Runtime::Logger.info "Transferring project: #{project_name} to namespace: #{namespace}" QA::Runtime::Logger.info "Transferring project: #{project_name} to namespace: #{namespace}"
click_element_coordinates(:archive_project_content) click_element_coordinates(:archive_project_content)
expand_select_list
# Workaround for a failure to search when there are no spaces around the / # Workaround for a failure to search when there are no spaces around the /
# https://gitlab.com/gitlab-org/gitlab/-/issues/218965 # https://gitlab.com/gitlab-org/gitlab/-/issues/218965
search_and_select(namespace.gsub(%r{([^\s])/([^\s])}, '\1 / \2')) select_namespace(namespace.gsub(%r{([^\s])/([^\s])}, '\1 / \2'))
click_element(:transfer_button) click_element(:transfer_button)
fill_confirmation_text(project_name) fill_confirmation_text(project_name)
......
// TODO: remove jquery dep
import $ from 'jquery'; import $ from 'jquery';
import { loadHTMLFixture } from 'helpers/fixtures'; import { loadHTMLFixture } from 'helpers/fixtures';
import setupTransferEdit from '~/transfer_edit'; import setupTransferEdit from '~/transfer_edit';
describe('setupTransferEdit', () => { describe('setupTransferEdit', () => {
const formSelector = '.js-project-transfer-form'; const formSelector = '.js-group-transfer-form';
const targetSelector = 'select.select2'; const targetSelector = '#new_parent_group_id';
beforeEach(() => { beforeEach(() => {
loadHTMLFixture('projects/edit.html'); loadHTMLFixture('groups/edit.html');
setupTransferEdit(formSelector, targetSelector); setupTransferEdit(formSelector, targetSelector);
}); });
...@@ -18,8 +17,8 @@ describe('setupTransferEdit', () => { ...@@ -18,8 +17,8 @@ describe('setupTransferEdit', () => {
}); });
it('enables submit button when selection changes to non-empty value', () => { it('enables submit button when selection changes to non-empty value', () => {
const nonEmptyValue = $(formSelector).find(targetSelector).find('option').not(':empty').val(); const lastValue = $(formSelector).find(targetSelector).find('.dropdown-content li').last();
$(formSelector).find(targetSelector).val(nonEmptyValue).trigger('change'); $(formSelector).find(targetSelector).val(lastValue).trigger('change');
expect($(formSelector).find(':submit').prop('disabled')).toBeFalsy(); expect($(formSelector).find(':submit').prop('disabled')).toBeFalsy();
}); });
......
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