user_browses_files_spec.rb 8.2 KB
Newer Older
1
require "spec_helper"
2

3
describe "User browses files" do
4 5 6 7
  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
8 9
  let(:project) { create(:project, :repository, name: "Shop") }
  let(:project2) { create(:project, :repository, name: "Another Project", path: "another-project") }
10
  let(:tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) }
R
Rémy Coutable 已提交
11
  let(:user) { project.owner }
12 13

  before do
C
Clement Ho 已提交
14
    stub_feature_flags(csslab: false)
15 16 17
    sign_in(user)
  end

18
  it "shows last commit for current directory" do
19 20
    visit(tree_path_root_ref)

21
    click_link("files")
22

23 24 25 26
    last_commit = project.repository.last_commit_for_path(project.default_branch, "files")

    page.within(".blob-commit-info") do
      expect(page).to have_content(last_commit.short_id).and have_content(last_commit.author_name)
27 28 29
    end
  end

30
  context "when browsing the master branch" do
31 32 33 34
    before do
      visit(tree_path_root_ref)
    end

35 36 37 38
    it "shows files from a repository" do
      expect(page).to have_content("VERSION")
                 .and have_content(".gitignore")
                 .and have_content("LICENSE")
39 40
    end

41 42 43
    it "shows the `Browse Directory` link" do
      click_link("files")
      click_link("History")
44

45
      expect(page).to have_link("Browse Directory").and have_no_link("Browse Code")
46 47
    end

48 49 50
    it "shows the `Browse File` link" do
      page.within(".tree-table") do
        click_link("README.md")
51 52
      end

53 54 55
      click_link("History")

      expect(page).to have_link("Browse File").and have_no_link("Browse Files")
56 57
    end

58 59
    it "shows the `Browse Files` link" do
      click_link("History")
60

61
      expect(page).to have_link("Browse Files").and have_no_link("Browse Directory")
62 63
    end

64 65 66
    it "redirects to the permalink URL" do
      click_link(".gitignore")
      click_link("Permalink")
67 68 69 70 71 72 73

      permalink_path = project_blob_path(project, "#{project.repository.commit.sha}/.gitignore")

      expect(current_path).to eq(permalink_path)
    end
  end

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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  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
        # rubocop:disable Lint/Void
        # Test the full URLs of links instead of relative paths by `have_link(text: "...", href: "...")`.
        find("a", text: /^empty$/)["href"]            == project_tree_url(project, "markdown")
        find("a", text: /^#id$/)["href"]              == project_tree_url(project, "markdown", anchor: "#id")
        find("a", text: %r{^/#id$})["href"]           == project_tree_url(project, "markdown", anchor: "#id")
        find("a", text: /^README.md#id$/)["href"]     == project_blob_url(project, "markdown/README.md", anchor: "#id")
        find("a", text: %r{^d/README.md#id$})["href"] == project_blob_url(project, "d/markdown/README.md", anchor: "#id")
        # rubocop:enable Lint/Void

        expect(current_path).to eq(project_tree_path(project, "markdown"))
        expect(page).to have_content("README.md")
                   .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")
      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")
                   .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")

        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")

        click_link("shop")
        click_link("Maintenance")

        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

        # rubocop:disable Lint/Void
        # Test the full URLs of links instead of relative paths by `have_link(text: "...", href: "...")`.
        find("a", text: /^empty$/)["href"] == project_tree_url(project, "markdown/d")
        # rubocop:enable Lint/Void

        page.within(".tree-table") do
          click_link("README.md")
        end
        # Test the full URLs of links instead of relative paths by `have_link(text: "...", href: "...")`.
        find("a", text: /^empty$/)["href"] == project_blob_url(project, "markdown/d/README.md")
      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

  context "when browsing a specific ref" do
    let(:ref) { project_tree_path(project, "6d39438") }

172
    before do
173
      visit(ref)
174 175
    end

176 177 178
    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")
179 180
    end

181 182
    it "shows files from a repository with apostroph in its name", :js do
      first(".js-project-refs-dropdown").click
183

184
      page.within(".project-refs-form") do
185 186 187
        click_link("'test'")
      end

188
      expect(page).to have_selector(".dropdown-toggle-text", text: "'test'")
189 190 191

      visit(project_tree_path(project, "'test'"))

192
      expect(page).to have_css(".tree-commit-link").and have_no_content("Loading commit data...")
193 194
    end

195 196
    it "shows the code with a leading dot in the directory", :js do
      first(".js-project-refs-dropdown").click
197

198 199
      page.within(".project-refs-form") do
        click_link("fix")
200 201
      end

202
      visit(project_tree_path(project, "fix/.testdir"))
203

204
      expect(page).to have_css(".tree-commit-link").and have_no_content("Loading commit data...")
205 206
    end

207 208
    it "does not show the permalink link" do
      click_link(".gitignore")
209

210
      expect(page).not_to have_link("permalink")
211 212 213
    end
  end

214
  context "when browsing a file content", :js do
215 216
    before do
      visit(tree_path_root_ref)
217
      wait_for_requests
218 219

      click_link(".gitignore")
220 221
    end

222 223
    it "shows a file content", :js do
      expect(page).to have_content("*.rbc")
224
    end
225

226 227
    it "is possible to blame" do
      click_link("Blame")
228

229 230 231
      expect(page).to have_content("*.rb")
                 .and have_content("Dmitriy Zaporozhets")
                 .and have_content("Initial commit")
232
    end
233 234
  end

235
  context "when browsing a raw file" do
236
    before do
237 238 239
      path = File.join(RepoHelpers.sample_commit.id, RepoHelpers.sample_blob.path)

      visit(project_blob_path(project, path))
240 241
    end

242 243 244 245
    it "shows a raw file content" do
      click_link("Open raw")

      expect(source).to eq("") # Body is filled in by gitlab-workhorse
246 247 248
    end
  end
end