BigW Consortium Gitlab

blob_line_permalink_updater_spec.rb 3.07 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js do
4 5 6 7 8 9 10 11 12 13 14 15
  include TreeHelper

  let(:project) { create(:project, :public, :repository) }
  let(:path) { 'CHANGELOG' }
  let(:sha) { project.repository.commit.sha }

  describe 'On a file(blob)' do
    def get_absolute_url(path = "")
      "http://#{page.server.host}:#{page.server.port}#{path}"
    end

    def visit_blob(fragment = nil)
16
      visit project_blob_path(project, tree_join('master', path), anchor: fragment)
17 18 19 20 21 22
    end

    describe 'Click "Permalink" button' do
      it 'works with no initial line number fragment hash' do
        visit_blob

23
        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path))))
24 25 26 27 28 29 30
      end

      it 'maintains intitial fragment hash' do
        fragment = "L3"

        visit_blob(fragment)

31
        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path), anchor: fragment)))
32 33 34 35 36 37 38 39 40 41
      end

      it 'changes fragment hash if line number clicked' do
        ending_fragment = "L5"

        visit_blob

        find('#L3').click
        find("##{ending_fragment}").click

42
        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path), anchor: ending_fragment)))
43 44 45 46 47 48 49 50 51 52 53
      end

      it 'with initial fragment hash, changes fragment hash if line number clicked' do
        fragment = "L1"
        ending_fragment = "L5"

        visit_blob(fragment)

        find('#L3').click
        find("##{ending_fragment}").click

54
        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path), anchor: ending_fragment)))
55 56 57
      end
    end

Stan Hu committed
58
    describe 'Click "Blame" button' do
59 60 61
      it 'works with no initial line number fragment hash' do
        visit_blob

62
        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path))))
63 64 65 66 67 68 69
      end

      it 'maintains intitial fragment hash' do
        fragment = "L3"

        visit_blob(fragment)

70
        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: fragment)))
71 72 73 74 75 76 77 78 79 80
      end

      it 'changes fragment hash if line number clicked' do
        ending_fragment = "L5"

        visit_blob

        find('#L3').click
        find("##{ending_fragment}").click

81
        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: ending_fragment)))
82 83 84 85 86 87 88 89 90 91 92
      end

      it 'with initial fragment hash, changes fragment hash if line number clicked' do
        fragment = "L1"
        ending_fragment = "L5"

        visit_blob(fragment)

        find('#L3').click
        find("##{ending_fragment}").click

93
        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: ending_fragment)))
94 95 96 97
      end
    end
  end
end