Commit 40da4345 authored by ddavison's avatar ddavison

Add support for pre-made templates

Extract logic into separate component
Refactor some existing qa-classes into data-qa
parent 491b45b1
.custom-project-templates .custom-project-templates
- if custom_project_templates.present? - if custom_project_templates.present?
- custom_project_templates.each do |template| - custom_project_templates.each do |template|
.template-option.d-flex.align-items-center.qa-template-option-row .template-option.d-flex.align-items-center{ data: { qa_selector: 'template_option_row' } }
.avatar-container.s40 .avatar-container.s40
= project_icon(template, alt: template.name, class: 'btn-template-icon avatar s40 avatar-tile', lazy: false) = project_icon(template, alt: template.name, class: 'btn-template-icon avatar s40 avatar-tile', lazy: false)
.description .description
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
= _('Preview') = _('Preview')
%label.btn.btn-success.custom-template-button.choose-template.append-bottom-0{ for: template.name } %label.btn.btn-success.custom-template-button.choose-template.append-bottom-0{ for: template.name }
%input{ type: "radio", autocomplete: "off", name: "project[template_project_id]", id: template.name, value: template.id, data: { template_name: template.name } } %input{ type: "radio", autocomplete: "off", name: "project[template_project_id]", id: template.name, value: template.id, data: { template_name: template.name } }
%span.qa-use-template-button %span{ data: { qa_selector: 'use_template_button' } }
= _('Use template') = _('Use template')
= paginate custom_project_templates, params: {controller: 'users', action: 'available_project_templates', username: current_user.username}, theme: 'gitlab', remote: true = paginate custom_project_templates, params: {controller: 'users', action: 'available_project_templates', username: current_user.username}, theme: 'gitlab', remote: true
......
...@@ -417,6 +417,10 @@ module QA ...@@ -417,6 +417,10 @@ module QA
module WebIDE module WebIDE
autoload :Alert, 'qa/page/component/web_ide/alert' autoload :Alert, 'qa/page/component/web_ide/alert'
end end
module Project
autoload :Templates, 'qa/page/component/project/templates'
end
end end
end end
......
...@@ -43,12 +43,6 @@ module QA ...@@ -43,12 +43,6 @@ module QA
def instance_template_tab_badge_text def instance_template_tab_badge_text
find_element(:instance_template_tab_badge).text find_element(:instance_template_tab_badge).text
end end
def use_template_for_project(project_name)
within find_element(:template_option_row, text: project_name) do
click_element :use_template_button
end
end
end end
end end
end end
......
# frozen_string_literal: true
module QA
module Page::Component
module Project
module Templates
def use_template_for_project(project_name)
within find_element(:template_option_row, text: project_name) do
click_element :use_template_button
end
end
end
end
end
end
...@@ -5,6 +5,7 @@ module QA ...@@ -5,6 +5,7 @@ module QA
module Project module Project
class New < Page::Base class New < Page::Base
include Page::Component::Select2 include Page::Component::Select2
include Page::Component::Project::Templates
view 'app/views/projects/new.html.haml' do view 'app/views/projects/new.html.haml' do
element :project_create_from_template_tab element :project_create_from_template_tab
...@@ -26,6 +27,11 @@ module QA ...@@ -26,6 +27,11 @@ module QA
element :import_github, "icon('github', text: 'GitHub')" # rubocop:disable QA/ElementWithPattern element :import_github, "icon('github', text: 'GitHub')" # rubocop:disable QA/ElementWithPattern
end end
view 'app/views/projects/project_templates/_built_in_templates.html.haml' do
element :use_template_button
element :template_option_row
end
def choose_test_namespace def choose_test_namespace
choose_namespace(Runtime::Namespace.path) choose_namespace(Runtime::Namespace.path)
end end
......
...@@ -20,6 +20,7 @@ module QA ...@@ -20,6 +20,7 @@ module QA
attribute :standalone attribute :standalone
attribute :runners_token attribute :runners_token
attribute :visibility attribute :visibility
attribute :template_name
attribute :group do attribute :group do
Group.fabricate! Group.fabricate!
...@@ -52,6 +53,7 @@ module QA ...@@ -52,6 +53,7 @@ module QA
@initialize_with_readme = false @initialize_with_readme = false
@auto_devops_enabled = false @auto_devops_enabled = false
@visibility = :public @visibility = :public
@template_name = nil
end end
def name=(raw_name) def name=(raw_name)
...@@ -64,6 +66,13 @@ module QA ...@@ -64,6 +66,13 @@ module QA
Page::Group::Show.perform(&:go_to_new_project) Page::Group::Show.perform(&:go_to_new_project)
end end
if @template_name
Page::Project::New.perform do |new_page|
new_page.click_create_from_template_tab
new_page.use_template_for_project(@template_name)
end
end
Page::Project::New.perform do |new_page| Page::Project::New.perform do |new_page|
new_page.choose_test_namespace new_page.choose_test_namespace
new_page.choose_name(@name) new_page.choose_name(@name)
...@@ -127,6 +136,7 @@ module QA ...@@ -127,6 +136,7 @@ module QA
end end
post_body[:repository_storage] = repository_storage if repository_storage post_body[:repository_storage] = repository_storage if repository_storage
post_body[:template_name] = @template_name if @template_name
post_body post_body
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