summaryrefslogtreecommitdiff
path: root/spec/features/snippets
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/features/snippets
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/features/snippets')
-rw-r--r--spec/features/snippets/embedded_snippet_spec.rb22
-rw-r--r--spec/features/snippets/notes_on_personal_snippets_spec.rb11
-rw-r--r--spec/features/snippets/show_spec.rb167
-rw-r--r--spec/features/snippets/user_creates_snippet_spec.rb91
-rw-r--r--spec/features/snippets/user_edits_snippet_spec.rb8
5 files changed, 70 insertions, 229 deletions
diff --git a/spec/features/snippets/embedded_snippet_spec.rb b/spec/features/snippets/embedded_snippet_spec.rb
index 4f2ab598a6f..b799fb2fc00 100644
--- a/spec/features/snippets/embedded_snippet_spec.rb
+++ b/spec/features/snippets/embedded_snippet_spec.rb
@@ -3,11 +3,13 @@
require 'spec_helper'
RSpec.describe 'Embedded Snippets' do
- let(:snippet) { create(:personal_snippet, :public, file_name: 'random_dir.rb', content: content) }
- let(:content) { "require 'fileutils'\nFileUtils.mkdir_p 'some/random_dir'\n" }
+ let_it_be(:snippet) { create(:personal_snippet, :public, :repository) }
+ let(:blobs) { snippet.blobs.first(3) }
it 'loads snippet', :js do
- script_url = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/#{snippet_path(snippet, format: 'js')}"
+ expect_any_instance_of(Snippet).to receive(:blobs).and_return(blobs)
+
+ script_url = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}#{snippet_path(snippet, format: 'js')}"
embed_body = "<html><body><script src=\"#{script_url}\"></script></body></html>"
rack_app = proc do
@@ -19,9 +21,15 @@ RSpec.describe 'Embedded Snippets' do
visit("http://#{server.host}:#{server.port}/embedded_snippet.html")
- expect(page).to have_content("random_dir.rb")
- expect(page).to have_content("require 'fileutils'")
- expect(page).to have_link('Open raw')
- expect(page).to have_link('Download')
+ wait_for_requests
+
+ aggregate_failures do
+ blobs.each do |blob|
+ expect(page).to have_content(blob.path)
+ expect(page.find(".snippet-file-content .blob-content[data-blob-id='#{blob.id}'] code")).to have_content(blob.data.squish)
+ expect(page).to have_link('Open raw', href: /-\/snippets\/#{snippet.id}\/raw\/master\/#{blob.path}/)
+ expect(page).to have_link('Download', href: /-\/snippets\/#{snippet.id}\/raw\/master\/#{blob.path}\?inline=false/)
+ end
+ end
end
end
diff --git a/spec/features/snippets/notes_on_personal_snippets_spec.rb b/spec/features/snippets/notes_on_personal_snippets_spec.rb
index 55031183e10..e98bb22d3ea 100644
--- a/spec/features/snippets/notes_on_personal_snippets_spec.rb
+++ b/spec/features/snippets/notes_on_personal_snippets_spec.rb
@@ -120,6 +120,17 @@ RSpec.describe 'Comments on personal snippets', :js do
# but we want to make sure
expect(page).not_to have_selector('.atwho-view')
end
+
+ it_behaves_like 'personal snippet with references' do
+ let(:container) { 'div#notes' }
+
+ subject do
+ fill_in 'note[note]', with: references
+ click_button 'Comment'
+
+ wait_for_requests
+ end
+ end
end
context 'when editing a note' do
diff --git a/spec/features/snippets/show_spec.rb b/spec/features/snippets/show_spec.rb
index 9125ed74273..981ed12d540 100644
--- a/spec/features/snippets/show_spec.rb
+++ b/spec/features/snippets/show_spec.rb
@@ -3,180 +3,33 @@
require 'spec_helper'
RSpec.describe 'Snippet', :js do
- let(:project) { create(:project, :repository) }
- let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:snippet) { create(:personal_snippet, :public, :repository, author: user) }
before do
stub_feature_flags(snippets_vue: false)
end
- context 'Ruby file' do
- let(:file_name) { 'popen.rb' }
- let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data }
+ it_behaves_like 'show and render proper snippet blob' do
+ let(:anchor) { nil }
- before do
- visit snippet_path(snippet)
+ subject do
+ visit snippet_path(snippet, anchor: anchor)
wait_for_requests
end
-
- it 'displays the blob' do
- aggregate_failures do
- # shows highlighted Ruby code
- expect(page).to have_content("require 'fileutils'")
-
- # does not show a viewer switcher
- expect(page).not_to have_selector('.js-blob-viewer-switcher')
-
- # shows an enabled copy button
- expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)')
-
- # shows a raw button
- expect(page).to have_link('Open raw')
-
- # shows a download button
- expect(page).to have_link('Download')
- end
- end
- end
-
- context 'Markdown file' do
- let(:file_name) { 'ruby-style-guide.md' }
- let(:content) { project.repository.blob_at('master', 'files/markdown/ruby-style-guide.md').data }
-
- context 'visiting directly' do
- before do
- visit snippet_path(snippet)
-
- wait_for_requests
- end
-
- it 'displays the blob using the rich viewer' do
- aggregate_failures do
- # hides the simple viewer
- expect(page).to have_selector('.blob-viewer[data-type="simple"]', visible: false)
- expect(page).to have_selector('.blob-viewer[data-type="rich"]')
-
- # shows rendered Markdown
- expect(page).to have_link("PEP-8")
-
- # shows a viewer switcher
- expect(page).to have_selector('.js-blob-viewer-switcher')
-
- # shows a disabled copy button
- expect(page).to have_selector('.js-copy-blob-source-btn.disabled')
-
- # shows a raw button
- expect(page).to have_link('Open raw')
-
- # shows a download button
- expect(page).to have_link('Download')
- end
- end
-
- context 'Markdown rendering' do
- let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) }
- let(:file_name) { 'test.md' }
- let(:content) { "1. one\n - sublist\n" }
-
- context 'when rendering default markdown' do
- it 'renders using CommonMark' do
- expect(page).to have_content("sublist")
- expect(page).not_to have_xpath("//ol//li//ul")
- end
- end
- end
-
- context 'switching to the simple viewer' do
- before do
- find('.js-blob-viewer-switch-btn[data-viewer=simple]').click
-
- wait_for_requests
- end
-
- it 'displays the blob using the simple viewer' do
- aggregate_failures do
- # hides the rich viewer
- expect(page).to have_selector('.blob-viewer[data-type="simple"]')
- expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false)
-
- # shows highlighted Markdown code
- expect(page).to have_content("[PEP-8](http://www.python.org/dev/peps/pep-0008/)")
-
- # shows an enabled copy button
- expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)')
- end
- end
-
- context 'switching to the rich viewer again' do
- before do
- find('.js-blob-viewer-switch-btn[data-viewer=rich]').click
-
- wait_for_requests
- end
-
- it 'displays the blob using the rich viewer' do
- aggregate_failures do
- # hides the simple viewer
- expect(page).to have_selector('.blob-viewer[data-type="simple"]', visible: false)
- expect(page).to have_selector('.blob-viewer[data-type="rich"]')
-
- # shows an enabled copy button
- expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)')
- end
- end
- end
- end
- end
-
- context 'visiting with a line number anchor' do
- before do
- visit snippet_path(snippet, anchor: 'L1')
-
- wait_for_requests
- end
-
- it 'displays the blob using the simple viewer' do
- aggregate_failures do
- # hides the rich viewer
- expect(page).to have_selector('.blob-viewer[data-type="simple"]')
- expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false)
-
- # highlights the line in question
- expect(page).to have_selector('#LC1.hll')
-
- # shows highlighted Markdown code
- expect(page).to have_content("[PEP-8](http://www.python.org/dev/peps/pep-0008/)")
-
- # shows an enabled copy button
- expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)')
- end
- end
- end
end
it_behaves_like 'showing user status' do
- let(:file_name) { 'popen.rb' }
- let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data }
+ let(:file_path) { 'files/ruby/popen.rb' }
let(:user_with_status) { snippet.author }
subject { visit snippet_path(snippet) }
end
- context 'when user cannot create snippets' do
- let(:user) { create(:user, :external) }
- let(:snippet) { create(:personal_snippet, :public) }
-
- before do
- sign_in(user)
-
- visit snippet_path(snippet)
+ it_behaves_like 'does not show New Snippet button' do
+ let(:file_path) { 'files/ruby/popen.rb' }
- wait_for_requests
- end
-
- it 'does not show the "New Snippet" button' do
- expect(page).not_to have_link('New snippet')
- end
+ subject { visit snippet_path(snippet) }
end
end
diff --git a/spec/features/snippets/user_creates_snippet_spec.rb b/spec/features/snippets/user_creates_snippet_spec.rb
index b100e035d38..f4c6536d6d3 100644
--- a/spec/features/snippets/user_creates_snippet_spec.rb
+++ b/spec/features/snippets/user_creates_snippet_spec.rb
@@ -2,7 +2,17 @@
require 'spec_helper'
-RSpec.shared_examples_for 'snippet editor' do
+RSpec.describe 'User creates snippet', :js do
+ include DropzoneHelper
+
+ let_it_be(:user) { create(:user) }
+
+ let(:title) { 'My Snippet Title' }
+ let(:file_content) { 'Hello World!' }
+ let(:md_description) { 'My Snippet **Description**' }
+ let(:description) { 'My Snippet Description' }
+ let(:created_snippet) { Snippet.last }
+
before do
stub_feature_flags(snippets_vue: false)
stub_feature_flags(snippets_edit_vue: false)
@@ -14,15 +24,15 @@ RSpec.shared_examples_for 'snippet editor' do
end
def fill_form
- fill_in 'personal_snippet_title', with: 'My Snippet Title'
+ fill_in 'personal_snippet_title', with: title
# Click placeholder first to expand full description field
description_field.click
- fill_in 'personal_snippet_description', with: 'My Snippet **Description**'
+ fill_in 'personal_snippet_description', with: md_description
page.within('.file-editor') do
el = find('.inputarea')
- el.send_keys 'Hello World!'
+ el.send_keys file_content
end
end
@@ -34,12 +44,12 @@ RSpec.shared_examples_for 'snippet editor' do
click_button('Create snippet')
wait_for_requests
- expect(page).to have_content('My Snippet Title')
+ expect(page).to have_content(title)
page.within('.snippet-header .description') do
- expect(page).to have_content('My Snippet Description')
+ expect(page).to have_content(description)
expect(page).to have_selector('strong')
end
- expect(page).to have_content('Hello World!')
+ expect(page).to have_content(file_content)
end
it 'previews a snippet with file' do
@@ -57,7 +67,7 @@ RSpec.shared_examples_for 'snippet editor' do
link = find('a.no-attachment-icon img.js-lazy-loaded[alt="banana_sample"]')['src']
expect(link).to match(%r{/uploads/-/system/user/#{user.id}/\h{32}/banana_sample\.gif\z})
- # Adds a cache buster for checking if the image exists as Selenium is now handling the cached regquests
+ # Adds a cache buster for checking if the image exists as Selenium is now handling the cached requests
# not anymore as requests when they come straight from memory cache.
reqs = inspect_requests { visit("#{link}?ran=#{SecureRandom.base64(20)}") }
expect(reqs.first.status_code).to eq(200)
@@ -99,15 +109,10 @@ RSpec.shared_examples_for 'snippet editor' do
wait_for_requests
end
- it 'displays the error' do
+ it 'renders the new page and displays the error' do
expect(page).to have_content(error)
- end
-
- it 'renders new page' do
expect(page).to have_content('New Snippet')
- end
- it 'has the correct action path' do
action = find('form.snippet-form')['action']
expect(action).to match(%r{/snippets\z})
end
@@ -116,46 +121,10 @@ RSpec.shared_examples_for 'snippet editor' do
it 'validation fails for the first time' do
visit new_snippet_path
- fill_in 'personal_snippet_title', with: 'My Snippet Title'
+ fill_in 'personal_snippet_title', with: title
click_button('Create snippet')
expect(page).to have_selector('#error_explanation')
-
- fill_form
- dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif')
-
- click_button('Create snippet')
- wait_for_requests
-
- expect(page).to have_content('My Snippet Title')
- page.within('.snippet-header .description') do
- expect(page).to have_content('My Snippet Description')
- expect(page).to have_selector('strong')
- end
- expect(page).to have_content('Hello World!')
- link = find('a.no-attachment-icon img.js-lazy-loaded[alt="banana_sample"]')['src']
- expect(link).to match(%r{/uploads/-/system/personal_snippet/#{Snippet.last.id}/\h{32}/banana_sample\.gif\z})
-
- reqs = inspect_requests { visit("#{link}?ran=#{SecureRandom.base64(20)}") }
- expect(reqs.first.status_code).to eq(200)
- end
-
- it 'Authenticated user creates a snippet with + in filename' do
- visit new_snippet_path
-
- fill_in 'personal_snippet_title', with: 'My Snippet Title'
- page.within('.file-editor') do
- find(:xpath, "//input[@id='personal_snippet_file_name']").set 'snippet+file+name'
- el = find('.inputarea')
- el.send_keys 'Hello World!'
- end
-
- click_button 'Create snippet'
- wait_for_requests
-
- expect(page).to have_content('My Snippet Title')
- expect(page).to have_content('snippet+file+name')
- expect(page).to have_content('Hello World!')
end
context 'when snippets default visibility level is restricted' do
@@ -172,20 +141,20 @@ RSpec.shared_examples_for 'snippet editor' do
click_button('Create snippet')
wait_for_requests
- visit snippets_path
- click_link('Internal')
-
- expect(page).to have_content('My Snippet Title')
- created_snippet = Snippet.last
expect(created_snippet.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
end
end
-end
-RSpec.describe 'User creates snippet', :js do
- include DropzoneHelper
+ it_behaves_like 'personal snippet with references' do
+ let(:container) { '.snippet-header .description' }
+ let(:md_description) { references }
- let_it_be(:user) { create(:user) }
+ subject do
+ visit new_snippet_path
+ fill_form
+ click_button('Create snippet')
- it_behaves_like "snippet editor"
+ wait_for_requests
+ end
+ end
end
diff --git a/spec/features/snippets/user_edits_snippet_spec.rb b/spec/features/snippets/user_edits_snippet_spec.rb
index 3692b0d1ad8..5773904dedf 100644
--- a/spec/features/snippets/user_edits_snippet_spec.rb
+++ b/spec/features/snippets/user_edits_snippet_spec.rb
@@ -56,8 +56,8 @@ RSpec.describe 'User edits snippet', :js do
click_button 'Save changes'
wait_for_requests
- expect(page).to have_no_xpath("//i[@class='fa fa-lock']")
- expect(page).to have_xpath("//i[@class='fa fa-shield']")
+ expect(page).to have_no_selector('[data-testid="lock-icon"]')
+ expect(page).to have_selector('[data-testid="shield-icon"]')
end
it 'updates the snippet to make it public' do
@@ -66,8 +66,8 @@ RSpec.describe 'User edits snippet', :js do
click_button 'Save changes'
wait_for_requests
- expect(page).to have_no_xpath("//i[@class='fa fa-lock']")
- expect(page).to have_xpath("//i[@class='fa fa-globe']")
+ expect(page).to have_no_selector('[data-testid="lock-icon"]')
+ expect(page).to have_selector('[data-testid="earth-icon"]')
end
context 'when the git operation fails' do