2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
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)
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_blob_path(project, tree_join('master', path), anchor: fragment)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Click "Permalink" button' do
|
|
|
|
it 'works with no initial line number fragment hash' do
|
|
|
|
visit_blob
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path))))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'maintains intitial fragment hash' do
|
|
|
|
fragment = "L3"
|
|
|
|
|
|
|
|
visit_blob(fragment)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-data-file-blob-permalink-url')['href']).to eq(get_absolute_url(project_blob_path(project, tree_join(sha, path), anchor: fragment)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes fragment hash if line number clicked' do
|
|
|
|
ending_fragment = "L5"
|
|
|
|
|
|
|
|
visit_blob
|
|
|
|
|
|
|
|
find('#L3').click
|
|
|
|
find("##{ending_fragment}").click
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
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)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
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} i").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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
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)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Click "Blame" button' do
|
|
|
|
it 'works with no initial line number fragment hash' do
|
|
|
|
visit_blob
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path))))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'maintains intitial fragment hash' do
|
|
|
|
fragment = "L3"
|
|
|
|
|
|
|
|
visit_blob(fragment)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: fragment)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes fragment hash if line number clicked' do
|
|
|
|
ending_fragment = "L5"
|
|
|
|
|
|
|
|
visit_blob
|
|
|
|
|
|
|
|
find('#L3').click
|
|
|
|
find("##{ending_fragment}").click
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: ending_fragment)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
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} i").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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-blob-blame-link')['href']).to eq(get_absolute_url(project_blame_path(project, tree_join('master', path), anchor: ending_fragment)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|