summaryrefslogtreecommitdiff
path: root/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb
blob: d94204230f617652d820e3c3b5ddb884226c78db (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'spec_helper'

feature 'Blob button line permalinks (BlobLinePermalinkUpdater)', feature: true, js: true do
  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)
      visit namespace_project_blob_path(project.namespace, project, tree_join('master', path), anchor: fragment)
    end

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

        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(namespace_project_blob_path(project.namespace, project, tree_join(sha, path))))
      end

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

        visit_blob(fragment)

        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(namespace_project_blob_path(project.namespace, project, tree_join(sha, path), anchor: fragment)))
      end

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

        visit_blob

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

        expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(namespace_project_blob_path(project.namespace, project, tree_join(sha, path), anchor: ending_fragment)))
      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

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

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

        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(namespace_project_blame_path(project.namespace, project, tree_join('master', path))))
      end

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

        visit_blob(fragment)

        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(namespace_project_blame_path(project.namespace, project, tree_join('master', path), anchor: fragment)))
      end

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

        visit_blob

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

        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(namespace_project_blame_path(project.namespace, project, tree_join('master', path), anchor: ending_fragment)))
      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

        expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(namespace_project_blame_path(project.namespace, project, tree_join('master', path), anchor: ending_fragment)))
      end
    end
  end
end