diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-25 23:22:56 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 20:23:26 +0300 |
commit | 964e7d206b2c9ce0c884ee5c13fafa3763a142a2 (patch) | |
tree | 32ea77b2d528bef67b4ed526f8b5520ffea666ba /spec/views | |
parent | b73b16798dd0fe402df42a1e706f3b1034c22270 (diff) |
Add specs
Diffstat (limited to 'spec/views')
3 files changed, 94 insertions, 12 deletions
diff --git a/spec/views/projects/blob/_render_error.html.haml_spec.rb b/spec/views/projects/blob/_render_error.html.haml_spec.rb deleted file mode 100644 index fabd444a6ad..00000000000 --- a/spec/views/projects/blob/_render_error.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe 'app/views/projects/blob/_render_error.html.haml' do - # TODO: Test -end diff --git a/spec/views/projects/blob/_viewer.html.haml_spec.rb b/spec/views/projects/blob/_viewer.html.haml_spec.rb index 1d2055c10fc..c790dc79b0a 100644 --- a/spec/views/projects/blob/_viewer.html.haml_spec.rb +++ b/spec/views/projects/blob/_viewer.html.haml_spec.rb @@ -1,5 +1,97 @@ require 'spec_helper' -describe 'app/views/projects/blob/_viewer.html.haml' do - # TODO: Test +describe 'projects/blob/_viewer.html.haml', :view do + include FakeBlobHelpers + + let(:project) { build(:empty_project) } + + let(:viewer_class) do + Class.new(BlobViewer::Base) do + include BlobViewer::Rich + + self.partial_name = 'text' + self.max_size = 1.megabyte + self.absolute_max_size = 5.megabytes + self.client_side = false + end + end + + let(:viewer) { viewer_class.new(blob) } + let(:blob) { fake_blob } + + before do + assign(:project, project) + 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) + end + + def render_view + render partial: 'projects/blob/viewer', locals: { viewer: viewer } + end + + context 'when the viewer is server side' do + before do + viewer_class.client_side = false + 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 + + it 'displays a spinner' do + render_view + + expect(rendered).to have_css('i[aria-label="Loading content"]') + 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 + + context 'when the viewer is client side' do + before do + viewer_class.client_side = true + 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 end diff --git a/spec/views/projects/blob/_viewer_switcher.html.haml_spec.rb b/spec/views/projects/blob/_viewer_switcher.html.haml_spec.rb deleted file mode 100644 index 337f40d50df..00000000000 --- a/spec/views/projects/blob/_viewer_switcher.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe 'app/views/projects/blob/_viewer_switcher.html.haml' do - # TODO: Test -end |