diff --git a/app/views/layouts/header/_new_dropdown.haml b/app/views/layouts/header/_new_dropdown.haml index 5a66b02c0483208845fd4c08f9d2fdaa933f5a44..438340464bd7b2e1dd617136f89626f995862111 100644 --- a/app/views/layouts/header/_new_dropdown.haml +++ b/app/views/layouts/header/_new_dropdown.haml @@ -38,4 +38,4 @@ %li= link_to _('New project'), new_project_path, class: 'qa-global-new-project-link' - if current_user.can_create_group? %li= link_to _('New group'), new_group_path - %li= link_to _('New snippet'), new_snippet_path + %li= link_to _('New snippet'), new_snippet_path, class: 'qa-global-new-snippet-link' diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index f659c89dd30ee2530a5cc58f2a269e3473503255..1ec368f8910719b2e9ceaadfc91bb2985d7fc11c 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -29,7 +29,7 @@ - if dashboard_nav_link?(:snippets) = nav_link(controller: 'dashboard/snippets', html_options: { class: ["d-none d-xl-block", ("d-lg-block" unless has_extra_nav_icons?)] }) do - = link_to dashboard_snippets_path, class: 'dashboard-shortcuts-snippets', title: _('Snippets') do + = link_to dashboard_snippets_path, class: 'dashboard-shortcuts-snippets qa-snippets-link', title: _('Snippets') do = _('Snippets') - if any_dashboard_nav_link?([:groups, :milestones, :activity, :snippets]) diff --git a/app/views/projects/blob/_header_content.html.haml b/app/views/projects/blob/_header_content.html.haml index 4bef45932d0d965f13334875e4564b93c36b6bba..88fa31a73b08f13f158d02f7815214e78b447b4b 100644 --- a/app/views/projects/blob/_header_content.html.haml +++ b/app/views/projects/blob/_header_content.html.haml @@ -1,7 +1,7 @@ .file-header-content = blob_icon blob.mode, blob.name - %strong.file-title-name + %strong.file-title-name.qa-file-title-name = blob.name = copy_file_path_button(blob.path) diff --git a/app/views/shared/_file_highlight.html.haml b/app/views/shared/_file_highlight.html.haml index 5073e6ad48f4434d6804596db38791e2b083d48e..d7e57fc0d012358d43812e1b0174fd2133a2216d 100644 --- a/app/views/shared/_file_highlight.html.haml +++ b/app/views/shared/_file_highlight.html.haml @@ -1,4 +1,4 @@ -.file-content.code.js-syntax-highlight +.file-content.code.js-syntax-highlight.qa-file-content .line-numbers - if blob.data.present? - link_icon = icon('link') diff --git a/app/views/shared/snippets/_form.html.haml b/app/views/shared/snippets/_form.html.haml index 3007da0c189cbdebbc63b97df0e3ecf5d82fbce6..6f2ddc5bdbab6f45e940eb1207999b78da7ca4c0 100644 --- a/app/views/shared/snippets/_form.html.haml +++ b/app/views/shared/snippets/_form.html.haml @@ -9,7 +9,7 @@ .form-group.row = f.label :title, class: 'col-form-label col-sm-2' .col-sm-10 - = f.text_field :title, class: 'form-control', required: true, autofocus: true + = f.text_field :title, class: 'form-control qa-snippet-title', required: true, autofocus: true = render 'shared/form_elements/description', model: @snippet, project: @project, form: f @@ -21,7 +21,7 @@ .col-sm-10 .file-holder.snippet .js-file-title.file-title - = f.text_field :file_name, placeholder: "Optionally name this file to add code highlighting, e.g. example.rb for Ruby.", class: 'form-control snippet-file-name' + = f.text_field :file_name, placeholder: "Optionally name this file to add code highlighting, e.g. example.rb for Ruby.", class: 'form-control snippet-file-name qa-snippet-file-name' .file-content.code %pre#editor= @snippet.content = f.hidden_field :content, class: 'snippet-file-content' @@ -31,7 +31,7 @@ .form-actions - if @snippet.new_record? - = f.submit 'Create snippet', class: "btn-success btn" + = f.submit 'Create snippet', class: "btn-success btn qa-create-snippet-button" - else = f.submit 'Save changes', class: "btn-success btn" diff --git a/app/views/shared/snippets/_header.html.haml b/app/views/shared/snippets/_header.html.haml index a43296aa8065cc1b15fdf09d028dd52258e1a391..0c07eae86431b02ee72f6a11ba5c8b0f944c72d6 100644 --- a/app/views/shared/snippets/_header.html.haml +++ b/app/views/shared/snippets/_header.html.haml @@ -1,6 +1,6 @@ .detail-page-header .detail-page-header-body - .snippet-box.has-tooltip.inline.append-right-5{ title: snippet_visibility_level_description(@snippet.visibility_level, @snippet), data: { container: "body" } } + .snippet-box.qa-snippet-box.has-tooltip.inline.append-right-5{ title: snippet_visibility_level_description(@snippet.visibility_level, @snippet), data: { container: "body" } } %span.sr-only = visibility_level_label(@snippet.visibility_level) = visibility_level_icon(@snippet.visibility_level, fw: false) @@ -17,11 +17,11 @@ = render "snippets/actions" .snippet-header.limited-header-width - %h2.snippet-title.prepend-top-0.append-bottom-0 + %h2.snippet-title.prepend-top-0.append-bottom-0.qa-snippet-title = markdown_field(@snippet, :title) - if @snippet.description.present? - .description + .description.qa-snippet-description .wiki = markdown_field(@snippet, :description) %textarea.hidden.js-task-list-field @@ -34,7 +34,7 @@ .embed-snippet .input-group .input-group-prepend - %button.btn.btn-svg.embed-toggle.input-group-text{ 'data-toggle': 'dropdown', type: 'button' } + %button.btn.btn-svg.embed-toggle.input-group-text.qa-embed-type{ 'data-toggle': 'dropdown', type: 'button' } %span.js-embed-action= _("Embed") = sprite_icon('angle-down', size: 12, css_class: 'caret-down') %ul.dropdown-menu.dropdown-menu-selectable.embed-toggle-list diff --git a/qa/qa.rb b/qa/qa.rb index a79fecaab716b1bc1dbe08ea58b00d850e08853e..ec8aef31e48f554e4e35ed97f0d777bf1e6082d5 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -61,6 +61,7 @@ module QA autoload :File, 'qa/resource/file' autoload :Fork, 'qa/resource/fork' autoload :SSHKey, 'qa/resource/ssh_key' + autoload :Snippet, 'qa/resource/snippet' module Events autoload :Base, 'qa/resource/events/base' @@ -142,6 +143,12 @@ module QA module Dashboard autoload :Projects, 'qa/page/dashboard/projects' autoload :Groups, 'qa/page/dashboard/groups' + + module Snippet + autoload :New, 'qa/page/dashboard/snippet/new' + autoload :Index, 'qa/page/dashboard/snippet/index' + autoload :Show, 'qa/page/dashboard/snippet/show' + end end module Group diff --git a/qa/qa/page/dashboard/projects.rb b/qa/qa/page/dashboard/projects.rb index 0f434577b3b5f454eb0ce17290c73b1e82252ed6..271c5456efea657a70e3ad3f983192c9f0e2a254 100644 --- a/qa/qa/page/dashboard/projects.rb +++ b/qa/qa/page/dashboard/projects.rb @@ -2,8 +2,6 @@ module QA module Page module Dashboard class Projects < Page::Base - view 'app/views/dashboard/projects/index.html.haml' - view 'app/views/shared/projects/_search_form.html.haml' do element :form_filter_by_name, /form_tag.+id: 'project-filter-form'/ # rubocop:disable QA/ElementWithPattern end diff --git a/qa/qa/page/dashboard/snippet/index.rb b/qa/qa/page/dashboard/snippet/index.rb new file mode 100644 index 0000000000000000000000000000000000000000..1f467fda9e1cccbab6eddc0142efdc18f7128b33 --- /dev/null +++ b/qa/qa/page/dashboard/snippet/index.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module QA + module Page + module Dashboard + module Snippet + class Index < Page::Base + view 'app/views/layouts/header/_new_dropdown.haml' do + element :new_menu_toggle + element :global_new_snippet_link + end + + def go_to_new_snippet_page + click_element :new_menu_toggle + click_element :global_new_snippet_link + end + end + end + end + end +end diff --git a/qa/qa/page/dashboard/snippet/new.rb b/qa/qa/page/dashboard/snippet/new.rb new file mode 100644 index 0000000000000000000000000000000000000000..a637b869d2f632fb8cd746d1ffd00e9e5b578625 --- /dev/null +++ b/qa/qa/page/dashboard/snippet/new.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module QA + module Page + module Dashboard + module Snippet + class New < Page::Base + view 'app/views/shared/form_elements/_description.html.haml' do + element :issuable_form_description + end + + view 'app/views/shared/snippets/_form.html.haml' do + element :snippet_title + element :snippet_file_name + element :create_snippet_button + end + + def fill_title(title) + fill_element :snippet_title, title + end + + def fill_description(description) + fill_element :issuable_form_description, description + end + + def set_visibility(visibility) + choose visibility + end + + def fill_file_name(name) + finished_loading? + fill_element :snippet_file_name, name + end + + def fill_file_content(content) + finished_loading? + text_area.set content + end + + def create_snippet + click_element :create_snippet_button + end + + private + + def text_area + find('#editor>textarea', visible: false) + end + end + end + end + end +end diff --git a/qa/qa/page/dashboard/snippet/show.rb b/qa/qa/page/dashboard/snippet/show.rb new file mode 100644 index 0000000000000000000000000000000000000000..a75ea63eca7036fc87eca0cef4d04036031b1915 --- /dev/null +++ b/qa/qa/page/dashboard/snippet/show.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +module QA + module Page + module Dashboard + module Snippet + class Show < Page::Base + view 'app/views/shared/snippets/_header.html.haml' do + element :snippet_title + element :snippet_description + element :embed_type + element :snippet_box + end + + view 'app/views/projects/blob/_header_content.html.haml' do + element :file_title_name + end + + view 'app/views/shared/_file_highlight.html.haml' do + element :file_content + end + + def has_snippet_title?(snippet_title) + within_element(:snippet_title) do + has_text?(snippet_title) + end + end + + def has_snippet_description?(snippet_description) + within_element(:snippet_description) do + has_text?(snippet_description) + end + end + + def has_embed_type?(embed_type) + within_element(:embed_type) do + has_text?(embed_type) + end + end + + def has_visibility_type?(visibility_type) + within_element(:snippet_box) do + has_text?(visibility_type) + end + end + + def has_file_name?(file_name) + within_element(:file_title_name) do + has_text?(file_name) + end + end + + def has_file_content?(file_content) + finished_loading? + within_element(:file_content) do + has_text?(file_content) + end + end + end + end + end + end +end diff --git a/qa/qa/page/main/menu.rb b/qa/qa/page/main/menu.rb index 55500e831c66ae074bc0d4e9a3403757c11e8a78..1b3445b0064a56a85027892a30be8b30f5d3b8de 100644 --- a/qa/qa/page/main/menu.rb +++ b/qa/qa/page/main/menu.rb @@ -19,6 +19,7 @@ module QA element :admin_area_link element :projects_dropdown element :groups_dropdown + element :snippets_link end view 'app/views/layouts/nav/projects_dropdown/_show.html.haml' do @@ -66,6 +67,10 @@ module QA end end + def go_to_snippets + click_element :snippets_link + end + def has_personal_area?(wait: Capybara.default_max_wait_time) has_element?(:user_avatar, wait: wait) end diff --git a/qa/qa/resource/snippet.rb b/qa/qa/resource/snippet.rb new file mode 100644 index 0000000000000000000000000000000000000000..1478f1975707da967d8dc78461dbba04af508faf --- /dev/null +++ b/qa/qa/resource/snippet.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module QA + module Resource + class Snippet < Base + attr_accessor :title, :description, :file_content, :visibility, :file_name + + def initialize + @title = 'New snippet title' + @description = 'The snippet description' + @visibility = 'Public' + @file_content = 'The snippet content' + @file_name = 'New snippet file name' + end + + def fabricate! + Page::Dashboard::Snippet::Index.perform(&:go_to_new_snippet_page) + + Page::Dashboard::Snippet::New.perform do |page| + page.fill_title(@title) + page.fill_description(@description) + page.set_visibility(@visibility) + page.fill_file_name(@file_name) + page.fill_file_content(@file_content) + page.create_snippet + end + end + end + end +end diff --git a/qa/qa/specs/features/browser_ui/3_create/snippet/create_snippet_spec.rb b/qa/qa/specs/features/browser_ui/3_create/snippet/create_snippet_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..ab53dff464ea7f60e79e7cc8c170c2c4de4d5456 --- /dev/null +++ b/qa/qa/specs/features/browser_ui/3_create/snippet/create_snippet_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module QA + context 'Create', :smoke do + describe 'Snippet creation' do + it 'User creates a snippet' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.perform(&:sign_in_using_credentials) + + Page::Main::Menu.perform(&:go_to_snippets) + + Resource::Snippet.fabricate_via_browser_ui! do |snippet| + snippet.title = 'Snippet title' + snippet.description = 'Snippet description' + snippet.visibility = 'Public' + snippet.file_name = 'New snippet file name' + snippet.file_content = 'Snippet file text' + end + + Page::Dashboard::Snippet::Show.perform do |snippet| + expect(snippet).to have_snippet_title('Snippet title') + expect(snippet).to have_snippet_description('Snippet description') + expect(snippet).to have_embed_type('Embed') + expect(snippet).to have_visibility_type('Public') + expect(snippet).to have_file_name('New snippet file name') + expect(snippet).to have_file_content('Snippet file text') + end + end + end + end +end