diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2018-09-26 15:15:35 -0400 |
---|---|---|
committer | Mark Lapierre <mlapierre@gitlab.com> | 2018-09-27 14:22:50 -0400 |
commit | aa852b2d4f373d2b20ce985864324ca57b1890a5 (patch) | |
tree | 2d314778ac3614dcb50920d61a0d3f01b0e19843 | |
parent | 779169d337394be7cf2b76d01b42550d7a60b488 (diff) | |
download | gitlab-ce-aa852b2d4f373d2b20ce985864324ca57b1890a5.tar.gz |
Add test of adding file templates via Files view
Adds a test that adds new files via file templates via the Files view
Includes changes to page objects and associated code
-rw-r--r-- | app/views/projects/blob/_template_selectors.html.haml | 10 | ||||
-rw-r--r-- | app/views/projects/buttons/_dropdown.html.haml | 4 | ||||
-rw-r--r-- | qa/qa.rb | 1 | ||||
-rw-r--r-- | qa/qa/factory/resource/file.rb | 4 | ||||
-rw-r--r-- | qa/qa/page/component/dropdown_filter.rb | 18 | ||||
-rw-r--r-- | qa/qa/page/file/form.rb | 31 | ||||
-rw-r--r-- | qa/qa/page/project/show.rb | 10 | ||||
-rw-r--r-- | qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb | 58 |
8 files changed, 126 insertions, 10 deletions
diff --git a/app/views/projects/blob/_template_selectors.html.haml b/app/views/projects/blob/_template_selectors.html.haml index 5b092427496..2c8dd45670f 100644 --- a/app/views/projects/blob/_template_selectors.html.haml +++ b/app/views/projects/blob/_template_selectors.html.haml @@ -3,15 +3,15 @@ Template .template-selector-dropdowns-wrap .template-type-selector.js-template-type-selector-wrap.hidden - = dropdown_tag("Choose type", options: { toggle_class: 'js-template-type-selector', title: "Choose a template type" } ) + = dropdown_tag("Choose type", options: { toggle_class: 'js-template-type-selector qa-template-type-dropdown', title: "Choose a template type" } ) .license-selector.js-license-selector-wrap.js-template-selector-wrap.hidden - = dropdown_tag("Apply a license template", options: { toggle_class: 'js-license-selector', title: "Apply a license", filter: true, placeholder: "Filter", data: { data: licenses_for_select, project: @project.name, fullname: @project.namespace.human_name } } ) + = dropdown_tag("Apply a license template", options: { toggle_class: 'js-license-selector qa-license-dropdown', title: "Apply a license", filter: true, placeholder: "Filter", data: { data: licenses_for_select, project: @project.name, fullname: @project.namespace.human_name } } ) .gitignore-selector.js-gitignore-selector-wrap.js-template-selector-wrap.hidden - = dropdown_tag("Apply a .gitignore template", options: { toggle_class: 'js-gitignore-selector', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } ) + = dropdown_tag("Apply a .gitignore template", options: { toggle_class: 'js-gitignore-selector qa-gitignore-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } ) .gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.js-template-selector-wrap.hidden - = dropdown_tag("Apply a GitLab CI Yaml template", options: { toggle_class: 'js-gitlab-ci-yml-selector', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } ) + = dropdown_tag("Apply a GitLab CI Yaml template", options: { toggle_class: 'js-gitlab-ci-yml-selector qa-gitlab-ci-yml-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } ) .dockerfile-selector.js-dockerfile-selector-wrap.js-template-selector-wrap.hidden - = dropdown_tag("Apply a Dockerfile template", options: { toggle_class: 'js-dockerfile-selector', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names } } ) + = dropdown_tag("Apply a Dockerfile template", options: { toggle_class: 'js-dockerfile-selector qa-dockerfile-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names } } ) .template-selectors-undo-menu.hidden %span.text-info Template applied %button.btn.btn-sm.btn-info Undo diff --git a/app/views/projects/buttons/_dropdown.html.haml b/app/views/projects/buttons/_dropdown.html.haml index 8b9c52f0802..45515fb492f 100644 --- a/app/views/projects/buttons/_dropdown.html.haml +++ b/app/views/projects/buttons/_dropdown.html.haml @@ -8,7 +8,7 @@ - if show_menu .project-action-button.dropdown.inline - %a.btn.dropdown-toggle.has-tooltip{ href: '#', title: _('Create new...'), 'data-toggle' => 'dropdown', 'data-container' => 'body', 'aria-label' => _('Create new...'), 'data-display' => 'static' } + %a.btn.dropdown-toggle.has-tooltip.qa-create-new-dropdown{ href: '#', title: _('Create new...'), 'data-toggle' => 'dropdown', 'data-container' => 'body', 'aria-label' => _('Create new...'), 'data-display' => 'static' } = icon('plus') = icon("caret-down") %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown @@ -28,7 +28,7 @@ %li.dropdown-header= _('This repository') - if can_push_code - %li= link_to _('New file'), project_new_blob_path(@project, @project.default_branch || 'master') + %li.qa-new-file-option= link_to _('New file'), project_new_blob_path(@project, @project.default_branch || 'master') - unless @project.empty_repo? %li= link_to _('New branch'), new_project_branch_path(@project) %li= link_to _('New tag'), new_project_tag_path(@project) @@ -254,6 +254,7 @@ module QA autoload :Dropzone, 'qa/page/component/dropzone' autoload :GroupsFilter, 'qa/page/component/groups_filter' autoload :Select2, 'qa/page/component/select2' + autoload :DropdownFilter, 'qa/page/component/dropdown_filter' end end diff --git a/qa/qa/factory/resource/file.rb b/qa/qa/factory/resource/file.rb index 2016d10ddae..f8dea06d361 100644 --- a/qa/qa/factory/resource/file.rb +++ b/qa/qa/factory/resource/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module QA module Factory module Resource @@ -19,7 +21,7 @@ module QA def fabricate! project.visit! - Page::Project::Show.act { go_to_new_file! } + Page::Project::Show.act { create_new_file! } Page::File::Form.perform do |page| page.add_name(@name) diff --git a/qa/qa/page/component/dropdown_filter.rb b/qa/qa/page/component/dropdown_filter.rb new file mode 100644 index 00000000000..e896c382779 --- /dev/null +++ b/qa/qa/page/component/dropdown_filter.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module QA + module Page + module Component + module DropdownFilter + def filter_and_select(item) + wait(reload: false) do + page.has_css?('.dropdown-input-field') + end + + find('.dropdown-input-field').set(item) + click_link item + end + end + end + end +end diff --git a/qa/qa/page/file/form.rb b/qa/qa/page/file/form.rb index f6e502f500b..e14bd9fbf98 100644 --- a/qa/qa/page/file/form.rb +++ b/qa/qa/page/file/form.rb @@ -3,6 +3,7 @@ module QA module File class Form < Page::Base include Shared::CommitMessage + include Page::Component::DropdownFilter view 'app/views/projects/blob/_editor.html.haml' do element :file_name, "text_field_tag 'file_name'" @@ -13,6 +14,14 @@ module QA element :commit_changes, "button_tag 'Commit changes'" end + view 'app/views/projects/blob/_template_selectors.html.haml' do + element :template_type_dropdown + element :gitignore_dropdown + element :gitlab_ci_yml_dropdown + element :dockerfile_dropdown + element :license_dropdown + end + def add_name(name) fill_in 'file_name', with: name end @@ -29,6 +38,28 @@ module QA click_on 'Commit changes' end + def template_type=(template_type) + click_element :template_type_dropdown + click_link template_type + @template_type = template_type + end + + def template=(template) + case @template_type + when '.gitignore' + click_element :gitignore_dropdown + when '.gitlab-ci.yml' + click_element :gitlab_ci_yml_dropdown + when 'Dockerfile' + click_element :dockerfile_dropdown + when 'LICENSE' + click_element :license_dropdown + else + raise "Invalid template_type: #{@template_type}" + end + filter_and_select template + end + private def text_area diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 267e7bbc249..4990a30d0fa 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -35,12 +35,18 @@ module QA element :new_file_button, "_('New file')," end + view 'app/views/projects/buttons/_dropdown.html.haml' do + element :create_new_dropdown + element :new_file_option + end + def project_name find('.qa-project-name').text end - def go_to_new_file! - click_on 'New file' + def create_new_file! + click_element :create_new_dropdown + click_element :new_file_option end def switch_to_branch(branch_name) diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb new file mode 100644 index 00000000000..71152f16024 --- /dev/null +++ b/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module QA + context :create do + describe 'File templates' do + def login + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + end + + before(:all) do + login + + @project = Factory::Resource::Project.fabricate! do |project| + project.name = 'file-template-project' + project.description = 'Add file templates via the Files view' + end + + Page::Menu::Main.act { sign_out } + end + + templates = [ + ['.gitignore', 'Go', ['# Output of the go coverage tool']], + ['.gitlab-ci.yml', 'Ruby', ['# This file is a template', 'image: "ruby']], + ['Dockerfile', 'Python', ['FROM python:3.6']], + ['LICENSE', 'Mozilla Public License 2.0', ['Mozilla Public License Version 2.0']] + ] + + templates.each do |(file_name, template, contents)| + it "user adds #{file_name} via a file template" do + login + + @project.visit! + + Page::Project::Show.act { create_new_file! } + + Page::File::Form.perform do |page| + page.template_type = file_name + page.template = template + end + + expect(page).to have_content('Template applied') + expect(page).to have_button('Undo') + contents.each { |content| expect(page).to have_content(content) } + + Page::File::Form.perform do |page| + page.commit_changes + end + + expect(page).to have_content('The file has been successfully created.') + expect(page).to have_content(file_name) + expect(page).to have_content('Add new file') + contents.each { |content| expect(page).to have_content(content) } + end + end + end + end +end |