Commit 6a57f5cb authored by Sanad Liaquat's avatar Sanad Liaquat

Add QA test for instance project template

Also combines the group level project template into the same file as
instance level project template.
parent d94adda3
- if ::Gitlab::CurrentSettings.custom_project_templates_enabled?
%section.settings.as-custom-project-templates.no-animate#js-custom-project-templates-settings{ class: ('expanded' if expanded) }
%section.settings.as-custom-project-templates.no-animate#js-custom-project-templates-settings.qa-custom-project-template-section{ class: ('expanded' if expanded) }
.settings-header
%h4
= _('Custom project templates')
......@@ -14,6 +14,6 @@
%fieldset
.form-group
= groups_select_tag('application_setting[custom_project_templates_group_id]', selected: @application_setting.custom_project_templates_group_id, class: 'input-clamp allowClear', multiple: false)
= groups_select_tag('application_setting[custom_project_templates_group_id]', selected: @application_setting.custom_project_templates_group_id, class: 'input-clamp allowClear qa-custom-project-template-select', multiple: false)
= f.submit _('Save changes'), class: "btn btn-success"
= f.submit _('Save changes'), class: "btn btn-success qa-save-changes-button"
......@@ -9,9 +9,9 @@
= _('Built-in')
%span.badge.badge-pill= Gitlab::ProjectTemplate.all.count
%li.custom-instance-project-templates-tab
%a.nav-link.js-custom-instance-project-templates-nav-link{ href: "#custom-instance-project-templates", data: { toggle: 'tab'} }
%a.nav-link.js-custom-instance-project-templates-nav-link.qa-instance-templates-tab{ href: "#custom-instance-project-templates", data: { toggle: 'tab'} }
= _('Instance')
%span.badge.badge-pill= project_template_count
%span.badge.badge-pill.qa-instance-template-tab-badge= project_template_count
%li.custom-group-project-templates-tab
%a.nav-link.js-custom-group-project-templates-nav-link.qa-group-templates-tab{ href: "#custom-group-project-templates", data: { toggle: 'tab'} }
= _('Group')
......
.custom-project-templates
- if custom_project_templates.present?
- custom_project_templates.each do |template|
.template-option.d-flex.align-items-center
.template-option.d-flex.align-items-center.qa-template-option-row
.avatar-container.s40
= project_icon(template, alt: template.name, class: 'btn-template-icon avatar s40 avatar-tile', lazy: false)
.description
......@@ -15,7 +15,7 @@
= _('Preview')
%label.btn.btn-success.custom-template-button.choose-template.append-bottom-0{ for: template.name }
%input{ type: "radio", autocomplete: "off", name: "project[template_name]", id: template.name, value: template.name }
%span
%span.qa-use-template-button
= _('Use template')
= paginate custom_project_templates, params: {controller: 'users', action: 'available_project_templates', username: current_user.username}, theme: 'gitlab', remote: true
......
......@@ -44,6 +44,10 @@ module QA
autoload :New, 'qa/ee/page/admin/geo/nodes/new'
end
end
module Settings
autoload :Templates, 'qa/ee/page/admin/settings/templates'
end
end
module Profile
......
......@@ -10,6 +10,7 @@ module QA
view 'app/views/layouts/nav/sidebar/_admin.html.haml' do
element :link_license_menu
element :link_geo_menu
element :admin_settings_template_item
end
end
end
......@@ -21,6 +22,14 @@ module QA
def go_to_license
click_element :link_license_menu
end
def go_to_template_settings
hover_settings do
within_submenu do
click_element :admin_settings_template_item
end
end
end
end
end
end
......
# frozen_string_literal: true
module QA
module EE
module Page
module Admin
module Settings
class Templates < QA::Page::Base
include ::QA::Page::Settings::Common
include ::QA::Page::Component::Select2
view 'ee/app/views/admin/application_settings/_custom_templates_form.html.haml' do
element :custom_project_template_section
element :save_changes_button
end
def choose_custom_project_template(path)
expand_section(:custom_project_template_section)
within_element(:custom_project_template_select) do
clear_current_selection_if_present
end
click_element :custom_project_template_select
search_and_select(path)
click_element :save_changes_button
end
end
end
end
end
end
end
......@@ -10,12 +10,19 @@ module QA
view 'ee/app/views/projects/_project_templates.html.haml' do
element :group_templates_tab
element :group_template_tab_badge
element :instance_templates_tab
element :instance_template_tab_badge
end
view 'ee/app/views/users/_custom_project_templates_from_groups.html.haml' do
element :use_template_button
element :template_option_row
end
view 'ee/app/views/users/_custom_project_templates.html.haml' do
element :use_template_button
element :template_option_row
end
end
end
......@@ -24,10 +31,19 @@ module QA
click_element(:group_templates_tab)
end
def go_to_create_from_template_instance_tab
go_to_create_from_template
click_element(:instance_templates_tab)
end
def group_template_tab_badge_text
find_element(:group_template_tab_badge).text
end
def instance_template_tab_badge_text
find_element(:instance_template_tab_badge).text
end
def use_template_for_project(project_name)
within find_element(:template_option_row, text: project_name) do
click_element :use_template_button
......
# frozen_string_literal: true
require 'securerandom'
module QA
context 'Manage' do
describe 'Group level project template' do
let(:files) do
[
{
name: 'file.txt',
content: 'foo'
},
{
name: 'README.md',
content: 'bar'
}
]
end
it 'user creates and uses group level project template' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
template_container_group_name = "template-container-group-#{SecureRandom.hex(8)}"
group = QA::Resource::Group.fabricate! do |group|
group.path = template_container_group_name
group.description = 'Template container group'
end
template_project = Resource::Project.fabricate! do |project|
project.name = 'template-project-1'
project.group = group
end
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = template_project
push.files = files
push.commit_message = 'Add test files'
end
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform { |page| page.go_to_group(Runtime::Namespace.sandbox_name) }
Page::Project::Menu.perform(&:go_to_settings)
EE::Page::Group::Settings::General.perform do |settings|
settings.choose_custom_project_template("#{template_container_group_name}")
end
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform { |page| page.go_to_group(Runtime::Namespace.sandbox_name) }
Page::Group::Show.perform(&:go_to_new_project)
Page::Project::New.perform do |page|
page.go_to_create_from_template_group_tab
expect(page.group_template_tab_badge_text).to eq "1"
expect(page).to have_text(template_container_group_name)
expect(page).to have_text(template_project.name)
page.use_template_for_project(template_project.name)
page.choose_name('Project using group level project template')
page.add_description('Project using group level project template')
page.set_visibility('Public')
page.create_new_project
end
Page::Project::Show.perform(&:wait_for_import_success)
files.each do |file|
expect(page).to have_content(file[:name])
end
end
end
end
end
# frozen_string_literal: true
require 'securerandom'
module QA
context :manage do
describe 'Project templates' do
before(:all) do
@files = [
{
name: 'file.txt',
content: 'foo'
},
{
name: 'README.md',
content: 'bar'
}
]
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
@template_container_group_name = "instance-template-container-group-#{SecureRandom.hex(8)}"
template_container_group = QA::Resource::Group.fabricate! do |group|
group.path = @template_container_group_name
group.description = 'Instance template container group'
end
@template_project = Resource::Project.fabricate! do |project|
project.name = 'template-project-1'
project.group = template_container_group
end
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @template_project
push.files = @files
push.commit_message = 'Add test files'
end
end
context 'instance level' do
before do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
Page::Main::Menu.perform(&:go_to_admin_area)
Page::Admin::Menu.perform(&:go_to_template_settings)
EE::Page::Admin::Settings::Templates.perform do |page|
page.choose_custom_project_template("#{@template_container_group_name}")
end
group = Resource::Group.fabricate_via_api!
group.visit!
Page::Group::Show.perform(&:go_to_new_project)
Page::Project::New.perform(&:go_to_create_from_template_instance_tab)
end
it 'successfully imports the project using template' do
Page::Project::New.perform do |page|
expect(page.instance_template_tab_badge_text).to eq "1"
expect(page).to have_text(@template_project.name)
end
create_project_using_template(project_name: 'Project using instance level project template',
namespace: Runtime::Namespace.path,
template_name: @template_project.name)
Page::Project::Show.perform(&:wait_for_import_success)
@files.each do |file|
expect(page).to have_content(file[:name])
end
end
end
context 'group level' do
before do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform { |page| page.go_to_group(Runtime::Namespace.sandbox_name) }
Page::Project::Menu.perform(&:go_to_settings)
EE::Page::Group::Settings::General.perform do |settings|
settings.choose_custom_project_template("#{@template_container_group_name}")
end
group = Resource::Group.fabricate_via_api!
group.visit!
Page::Group::Show.perform(&:go_to_new_project)
Page::Project::New.perform(&:go_to_create_from_template_group_tab)
end
it 'successfully imports the project using template' do
Page::Project::New.perform do |page|
expect(page.group_template_tab_badge_text).to eq "1"
expect(page).to have_text(@template_container_group_name)
expect(page).to have_text(@template_project.name)
end
create_project_using_template(project_name: 'Project using group level project template',
namespace: Runtime::Namespace.sandbox_name,
template_name: @template_project.name)
Page::Project::Show.perform(&:wait_for_import_success)
@files.each do |file|
expect(page).to have_content(file[:name])
end
end
end
def create_project_using_template(project_name:, namespace:, template_name:)
Page::Project::New.perform do |page|
page.use_template_for_project(template_name)
page.choose_namespace(namespace)
page.choose_name("#{project_name} #{SecureRandom.hex(8)}")
page.add_description("#{project_name}")
page.set_visibility('Public')
page.create_new_project
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