2019-10-08 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-20 19:34:57 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe 'projects/blob/_viewer.html.haml' do
|
2017-04-25 16:22:56 -04:00
|
|
|
include FakeBlobHelpers
|
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { build(:project) }
|
2017-04-25 16:22:56 -04:00
|
|
|
|
|
|
|
let(:viewer_class) do
|
|
|
|
Class.new(BlobViewer::Base) do
|
|
|
|
include BlobViewer::Rich
|
|
|
|
|
|
|
|
self.partial_name = 'text'
|
2017-05-26 19:27:30 -04:00
|
|
|
self.collapse_limit = 1.megabyte
|
|
|
|
self.size_limit = 5.megabytes
|
2017-05-12 15:43:06 -04:00
|
|
|
self.load_async = true
|
2017-04-25 16:22:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:viewer) { viewer_class.new(blob) }
|
|
|
|
let(:blob) { fake_blob }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
2017-04-13 12:47:28 -04:00
|
|
|
assign(:blob, blob)
|
2017-04-25 16:22:56 -04:00
|
|
|
assign(:id, File.join('master', blob.path))
|
|
|
|
|
|
|
|
controller.params[:controller] = 'projects/blob'
|
|
|
|
controller.params[:action] = 'show'
|
|
|
|
controller.params[:namespace_id] = project.namespace.to_param
|
|
|
|
controller.params[:project_id] = project.to_param
|
|
|
|
controller.params[:id] = File.join('master', blob.path)
|
2018-09-06 00:34:25 -04:00
|
|
|
|
|
|
|
allow(project.repository).to receive(:gitattribute).and_return(nil)
|
2017-04-25 16:22:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_view
|
|
|
|
render partial: 'projects/blob/viewer', locals: { viewer: viewer }
|
|
|
|
end
|
|
|
|
|
2017-05-12 15:43:06 -04:00
|
|
|
context 'when the viewer is loaded asynchronously' do
|
2017-04-25 16:22:56 -04:00
|
|
|
before do
|
2017-05-12 15:43:06 -04:00
|
|
|
viewer_class.load_async = true
|
2017-04-25 16:22:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no render error' do
|
|
|
|
it 'adds a URL to the blob viewer element' do
|
|
|
|
render_view
|
|
|
|
|
|
|
|
expect(rendered).to have_css('.blob-viewer[data-url]')
|
|
|
|
end
|
|
|
|
|
2017-05-08 19:50:23 -04:00
|
|
|
it 'renders the loading indicator' do
|
2017-04-25 16:22:56 -04:00
|
|
|
render_view
|
|
|
|
|
2017-05-08 19:50:23 -04:00
|
|
|
expect(view).to render_template('projects/blob/viewers/_loading')
|
2017-04-25 16:22:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a render error' do
|
|
|
|
let(:blob) { fake_blob(size: 10.megabytes) }
|
|
|
|
|
|
|
|
it 'renders the error' do
|
|
|
|
render_view
|
|
|
|
|
|
|
|
expect(view).to render_template('projects/blob/_render_error')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 15:43:06 -04:00
|
|
|
context 'when the viewer is loaded synchronously' do
|
2017-04-25 16:22:56 -04:00
|
|
|
before do
|
2017-05-12 15:43:06 -04:00
|
|
|
viewer_class.load_async = false
|
2017-04-25 16:22:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no render error' do
|
|
|
|
it 'prepares the viewer' do
|
|
|
|
expect(viewer).to receive(:prepare!)
|
|
|
|
|
|
|
|
render_view
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the viewer' do
|
|
|
|
render_view
|
|
|
|
|
|
|
|
expect(view).to render_template('projects/blob/viewers/_text')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a render error' do
|
|
|
|
let(:blob) { fake_blob(size: 10.megabytes) }
|
|
|
|
|
|
|
|
it 'renders the error' do
|
|
|
|
render_view
|
|
|
|
|
|
|
|
expect(view).to render_template('projects/blob/_render_error')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-20 19:34:57 -04:00
|
|
|
end
|