summaryrefslogtreecommitdiff
path: root/spec/features/projects/files/user_browses_files_spec.rb
blob: 0f3ce5a2bad744d860bb2c3e85c21b6e6f686843 (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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# frozen_string_literal: true

require "spec_helper"

RSpec.describe "User browses files", :js do
  include RepoHelpers

  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

  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.first_owner }

  before do
    sign_in(user)
  end

  it "shows last commit for current directory", :js do
    visit(tree_path_root_ref)

    click_link("files")

    last_commit = project.repository.last_commit_for_path(project.default_branch, "files")

    page.within(".commit-detail") do
      expect(page).to have_content(last_commit.short_id).and have_content(last_commit.author_name)
    end
  end

  context "when browsing the master branch", :js do
    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")

      page.within('.repo-breadcrumb') do
        expect(page).to have_link('files')
      end

      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(page).to have_current_path(permalink_path, ignore_query: true)
    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(page).to have_current_path(project_tree_path(project, "markdown"), ignore_query: true)
        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")
          .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"))
      end

      it "shows correct content of file" do
        click_link("GitLab API doc")

        expect(page).to have_current_path(project_blob_path(project, "markdown/doc/api/README.md"), ignore_query: true)
        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(page).to have_current_path(project_blob_path(project, "markdown/doc/api/users.md"), ignore_query: true)
        expect(page).to have_content("Get a list of users.")

        page.go_back

        click_link("Rake tasks")

        expect(page).to have_current_path(project_tree_path(project, "markdown/doc/raketasks"), ignore_query: true)
        expect(page).to have_content("backup_restore.md").and have_content("maintenance.md")

        click_link("maintenance.md")

        expect(page).to have_current_path(project_blob_path(project, "markdown/doc/raketasks/maintenance.md"), ignore_query: true)
        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

        expect(page).to have_link("..", href: project_tree_path(project, "markdown/"))

        page.within(".tree-table") do
          click_link("README.md")
        end

        expect(page).to have_link("empty", href: "")
      end

      it "shows correct content of directory" do
        click_link("GitLab API doc directory")

        expect(page).to have_current_path(project_tree_path(project, "markdown/doc/api"), ignore_query: true)
        expect(page).to have_content("README.md").and have_content("users.md")

        click_link("Users")

        expect(page).to have_current_path(project_blob_path(project, "markdown/doc/api/users.md"), ignore_query: true)
        expect(page).to have_content("List users").and have_content("Get a list of users.")
      end
    end
  end

  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

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

      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

  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

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

      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

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

    before do
      visit(ref)
    end

    it "shows files from a repository for `6d39438`" do
      expect(page).to have_current_path(ref, ignore_query: true)
      expect(page).to have_content(".gitignore").and have_content("LICENSE")
    end

    it "shows files from a repository with apostroph in its name" do
      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'"))

      expect(page).not_to have_selector(".tree-commit .animation-container")
    end

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

      page.within(".project-refs-form") do
        click_link("fix")
      end

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

      expect(page).not_to have_selector(".tree-commit .animation-container")
    end

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

      expect(page).not_to have_link("permalink")
    end
  end

  context "when browsing a file content", :js do
    before do
      visit(tree_path_root_ref)
      wait_for_requests

      click_link(".gitignore")
    end

    it "shows a file content" do
      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")
                 .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")
    end
  end

  context "when browsing a file with pathspec characters" do
    let(:filename) { ':wq' }
    let(:newrev) { project.repository.commit('master').sha }

    before do
      create_file_in_repo(project, 'master', 'master', filename, 'Test file')
      path = File.join('master', filename)

      visit(project_blob_path(project, path))
      wait_for_requests
    end

    it "shows raw file content in a new tab" do
      new_tab = window_opened_by { click_link 'Open raw' }

      within_window new_tab do
        expect(page).to have_content("Test file")
      end
    end
  end

  context "when browsing a raw file" do
    before do
      visit(tree_path_root_ref)
      wait_for_requests

      click_link(".gitignore")
      wait_for_requests
    end

    it "shows raw file content in a new tab" do
      new_tab = window_opened_by { click_link 'Open raw' }

      within_window new_tab do
        expect(page).to have_content("*.rbc")
      end
    end
  end
end