2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe SnippetsHelper do
|
2019-12-26 22:10:19 +05:30
|
|
|
include Gitlab::Routing
|
2018-10-15 14:42:47 +05:30
|
|
|
include IconsHelper
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
let_it_be(:public_personal_snippet) { create(:personal_snippet, :public, :repository) }
|
|
|
|
let_it_be(:public_project_snippet) { create(:project_snippet, :public, :repository) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe '#embedded_raw_snippet_button' do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:blob) { snippet.blobs.first }
|
|
|
|
let(:ref) { blob.repository.root_ref }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
subject { embedded_raw_snippet_button(snippet, blob) }
|
|
|
|
|
|
|
|
context 'for Personal Snippets' do
|
|
|
|
let(:snippet) { public_personal_snippet }
|
|
|
|
|
|
|
|
it 'returns view raw button of embedded snippets' do
|
|
|
|
expect(subject).to eq(download_link("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}"))
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'for Project Snippets' do
|
|
|
|
let(:snippet) { public_project_snippet }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it 'returns view raw button of embedded snippets' do
|
|
|
|
expect(subject).to eq(download_link("http://test.host/#{snippet.project.path_with_namespace}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}"))
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def download_link(url)
|
2021-04-29 21:17:54 +05:30
|
|
|
"<a class=\"gl-button btn btn-default\" target=\"_blank\" rel=\"noopener noreferrer\" title=\"Open raw\" href=\"#{url}\">#{external_snippet_icon('doc-code')}</a>"
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#embedded_snippet_download_button' do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:blob) { snippet.blobs.first }
|
|
|
|
let(:ref) { blob.repository.root_ref }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
subject { embedded_snippet_download_button(snippet, blob) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'for Personal Snippets' do
|
|
|
|
let(:snippet) { public_personal_snippet }
|
|
|
|
|
|
|
|
it 'returns download button of embedded snippets' do
|
|
|
|
expect(subject).to eq(download_link("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}"))
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'for Project Snippets' do
|
|
|
|
let(:snippet) { public_project_snippet }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it 'returns download button of embedded snippets' do
|
|
|
|
expect(subject).to eq(download_link("http://test.host/#{snippet.project.path_with_namespace}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}"))
|
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def download_link(url)
|
2021-04-29 21:17:54 +05:30
|
|
|
"<a class=\"gl-button btn btn-default\" target=\"_blank\" title=\"Download\" rel=\"noopener noreferrer\" href=\"#{url}?inline=false\">#{external_snippet_icon('download')}</a>"
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#snippet_badge' do
|
|
|
|
let(:snippet) { build(:personal_snippet, visibility) }
|
|
|
|
|
|
|
|
subject { snippet_badge(snippet) }
|
|
|
|
|
|
|
|
context 'when snippet is private' do
|
|
|
|
let(:visibility) { :private }
|
|
|
|
|
|
|
|
it 'returns the snippet badge' do
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(subject).to eq "<span class=\"badge badge-gray\">#{sprite_icon('lock', size: 14, css_class: 'gl-vertical-align-middle')} private</span>"
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when snippet is public' do
|
|
|
|
let(:visibility) { :public }
|
|
|
|
|
|
|
|
it 'does not return anything' do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when snippet is internal' do
|
|
|
|
let(:visibility) { :internal }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'does not return anything' do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|