2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe "User browses files" do
|
2020-07-28 23:09:34 +05:30
|
|
|
include RepoHelpers
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:fork_message) do
|
|
|
|
"You're not allowed to make changes to this project directly. "\
|
|
|
|
"A fork of this project has been created that you can make changes in, so you can submit a merge request."
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:project) { create(:project, :repository, name: "Shop") }
|
|
|
|
let(:project2) { create(:project, :repository, name: "Another Project", path: "another-project") }
|
|
|
|
let(:tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) }
|
|
|
|
let(:user) { project.owner }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it "shows last commit for current directory", :js do
|
2018-10-15 14:42:47 +05:30
|
|
|
visit(tree_path_root_ref)
|
|
|
|
|
|
|
|
click_link("files")
|
|
|
|
|
|
|
|
last_commit = project.repository.last_commit_for_path(project.default_branch, "files")
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
page.within(".commit-detail") do
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(page).to have_content(last_commit.short_id).and have_content(last_commit.author_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context "when browsing the master branch", :js do
|
2018-10-15 14:42:47 +05:30
|
|
|
before do
|
|
|
|
visit(tree_path_root_ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows files from a repository" do
|
|
|
|
expect(page).to have_content("VERSION")
|
|
|
|
.and have_content(".gitignore")
|
|
|
|
.and have_content("LICENSE")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows the `Browse Directory` link" do
|
|
|
|
click_link("files")
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('files')
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
click_link("History")
|
|
|
|
|
|
|
|
expect(page).to have_link("Browse Directory").and have_no_link("Browse Code")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows the `Browse File` link" do
|
|
|
|
page.within(".tree-table") do
|
|
|
|
click_link("README.md")
|
|
|
|
end
|
|
|
|
|
|
|
|
click_link("History")
|
|
|
|
|
|
|
|
expect(page).to have_link("Browse File").and have_no_link("Browse Files")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows the `Browse Files` link" do
|
|
|
|
click_link("History")
|
|
|
|
|
|
|
|
expect(page).to have_link("Browse Files").and have_no_link("Browse Directory")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to the permalink URL" do
|
|
|
|
click_link(".gitignore")
|
|
|
|
click_link("Permalink")
|
|
|
|
|
|
|
|
permalink_path = project_blob_path(project, "#{project.repository.commit.sha}/.gitignore")
|
|
|
|
|
|
|
|
expect(current_path).to eq(permalink_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when browsing the `markdown` branch", :js do
|
|
|
|
context "when browsing the root" do
|
|
|
|
before do
|
|
|
|
visit(project_tree_path(project, "markdown"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows correct files and links" do
|
|
|
|
expect(current_path).to eq(project_tree_path(project, "markdown"))
|
|
|
|
expect(page).to have_content("README.md")
|
2021-01-29 00:20:46 +05:30
|
|
|
.and have_content("CHANGELOG")
|
|
|
|
.and have_content("Welcome to GitLab GitLab is a free project and repository management application")
|
|
|
|
.and have_link("GitLab API doc")
|
|
|
|
.and have_link("GitLab API website")
|
|
|
|
.and have_link("Rake tasks")
|
|
|
|
.and have_link("backup and restore procedure")
|
|
|
|
.and have_link("GitLab API doc directory")
|
|
|
|
.and have_link("Maintenance")
|
|
|
|
.and have_header_with_correct_id_and_link(2, "Application details", "application-details")
|
|
|
|
.and have_link("empty", href: "")
|
|
|
|
.and have_link("#id", href: "#id")
|
|
|
|
.and have_link("/#id", href: project_blob_path(project, "markdown/README.md", anchor: "id"))
|
|
|
|
.and have_link("README.md#id", href: project_blob_path(project, "markdown/README.md", anchor: "id"))
|
|
|
|
.and have_link("d/README.md#id", href: project_blob_path(project, "markdown/db/README.md", anchor: "id"))
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "shows correct content of file" do
|
|
|
|
click_link("GitLab API doc")
|
|
|
|
|
|
|
|
expect(current_path).to eq(project_blob_path(project, "markdown/doc/api/README.md"))
|
|
|
|
expect(page).to have_content("All API requests require authentication")
|
2021-01-29 00:20:46 +05:30
|
|
|
.and have_content("Contents")
|
|
|
|
.and have_link("Users")
|
|
|
|
.and have_link("Rake tasks")
|
|
|
|
.and have_header_with_correct_id_and_link(1, "GitLab API", "gitlab-api")
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
click_link("Users")
|
|
|
|
|
|
|
|
expect(current_path).to eq(project_blob_path(project, "markdown/doc/api/users.md"))
|
|
|
|
expect(page).to have_content("Get a list of users.")
|
|
|
|
|
|
|
|
page.go_back
|
|
|
|
|
|
|
|
click_link("Rake tasks")
|
|
|
|
|
|
|
|
expect(current_path).to eq(project_tree_path(project, "markdown/doc/raketasks"))
|
|
|
|
expect(page).to have_content("backup_restore.md").and have_content("maintenance.md")
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
click_link("maintenance.md")
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
expect(current_path).to eq(project_blob_path(project, "markdown/doc/raketasks/maintenance.md"))
|
|
|
|
expect(page).to have_content("bundle exec rake gitlab:env:info RAILS_ENV=production")
|
|
|
|
|
|
|
|
click_link("shop")
|
|
|
|
|
|
|
|
page.within(".tree-table") do
|
|
|
|
click_link("README.md")
|
|
|
|
end
|
|
|
|
|
|
|
|
page.go_back
|
|
|
|
|
|
|
|
page.within(".tree-table") do
|
|
|
|
click_link("d")
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(page).to have_link("..", href: project_tree_path(project, "markdown/"))
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
page.within(".tree-table") do
|
|
|
|
click_link("README.md")
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(page).to have_link("empty", href: "")
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "shows correct content of directory" do
|
|
|
|
click_link("GitLab API doc directory")
|
|
|
|
|
|
|
|
expect(current_path).to eq(project_tree_path(project, "markdown/doc/api"))
|
|
|
|
expect(page).to have_content("README.md").and have_content("users.md")
|
|
|
|
|
|
|
|
click_link("Users")
|
|
|
|
|
|
|
|
expect(current_path).to eq(project_blob_path(project, "markdown/doc/api/users.md"))
|
|
|
|
expect(page).to have_content("List users").and have_content("Get a list of users.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when commit message has markdown', :js do
|
|
|
|
before do
|
|
|
|
project.repository.create_file(user, 'index', 'test', message: ':star: testing', branch_name: 'master')
|
|
|
|
|
|
|
|
visit(project_tree_path(project, "master"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders emojis' do
|
|
|
|
expect(page).to have_selector('gl-emoji', count: 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context "when browsing a `improve/awesome` branch", :js do
|
|
|
|
before do
|
|
|
|
visit(project_tree_path(project, "improve/awesome"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows files from a repository" do
|
|
|
|
expect(page).to have_content("VERSION")
|
|
|
|
.and have_content(".gitignore")
|
|
|
|
.and have_content("LICENSE")
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
click_link("files")
|
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('files')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_link("html")
|
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('html')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_link('500.html')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context "when browsing a `Ääh-test-utf-8` branch", :js do
|
|
|
|
before do
|
|
|
|
project.repository.create_branch('Ääh-test-utf-8', project.repository.root_ref)
|
|
|
|
visit(project_tree_path(project, "Ääh-test-utf-8"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows files from a repository" do
|
|
|
|
expect(page).to have_content("VERSION")
|
|
|
|
.and have_content(".gitignore")
|
|
|
|
.and have_content("LICENSE")
|
|
|
|
|
|
|
|
click_link("files")
|
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('files')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_link("html")
|
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('html')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_link('500.html')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context "when browsing a `test-#` branch", :js do
|
|
|
|
before do
|
|
|
|
project.repository.create_branch('test-#', project.repository.root_ref)
|
|
|
|
visit(project_tree_path(project, "test-#"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows files from a repository" do
|
|
|
|
expect(page).to have_content("VERSION")
|
|
|
|
.and have_content(".gitignore")
|
|
|
|
.and have_content("LICENSE")
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
click_link("files")
|
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('files')
|
|
|
|
end
|
|
|
|
|
|
|
|
click_link("html")
|
|
|
|
|
|
|
|
page.within('.repo-breadcrumb') do
|
|
|
|
expect(page).to have_link('html')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_link('500.html')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context "when browsing a specific ref", :js do
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:ref) { project_tree_path(project, "6d39438") }
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit(ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows files from a repository for `6d39438`" do
|
|
|
|
expect(current_path).to eq(ref)
|
|
|
|
expect(page).to have_content(".gitignore").and have_content("LICENSE")
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it "shows files from a repository with apostroph in its name" do
|
2018-10-15 14:42:47 +05:30
|
|
|
first(".js-project-refs-dropdown").click
|
|
|
|
|
|
|
|
page.within(".project-refs-form") do
|
|
|
|
click_link("'test'")
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_selector(".dropdown-toggle-text", text: "'test'")
|
|
|
|
|
|
|
|
visit(project_tree_path(project, "'test'"))
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(page).not_to have_selector(".tree-commit .animation-container")
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it "shows the code with a leading dot in the directory" do
|
2018-10-15 14:42:47 +05:30
|
|
|
first(".js-project-refs-dropdown").click
|
|
|
|
|
|
|
|
page.within(".project-refs-form") do
|
|
|
|
click_link("fix")
|
|
|
|
end
|
|
|
|
|
|
|
|
visit(project_tree_path(project, "fix/.testdir"))
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(page).not_to have_selector(".tree-commit .animation-container")
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show the permalink link" do
|
|
|
|
click_link(".gitignore")
|
|
|
|
|
|
|
|
expect(page).not_to have_link("permalink")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
context "when browsing a file content", :js do
|
2018-10-15 14:42:47 +05:30
|
|
|
before do
|
|
|
|
visit(tree_path_root_ref)
|
2018-11-20 20:47:30 +05:30
|
|
|
wait_for_requests
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
click_link(".gitignore")
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it "shows a file content" do
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(page).to have_content("*.rbc")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is possible to blame" do
|
|
|
|
click_link("Blame")
|
|
|
|
|
|
|
|
expect(page).to have_content("*.rb")
|
|
|
|
.and have_content("Dmitriy Zaporozhets")
|
|
|
|
.and have_content("Initial commit")
|
2020-03-13 15:44:24 +05:30
|
|
|
.and have_content("Ignore DS files")
|
|
|
|
|
|
|
|
previous_commit_anchor = "//a[@title='Ignore DS files']/parent::span/following-sibling::span/a"
|
|
|
|
find(:xpath, previous_commit_anchor).click
|
|
|
|
|
|
|
|
expect(page).to have_content("*.rb")
|
|
|
|
.and have_content("Dmitriy Zaporozhets")
|
|
|
|
.and have_content("Initial commit")
|
|
|
|
|
|
|
|
expect(page).not_to have_content("Ignore DS files")
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context "when browsing a file with pathspec characters" do
|
|
|
|
let(:filename) { ':wq' }
|
|
|
|
let(:newrev) { project.repository.commit('master').sha }
|
|
|
|
|
|
|
|
before do
|
2022-03-02 08:16:31 +05:30
|
|
|
stub_feature_flags(refactor_blob_viewer: false) # This stub will be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/350456
|
2020-07-28 23:09:34 +05:30
|
|
|
create_file_in_repo(project, 'master', 'master', filename, 'Test file')
|
|
|
|
path = File.join('master', filename)
|
|
|
|
|
|
|
|
visit(project_blob_path(project, path))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows a raw file content" do
|
|
|
|
click_link("Open raw")
|
|
|
|
|
|
|
|
expect(source).to eq("") # Body is filled in by gitlab-workhorse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
context "when browsing a raw file" do
|
|
|
|
before do
|
2022-03-02 08:16:31 +05:30
|
|
|
stub_feature_flags(refactor_blob_viewer: false) # This stub will be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/350456
|
2018-10-15 14:42:47 +05:30
|
|
|
path = File.join(RepoHelpers.sample_commit.id, RepoHelpers.sample_blob.path)
|
|
|
|
|
|
|
|
visit(project_blob_path(project, path))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows a raw file content" do
|
|
|
|
click_link("Open raw")
|
|
|
|
|
|
|
|
expect(source).to eq("") # Body is filled in by gitlab-workhorse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|