2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-13 12:47:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Snippet', :js do
|
2017-04-13 12:47:28 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) }
|
|
|
|
|
|
|
|
context 'Ruby file' do
|
|
|
|
let(:file_name) { 'popen.rb' }
|
|
|
|
let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data }
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit snippet_path(snippet)
|
|
|
|
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-13 12:47:28 -04:00
|
|
|
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)')
|
2017-04-30 13:15:20 -04:00
|
|
|
|
|
|
|
# shows a raw button
|
|
|
|
expect(page).to have_link('Open raw')
|
|
|
|
|
|
|
|
# shows a download button
|
|
|
|
expect(page).to have_link('Download')
|
2017-04-13 12:47:28 -04:00
|
|
|
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)
|
|
|
|
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-13 12:47:28 -04:00
|
|
|
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')
|
2017-04-30 13:15:20 -04:00
|
|
|
|
|
|
|
# shows a raw button
|
|
|
|
expect(page).to have_link('Open raw')
|
|
|
|
|
|
|
|
# shows a download button
|
|
|
|
expect(page).to have_link('Download')
|
2017-04-13 12:47:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-02 11:24:27 -04:00
|
|
|
context 'Markdown rendering' do
|
|
|
|
let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) }
|
2018-07-06 14:49:33 -04:00
|
|
|
let(:file_name) { 'test.md' }
|
|
|
|
let(:content) { "1. one\n - sublist\n" }
|
|
|
|
|
2018-09-02 11:24:27 -04:00
|
|
|
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
|
2018-07-06 14:49:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-13 12:47:28 -04:00
|
|
|
context 'switching to the simple viewer' do
|
|
|
|
before do
|
|
|
|
find('.js-blob-viewer-switch-btn[data-viewer=simple]').click
|
|
|
|
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-13 12:47:28 -04:00
|
|
|
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
|
|
|
|
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-13 12:47:28 -04:00
|
|
|
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')
|
|
|
|
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-13 12:47:28 -04:00
|
|
|
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
|
2018-07-16 12:18:52 -04:00
|
|
|
|
|
|
|
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(:user_with_status) { snippet.author }
|
|
|
|
|
|
|
|
subject { visit snippet_path(snippet) }
|
|
|
|
end
|
2017-04-13 12:47:28 -04:00
|
|
|
end
|