browse_files.rb 12.2 KB
Newer Older
L
liyakun 已提交
1
# coding: utf-8
C
Ciro Santilli 已提交
2
class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
N
Nihad Abbasov 已提交
3 4 5
  include SharedAuthentication
  include SharedProject
  include SharedPaths
6
  include RepoHelpers
N
Nihad Abbasov 已提交
7

D
Douwe Maan 已提交
8 9 10 11 12 13
  step "I don't have write access" do
    @project = create(:project, name: "Other Project", path: "other-project")
    @project.team << [@user, :reporter]
    visit namespace_project_tree_path(@project.namespace, @project, root_ref)
  end

14
  step 'I should see files from repository' do
15 16 17
    expect(page).to have_content "VERSION"
    expect(page).to have_content ".gitignore"
    expect(page).to have_content "LICENSE"
18 19
  end

20
  step 'I should see files from repository for "6d39438"' do
21 22 23
    expect(current_path).to eq namespace_project_tree_path(@project.namespace, @project, "6d39438")
    expect(page).to have_content ".gitignore"
    expect(page).to have_content "LICENSE"
24 25
  end

C
Ciro Santilli 已提交
26
  step 'I see the ".gitignore"' do
27
    expect(page).to have_content '.gitignore'
C
Ciro Santilli 已提交
28 29 30
  end

  step 'I don\'t see the ".gitignore"' do
31
    expect(page).not_to have_content '.gitignore'
C
Ciro Santilli 已提交
32 33
  end

34 35
  step 'I click on ".gitignore" file in repo' do
    click_link ".gitignore"
36 37
  end

C
Ciro Santilli 已提交
38
  step 'I should see its content' do
39
    expect(page).to have_content old_gitignore_content
C
Ciro Santilli 已提交
40 41 42
  end

  step 'I should see its new content' do
43
    expect(page).to have_content new_gitignore_content
44 45
  end

46
  step 'I should see its content with new lines preserved at end of file' do
C
Connor Shea 已提交
47
    expect(evaluate_script('ace.edit("editor").getValue()')).to eq "Sample\n\n\n"
48 49
  end

C
Ciro Santilli 已提交
50 51
  step 'I click link "Raw"' do
    click_link 'Raw'
52 53
  end

54
  step 'I should see raw file content' do
55
    expect(source).to eq '' # Body is filled in by gitlab-workhorse
56
  end
V
Valeriy Sizov 已提交
57

C
Ciro Santilli 已提交
58 59
  step 'I click button "Edit"' do
    click_link 'Edit'
V
Valeriy Sizov 已提交
60 61
  end

62
  step 'I cannot see the edit button' do
63
    expect(page).not_to have_link 'edit'
64 65
  end

66
  step 'I can edit code' do
C
Ciro Santilli 已提交
67
    set_new_content
C
Connor Shea 已提交
68
    expect(evaluate_script('ace.edit("editor").getValue()')).to eq new_gitignore_content
V
Valeriy Sizov 已提交
69 70
  end

S
skv-headless 已提交
71
  step 'I edit code' do
P
Phil Hughes 已提交
72
    expect(page).to have_selector('.file-editor')
C
Ciro Santilli 已提交
73 74 75
    set_new_content
  end

76
  step 'I edit code with new lines at end of file' do
C
Connor Shea 已提交
77
    execute_script('ace.edit("editor").setValue("Sample\n\n\n")')
78 79
  end

C
Ciro Santilli 已提交
80 81 82 83
  step 'I fill the new file name' do
    fill_in :file_name, with: new_file_name
  end

84
  step 'I fill the new branch name' do
85
    fill_in :target_branch, with: 'new_branch_name', visible: true
86 87
  end

88
  step 'I fill the new file name with an illegal name' do
D
Douwe Maan 已提交
89
    fill_in :file_name, with: 'Spaces Not Allowed'
90 91
  end

92 93 94 95
  step 'I fill the new file name with a new directory' do
    fill_in :file_name, with: new_file_name_with_directory
  end

C
Ciro Santilli 已提交
96
  step 'I fill the commit message' do
D
Douwe Maan 已提交
97
    fill_in :commit_message, with: 'New commit message', visible: true
S
skv-headless 已提交
98 99 100
  end

  step 'I click link "Diff"' do
D
Douwe Maan 已提交
101
    click_link 'Preview Changes'
S
skv-headless 已提交
102 103
  end

104 105
  step 'I click on "Commit Changes"' do
    click_button 'Commit Changes'
C
Ciro Santilli 已提交
106 107
  end

S
Stan Hu 已提交
108 109 110 111
  step 'I click on "Create directory"' do
    click_button 'Create directory'
  end

D
Douwe Maan 已提交
112
  step 'I click on "Delete"' do
D
Douwe Maan 已提交
113
    click_on 'Delete'
C
Ciro Santilli 已提交
114 115
  end

D
Douwe Maan 已提交
116 117
  step 'I click on "Delete file"' do
    click_button 'Delete file'
C
Ciro Santilli 已提交
118 119
  end

L
liyakun 已提交
120
  step 'I click on "Replace"' do
D
Douwe Maan 已提交
121
    click_on  "Replace"
L
liyakun 已提交
122 123 124 125 126 127
  end

  step 'I click on "Replace file"' do
    click_button  'Replace file'
  end

S
skv-headless 已提交
128
  step 'I see diff' do
129
    expect(page).to have_css '.line_holder.new'
S
skv-headless 已提交
130 131
  end

S
Stan Hu 已提交
132 133
  step 'I click on "New file" link in repo' do
    find('.add-to-tree').click
D
Douwe Maan 已提交
134
    click_link 'New file'
P
Phil Hughes 已提交
135
    expect(page).to have_selector('.file-editor')
136 137
  end

S
Stan Hu 已提交
138 139 140 141 142 143 144 145 146 147 148 149
  step 'I click on "Upload file" link in repo' do
    find('.add-to-tree').click
    click_link 'Upload file'
  end

  step 'I click on "New directory" link in repo' do
    find('.add-to-tree').click
    click_link 'New directory'
  end

  step 'I fill the new directory name' do
    fill_in :dir_name, with: new_dir_name
150
  end
151

S
Stan Hu 已提交
152 153
  step 'I fill an existing directory name' do
    fill_in :dir_name, with: 'files'
L
liyakun 已提交
154 155
  end

S
Stan Hu 已提交
156
  step 'I can see new file page' do
D
Douwe Maan 已提交
157
    expect(page).to have_content "New File"
S
Stan Hu 已提交
158
    expect(page).to have_content "Commit message"
L
liyakun 已提交
159 160 161 162 163 164 165
  end

  step 'I click on "Upload file"' do
    click_button 'Upload file'
  end

  step 'I can see the new commit message' do
D
Douwe Maan 已提交
166
    expect(page).to have_content "New commit message"
L
liyakun 已提交
167 168 169 170 171 172 173 174
  end

  step 'I upload a new text file' do
    drop_in_dropzone test_text_file
  end

  step 'I fill the upload file commit message' do
    page.within('#modal-upload-blob') do
D
Douwe Maan 已提交
175
      fill_in :commit_message, with: 'New commit message'
L
liyakun 已提交
176 177 178 179 180 181 182 183
    end
  end

  step 'I replace it with a text file' do
    drop_in_dropzone test_text_file
  end

  step 'I fill the replace file commit message' do
184
    page.within('#modal-upload-blob') do
L
liyakun 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197
      fill_in :commit_message, with: 'Replacement file commit message'
    end
  end

  step 'I can see the replacement commit message' do
    expect(page).to have_content "Replacement file commit message"
  end

  step 'I can see the new text file' do
    expect(page).to have_content "Lorem ipsum dolor sit amet"
    expect(page).to have_content "Sed ut perspiciatis unde omnis"
  end

198 199
  step 'I click on files directory' do
    click_link 'files'
200 201
  end

C
Ciro Santilli 已提交
202 203
  step 'I click on History link' do
    click_link 'History'
204 205 206
  end

  step 'I see Browse dir link' do
P
Phil Hughes 已提交
207 208
    expect(page).to have_link 'Browse Directory'
    expect(page).not_to have_link 'Browse Code'
209 210 211
  end

  step 'I click on readme file' do
212
    page.within '.tree-table' do
D
Dmitriy Zaporozhets 已提交
213 214
      click_link 'README.md'
    end
215 216 217
  end

  step 'I see Browse file link' do
P
Phil Hughes 已提交
218 219
    expect(page).to have_link 'Browse File'
    expect(page).not_to have_link 'Browse Files'
220 221 222
  end

  step 'I see Browse code link' do
P
Phil Hughes 已提交
223
    expect(page).to have_link 'Browse Files'
P
Phil Hughes 已提交
224
    expect(page).not_to have_link 'Browse Directory'
225
  end
226

C
Ciro Santilli 已提交
227 228
  step 'I click on Permalink' do
    click_link 'Permalink'
229 230
  end

C
Ciro Santilli 已提交
231
  step 'I am redirected to the files URL' do
232
    expect(current_path).to eq namespace_project_tree_path(@project.namespace, @project, 'master')
C
Ciro Santilli 已提交
233 234 235
  end

  step 'I am redirected to the ".gitignore"' do
V
Vinnie Okada 已提交
236
    expect(current_path).to eq(namespace_project_blob_path(@project.namespace, @project, 'master/.gitignore'))
C
Ciro Santilli 已提交
237 238
  end

239
  step 'I am redirected to the permalink URL' do
V
Vinnie Okada 已提交
240 241 242 243 244
    expect(current_path).to(
      eq(namespace_project_blob_path(@project.namespace, @project,
                                     @project.repository.commit.sha +
                                     '/.gitignore'))
    )
245 246
  end

C
Ciro Santilli 已提交
247
  step 'I am redirected to the new file' do
G
Gabriel Mazetto 已提交
248 249
    expect(current_path).to eq(
      namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name))
C
Ciro Santilli 已提交
250 251
  end

252
  step 'I am redirected to the new file with directory' do
G
Gabriel Mazetto 已提交
253 254
    expect(current_path).to eq(
      namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name_with_directory))
255 256
  end

D
Douwe Maan 已提交
257 258
  step 'I am redirected to the new merge request page' do
    expect(current_path).to eq(new_namespace_project_merge_request_path(@project.namespace, @project))
S
Stan Hu 已提交
259 260
  end

D
Douwe Maan 已提交
261 262 263 264 265
  step "I am redirected to the fork's new merge request page" do
    fork = @user.fork_of(@project)
    expect(current_path).to eq(new_namespace_project_merge_request_path(fork.namespace, fork))
  end

S
Stan Hu 已提交
266
  step 'I am redirected to the root directory' do
G
Gabriel Mazetto 已提交
267
    expect(current_path).to eq(
D
Douwe Maan 已提交
268
      namespace_project_tree_path(@project.namespace, @project, 'master'))
S
Stan Hu 已提交
269 270
  end

271 272 273
  step "I don't see the permalink link" do
    expect(page).not_to have_link('permalink')
  end
C
Ciro Santilli 已提交
274

S
Stan Hu 已提交
275 276 277 278
  step 'I see "Unable to create directory"' do
    expect(page).to have_content('Directory already exists')
  end

279 280 281 282
  step 'I see a commit error message' do
    expect(page).to have_content('Your changes could not be committed')
  end

283 284 285 286
  step 'I create bare repo' do
    click_link 'Create empty bare repository'
  end

R
Rémy Coutable 已提交
287 288
  step 'I click on "README" link' do
    click_link 'README'
289 290

    # Remove pre-receive hook so we can push without auth
291
    FileUtils.rm_f(File.join(@project.repository.path, 'hooks', 'pre-receive'))
292 293
  end

294
  step "I switch ref to 'test'" do
P
Phil Hughes 已提交
295 296 297
    first('.js-project-refs-dropdown').click

    page.within '.project-refs-form' do
298
      click_link "'test'"
P
Phil Hughes 已提交
299
    end
300 301
  end

302
  step "I switch ref to fix" do
P
Phil Hughes 已提交
303 304 305 306 307
    first('.js-project-refs-dropdown').click

    page.within '.project-refs-form' do
      click_link 'fix'
    end
308 309
  end

310
  step "I see the ref 'test' has been selected" do
311
    expect(page).to have_selector '.dropdown-toggle-text', text: "'test'"
312 313 314 315 316 317
  end

  step "I visit the 'test' tree" do
    visit namespace_project_tree_path(@project.namespace, @project, "'test'")
  end

318 319 320 321
  step "I visit the fix tree" do
    visit namespace_project_tree_path(@project.namespace, @project, "fix/.testdir")
  end

322 323 324 325 326
  step 'I see the commit data' do
    expect(page).to have_css('.tree-commit-link', visible: true)
    expect(page).not_to have_content('Loading commit data...')
  end

327 328 329 330 331
  step 'I see the commit data for a directory with a leading dot' do
    expect(page).to have_css('.tree-commit-link', visible: true)
    expect(page).not_to have_content('Loading commit data...')
  end

332
  step 'I click on "files/lfs/lfs_object.iso" file in repo' do
333
    visit namespace_project_tree_path(@project.namespace, @project, "lfs")
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    click_link 'files'
    click_link "lfs"
    click_link "lfs_object.iso"
  end

  step 'I should see download link and object size' do
    expect(page).to have_content 'Download (1.5 MB)'
  end

  step 'I should not see lfs pointer details' do
    expect(page).not_to have_content 'version https://git-lfs.github.com/spec/v1'
    expect(page).not_to have_content 'oid sha256:91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
    expect(page).not_to have_content 'size 1575078'
  end

  step 'I should see buttons for allowed commands' do
D
Dmitriy Zaporozhets 已提交
350 351 352 353 354 355 356 357 358
    page.within '.content' do
      expect(page).to have_content 'Raw'
      expect(page).to have_content 'History'
      expect(page).to have_content 'Permalink'
      expect(page).not_to have_content 'Edit'
      expect(page).not_to have_content 'Blame'
      expect(page).to have_content 'Delete'
      expect(page).to have_content 'Replace'
    end
359 360
  end

D
Douwe Maan 已提交
361 362 363 364
  step 'I should see a notice about a new fork having been created' do
    expect(page).to have_content "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

S
Stan Hu 已提交
365 366 367 368 369 370 371 372 373 374
  # SVG files
  step 'I upload a new SVG file' do
    drop_in_dropzone test_svg_file
  end

  step 'I visit the SVG file' do
    visit namespace_project_blob_path(@project.namespace, @project, 'new_branch_name/logo_sample.svg')
  end

  step 'I can see the new rendered SVG image' do
375
    expect(page).to have_css('.file-content img')
S
Stan Hu 已提交
376 377
  end

C
Ciro Santilli 已提交
378 379 380
  private

  def set_new_content
C
Connor Shea 已提交
381
    execute_script("ace.edit('editor').setValue('#{new_gitignore_content}')")
C
Ciro Santilli 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  end

  # Content of the gitignore file on the seed repository.
  def old_gitignore_content
    '*.rbc'
  end

  # Constant value that differs from the content
  # of the gitignore of the seed repository.
  def new_gitignore_content
    old_gitignore_content + 'a'
  end

  # Constant value that is a valid filename and
  # not a filename present at root of the seed repository.
  def new_file_name
    'not_a_file.md'
  end
L
liyakun 已提交
400

401 402 403 404 405 406
  # Constant value that is a valid filename with directory and
  # not a filename present at root of the seed repository.
  def new_file_name_with_directory
    'foo/bar/baz.txt'
  end

S
Stan Hu 已提交
407 408 409 410 411 412
  # Constant value that is a valid directory and
  # not a directory present at root of the seed repository.
  def new_dir_name
    'new_dir/subdir'
  end

L
liyakun 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
  def drop_in_dropzone(file_path)
    # Generate a fake input selector
    page.execute_script <<-JS
      var fakeFileInput = window.$('<input/>').attr(
        {id: 'fakeFileInput', type: 'file'}
      ).appendTo('body');
    JS
    # Attach the file to the fake input selector with Capybara
    attach_file("fakeFileInput", file_path)
    # Add the file to a fileList array and trigger the fake drop event
    page.execute_script <<-JS
      var fileList = [$('#fakeFileInput')[0].files[0]];
      var e = jQuery.Event('drop', { dataTransfer : { files : fileList } });
      $('.dropzone')[0].dropzone.listeners[0].events.drop(e);
    JS
  end

  def test_text_file
    File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt')
  end

  def test_image_file
    File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')
  end
S
Stan Hu 已提交
437 438 439 440

  def test_svg_file
    File.join(Rails.root, 'spec', 'fixtures', 'logo_sample.svg')
  end
441
end