summaryrefslogtreecommitdiff
path: root/spec/features/projects/blobs/blob_show_spec.rb
blob: 9fbb17b370736bac3f41c4175760b53c18f17c27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'

feature 'File blob', feature: true do
  include TreeHelper

  let(:project) { create(:project, :public, :test_repo) }

  def visit_blob(path, fragment = nil)
    visit namespace_project_blob_path(project.namespace, project, tree_join('master', path), anchor: fragment)
  end

  context 'text files' do
    it 'shows rendered output for SVG' do
      visit_blob('files/images/wm.svg')

      expect(page).to have_selector('.blob-viewer[data-type="rich"]')
    end

    it 'switches to code view' do
      visit_blob('files/images/wm.svg')

      first('.js-blob-viewer-switcher').click

      expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false)
      expect(page).to have_selector('.blob-viewer[data-type="simple"]')
    end

    it 'opens raw mode when linking to a line in SVG file' do
      visit_blob('files/images/wm.svg', 'L1')

      expect(page).to have_selector('#LC1.hll')
      expect(page).to have_selector('.blob-viewer[data-type="simple"]')
    end

    it 'opens raw mode when linking to a line in MD file' do
      visit_blob('README.md', 'L1')

      expect(page).to have_selector('#LC1.hll')
      expect(page).to have_selector('.blob-viewer[data-type="simple"]')
    end
  end

  context 'binary files' do
    it 'does not show view toggle buttons in toolbar' do
      visit_blob('Gemfile.zip')

      expect(first('.file-actions .btn-group')).to have_selector('.btn', count: 1)
      expect(first('.file-actions .btn-group .btn')[:title]).to eq('Download blob')
    end
  end
end