summaryrefslogtreecommitdiff
path: root/spec/features/projects/snippets/create_snippet_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-17 12:09:37 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-17 12:09:37 +0000
commitc6283014fe69dc6699b00abedff607bd5c5718b0 (patch)
treeb54f2096e09cd8b2e0985a416947cda515d82fbf /spec/features/projects/snippets/create_snippet_spec.rb
parentafed1a4be18c74f8b95a0b8e0e359a1339ca1ad1 (diff)
downloadgitlab-ce-c6283014fe69dc6699b00abedff607bd5c5718b0.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/features/projects/snippets/create_snippet_spec.rb')
-rw-r--r--spec/features/projects/snippets/create_snippet_spec.rb138
1 files changed, 79 insertions, 59 deletions
diff --git a/spec/features/projects/snippets/create_snippet_spec.rb b/spec/features/projects/snippets/create_snippet_spec.rb
index 3db870f229a..503246bbdcf 100644
--- a/spec/features/projects/snippets/create_snippet_spec.rb
+++ b/spec/features/projects/snippets/create_snippet_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Projects > Snippets > Create Snippet', :js do
include DropzoneHelper
+ include Spec::Support::Helpers::Features::SnippetSpecHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) do
@@ -16,96 +17,115 @@ RSpec.describe 'Projects > Snippets > Create Snippet', :js do
let(:file_content) { 'Hello World!' }
let(:md_description) { 'My Snippet **Description**' }
let(:description) { 'My Snippet Description' }
+ let(:snippet_title_field) { 'project_snippet_title' }
- before do
- stub_feature_flags(snippets_vue: false)
- stub_feature_flags(snippets_edit_vue: false)
+ shared_examples 'snippet creation' do
+ def fill_form
+ snippet_fill_in_form(title: title, content: file_content, description: md_description)
+ end
- sign_in(user)
+ it 'shows collapsible description input' do
+ collapsed = description_field
- visit new_project_snippet_path(project)
- end
+ expect(page).not_to have_field(snippet_description_field)
+ expect(collapsed).to be_visible
- def description_field
- find('.js-description-input').find('input,textarea')
- end
+ collapsed.click
- def fill_form
- fill_in 'project_snippet_title', with: title
+ expect(page).to have_field(snippet_description_field)
+ expect(collapsed).not_to be_visible
+ end
- # Click placeholder first to expand full description field
- description_field.click
- fill_in 'project_snippet_description', with: md_description
+ it 'creates a new snippet' do
+ fill_form
+ click_button('Create snippet')
+ wait_for_requests
- page.within('.file-editor') do
- el = find('.inputarea')
- el.send_keys file_content
+ expect(page).to have_content(title)
+ expect(page).to have_content(file_content)
+ page.within(snippet_description_view_selector) do
+ expect(page).to have_content(description)
+ expect(page).to have_selector('strong')
+ end
end
- end
- it 'shows collapsible description input' do
- collapsed = description_field
+ it 'uploads a file when dragging into textarea' do
+ fill_form
+ dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif')
- expect(page).not_to have_field('project_snippet_description')
- expect(collapsed).to be_visible
+ expect(snippet_description_value).to have_content('banana_sample')
- collapsed.click
+ click_button('Create snippet')
+ wait_for_requests
- expect(page).to have_field('project_snippet_description')
- expect(collapsed).not_to be_visible
- end
+ link = find('a.no-attachment-icon img[alt="banana_sample"]')['src']
+ expect(link).to match(%r{/#{Regexp.escape(project.full_path)}/uploads/\h{32}/banana_sample\.gif\z})
+ end
+
+ context 'when the git operation fails' do
+ let(:error) { 'Error creating the snippet' }
- it 'creates a new snippet' do
- fill_form
- click_button('Create snippet')
- wait_for_requests
+ before do
+ allow_next_instance_of(Snippets::CreateService) do |instance|
+ allow(instance).to receive(:create_commit).and_raise(StandardError, error)
+ end
- expect(page).to have_content(title)
- expect(page).to have_content(file_content)
- page.within('.snippet-header .description') do
- expect(page).to have_content(description)
- expect(page).to have_selector('strong')
+ fill_form
+
+ click_button('Create snippet')
+ wait_for_requests
+ end
+
+ it 'renders the new page and displays the error' do
+ expect(page).to have_content(error)
+ expect(page).to have_content('New Snippet')
+ end
end
end
- it 'uploads a file when dragging into textarea' do
- fill_form
- dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif')
+ context 'Vue application' do
+ let(:snippet_description_field) { 'snippet-description' }
+ let(:snippet_description_view_selector) { '.snippet-header .snippet-description' }
- expect(page.find_field('project_snippet_description').value).to have_content('banana_sample')
+ before do
+ sign_in(user)
+
+ visit new_project_snippet_path(project)
+ end
- click_button('Create snippet')
- wait_for_requests
+ it_behaves_like 'snippet creation'
- link = find('a.no-attachment-icon img[alt="banana_sample"]')['src']
- expect(link).to match(%r{/#{Regexp.escape(project.full_path)}/uploads/\h{32}/banana_sample\.gif\z})
- end
+ it 'does not allow submitting the form without title and content' do
+ fill_in snippet_title_field, with: title
- it 'displays validation errors' do
- fill_in 'project_snippet_title', with: title
- click_button('Create snippet')
- wait_for_requests
+ expect(page).not_to have_button('Create snippet')
- expect(page).to have_selector('#error_explanation')
+ snippet_fill_in_form(title: title, content: file_content)
+ expect(page).to have_button('Create snippet')
+ end
end
- context 'when the git operation fails' do
- let(:error) { 'Error creating the snippet' }
+ context 'non-Vue application' do
+ let(:snippet_description_field) { 'project_snippet_description' }
+ let(:snippet_description_view_selector) { '.snippet-header .description' }
before do
- allow_next_instance_of(Snippets::CreateService) do |instance|
- allow(instance).to receive(:create_commit).and_raise(StandardError, error)
- end
+ stub_feature_flags(snippets_vue: false)
+ stub_feature_flags(snippets_edit_vue: false)
- fill_form
+ sign_in(user)
+ visit new_project_snippet_path(project)
+ end
+
+ it_behaves_like 'snippet creation'
+
+ it 'displays validation errors' do
+ fill_in snippet_title_field, with: title
click_button('Create snippet')
wait_for_requests
- end
- it 'renders the new page and displays the error' do
- expect(page).to have_content(error)
- expect(page).to have_content('New Snippet')
+ expect(page).to have_selector('#error_explanation')
end
end
end