BigW Consortium Gitlab

browse_files.rb 12.9 KB
Newer Older
1
# coding: utf-8
2
class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
Nihad Abbasov committed
3 4 5
  include SharedAuthentication
  include SharedProject
  include SharedPaths
6
  include RepoHelpers
Douwe Maan committed
7
  include WaitForAjax
Nihad Abbasov committed
8

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

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

21
  step 'I should see files from repository for "6d39438"' do
22 23 24
    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"
25 26
  end

27
  step 'I see the ".gitignore"' do
28
    expect(page).to have_content '.gitignore'
29 30 31
  end

  step 'I don\'t see the ".gitignore"' do
32
    expect(page).not_to have_content '.gitignore'
33 34
  end

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

Ciro Santilli committed
39
  step 'I should see its content' do
Douwe Maan committed
40
    wait_for_ajax
41
    expect(page).to have_content old_gitignore_content
42 43 44
  end

  step 'I should see its new content' do
Douwe Maan committed
45
    wait_for_ajax
46
    expect(page).to have_content new_gitignore_content
47 48
  end

49
  step 'I should see its content with new lines preserved at end of file' do
50
    expect(evaluate_script('ace.edit("editor").getValue()')).to eq "Sample\n\n\n"
51 52
  end

53
  step 'I click link "Raw"' do
Douwe Maan committed
54
    click_link 'Open raw'
55 56
  end

57
  step 'I should see raw file content' do
58
    expect(source).to eq '' # Body is filled in by gitlab-workhorse
59
  end
Valeriy Sizov committed
60

61
  step 'I click button "Edit"' do
62
    find('.js-edit-blob').click
Valeriy Sizov committed
63 64
  end

65
  step 'I cannot see the edit button' do
66
    expect(page).not_to have_link 'edit'
67 68
  end

69 70 71 72
  step 'I click button "Fork"' do
    click_link 'Fork'
  end

73
  step 'I can edit code' do
74
    set_new_content
75
    expect(evaluate_script('ace.edit("editor").getValue()')).to eq new_gitignore_content
Valeriy Sizov committed
76 77
  end

skv-headless committed
78
  step 'I edit code' do
Phil Hughes committed
79
    expect(page).to have_selector('.file-editor')
80 81 82
    set_new_content
  end

83
  step 'I edit code with new lines at end of file' do
84
    execute_script('ace.edit("editor").setValue("Sample\n\n\n")')
85 86
  end

87 88 89 90
  step 'I fill the new file name' do
    fill_in :file_name, with: new_file_name
  end

91
  step 'I fill the new branch name' do
92
    first('button.js-target-branch', visible: true).click
93 94 95
    find('.create-new-branch', visible: true).click
    find('#new_branch_name', visible: true).set('new_branch_name')
    find('.js-new-branch-btn', visible: true).click
96 97
  end

98
  step 'I fill the new file name with an illegal name' do
Douwe Maan committed
99
    fill_in :file_name, with: 'Spaces Not Allowed'
100 101
  end

102 103 104 105
  step 'I fill the new file name with a new directory' do
    fill_in :file_name, with: new_file_name_with_directory
  end

106
  step 'I fill the commit message' do
107
    fill_in :commit_message, with: 'New commit message', visible: true
skv-headless committed
108 109 110
  end

  step 'I click link "Diff"' do
111
    click_link 'Preview changes'
skv-headless committed
112 113
  end

114 115
  step 'I click on "Commit changes"' do
    click_button 'Commit changes'
116 117
  end

118 119 120 121
  step 'I click on "Changes" tab' do
    click_link 'Changes'
  end

Stan Hu committed
122 123 124 125
  step 'I click on "Create directory"' do
    click_button 'Create directory'
  end

Douwe Maan committed
126
  step 'I click on "Delete"' do
127
    click_on 'Delete'
128 129
  end

Douwe Maan committed
130 131
  step 'I click on "Delete file"' do
    click_button 'Delete file'
132 133
  end

134
  step 'I click on "Replace"' do
135
    click_on  "Replace"
136 137 138 139 140 141
  end

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

skv-headless committed
142
  step 'I see diff' do
143
    expect(page).to have_css '.line_holder.new'
skv-headless committed
144 145
  end

Stan Hu committed
146 147
  step 'I click on "New file" link in repo' do
    find('.add-to-tree').click
Douwe Maan committed
148
    click_link 'New file'
Phil Hughes committed
149
    expect(page).to have_selector('.file-editor')
150 151
  end

Stan Hu committed
152 153 154 155 156 157 158 159 160 161 162 163
  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
164
  end
165

Stan Hu committed
166 167
  step 'I fill an existing directory name' do
    fill_in :dir_name, with: 'files'
168 169
  end

Stan Hu committed
170
  step 'I can see new file page' do
171
    expect(page).to have_content "New File"
Stan Hu committed
172
    expect(page).to have_content "Commit message"
173 174 175 176 177 178 179
  end

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

  step 'I can see the new commit message' do
180
    expect(page).to have_content "New commit message"
181 182 183 184 185 186 187 188
  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
189
      fill_in :commit_message, with: 'New commit message'
190 191 192 193 194 195 196 197
    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
198
    page.within('#modal-upload-blob') do
199 200 201 202 203 204 205 206 207 208 209 210 211
      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

212 213
  step 'I click on files directory' do
    click_link 'files'
214 215
  end

216 217
  step 'I click on History link' do
    click_link 'History'
218 219 220
  end

  step 'I see Browse dir link' do
Phil Hughes committed
221 222
    expect(page).to have_link 'Browse Directory'
    expect(page).not_to have_link 'Browse Code'
223 224 225
  end

  step 'I click on readme file' do
226
    page.within '.tree-table' do
227 228
      click_link 'README.md'
    end
229 230 231
  end

  step 'I see Browse file link' do
Phil Hughes committed
232 233
    expect(page).to have_link 'Browse File'
    expect(page).not_to have_link 'Browse Files'
234 235 236
  end

  step 'I see Browse code link' do
237
    expect(page).to have_link 'Browse Files'
Phil Hughes committed
238
    expect(page).not_to have_link 'Browse Directory'
239
  end
240

241 242
  step 'I click on Permalink' do
    click_link 'Permalink'
243 244
  end

245
  step 'I am redirected to the files URL' do
246
    expect(current_path).to eq namespace_project_tree_path(@project.namespace, @project, 'master')
247 248 249
  end

  step 'I am redirected to the ".gitignore"' do
Vinnie Okada committed
250
    expect(current_path).to eq(namespace_project_blob_path(@project.namespace, @project, 'master/.gitignore'))
251 252
  end

253
  step 'I am redirected to the permalink URL' do
Vinnie Okada committed
254 255 256 257 258
    expect(current_path).to(
      eq(namespace_project_blob_path(@project.namespace, @project,
                                     @project.repository.commit.sha +
                                     '/.gitignore'))
    )
259 260
  end

261
  step 'I am redirected to the new file' do
262 263
    expect(current_path).to eq(
      namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name))
264 265
  end

266
  step 'I am redirected to the new file with directory' do
267 268
    expect(current_path).to eq(
      namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name_with_directory))
269 270
  end

Douwe Maan committed
271 272
  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))
Stan Hu committed
273 274
  end

275 276 277 278 279
  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

Stan Hu committed
280
  step 'I am redirected to the root directory' do
281
    expect(current_path).to eq(
282
      namespace_project_tree_path(@project.namespace, @project, 'master'))
Stan Hu committed
283 284
  end

285 286 287
  step "I don't see the permalink link" do
    expect(page).not_to have_link('permalink')
  end
288

Stan Hu committed
289
  step 'I see "Unable to create directory"' do
290 291 292 293 294
    expect(page).to have_content('A directory with this name already exists')
  end

  step 'I see "Path can contain only..."' do
    expect(page).to have_content('Path can contain only')
Stan Hu committed
295 296
  end

297 298 299 300
  step 'I see a commit error message' do
    expect(page).to have_content('Your changes could not be committed')
  end

301 302 303 304
  step 'I create bare repo' do
    click_link 'Create empty bare repository'
  end

Rémy Coutable committed
305 306
  step 'I click on "README" link' do
    click_link 'README'
307 308

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

312
  step "I switch ref to 'test'" do
313 314 315
    first('.js-project-refs-dropdown').click

    page.within '.project-refs-form' do
316
      click_link "'test'"
317
    end
318 319
  end

320
  step "I switch ref to fix" do
321 322 323 324 325
    first('.js-project-refs-dropdown').click

    page.within '.project-refs-form' do
      click_link 'fix'
    end
326 327
  end

328
  step "I see the ref 'test' has been selected" do
329
    expect(page).to have_selector '.dropdown-toggle-text', text: "'test'"
330 331 332 333 334 335
  end

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

336 337 338 339
  step "I visit the fix tree" do
    visit namespace_project_tree_path(@project.namespace, @project, "fix/.testdir")
  end

340 341 342 343 344
  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

345 346 347 348 349
  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

350
  step 'I click on "files/lfs/lfs_object.iso" file in repo' do
351
    allow_any_instance_of(Project).to receive(:lfs_enabled?).and_return(true)
352
    visit namespace_project_tree_path(@project.namespace, @project, "lfs")
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
    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
369
    page.within '.content' do
370
      expect(page).to have_link 'Download'
371 372 373 374 375 376 377
      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
378 379
  end

380 381 382 383 384
  step 'I should see a Fork/Cancel combo' do
    expect(page).to have_link 'Fork'
    expect(page).to have_button 'Cancel'
  end

385 386 387 388
  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

Stan Hu committed
389 390 391 392 393 394 395 396 397 398
  # 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
399
    expect(page).to have_css('.file-content img')
Stan Hu committed
400 401
  end

402 403 404
  private

  def set_new_content
405
    execute_script("ace.edit('editor').setValue('#{new_gitignore_content}')")
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
  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
424

425 426 427 428 429 430
  # 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

Stan Hu committed
431 432 433 434 435 436
  # 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

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
  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
Stan Hu committed
461 462 463 464

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