Welcome to mirror list, hosted at ThFree Co, Russian Federation.

blob_line_permalink_updater_spec.rb « blobs « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a65a82fab436f2a260e2c5c8b1fec3a6eb4453c7 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js 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 project_blob_path(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(project_blob_path(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(project_blob_path(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(project_blob_path(project, tree_join(sha, path), anchor: ending_fragment)))
      end

      it 'changes fragment hash if icon inside line number link is clicked' do
        ending_fragment = "L7"

        visit_blob

        find("##{ending_fragment}").hover
        find("##{ending_fragment} svg").click

        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)))
      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(project_blob_path(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(project_blame_path(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(project_blame_path(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(project_blame_path(project, tree_join('master', path), anchor: ending_fragment)))
      end

      it 'changes fragment hash if icon inside line number link is clicked' do
        ending_fragment = "L7"

        visit_blob

        find("##{ending_fragment}").hover
        find("##{ending_fragment} svg").click

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