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

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

Ciro Santilli's avatar
Ciro Santilli committed
26
  step 'I see the ".gitignore"' do
27
    expect(page).to have_content '.gitignore'
Ciro Santilli's avatar
Ciro Santilli committed
28 29 30
  end

  step 'I don\'t see the ".gitignore"' do
31
    expect(page).not_to have_content '.gitignore'
Ciro Santilli's avatar
Ciro Santilli committed
32 33
  end

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

Ciro Santilli's avatar
Ciro Santilli committed
38
  step 'I should see its content' do
39
    expect(page).to have_content old_gitignore_content
Ciro Santilli's avatar
Ciro Santilli committed
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 47 48 49
  step 'I should see its content with new lines preserved at end of file' do
    expect(evaluate_script('blob.editor.getValue()')).to eq "Sample\n\n\n"
  end

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
Valeriy Sizov's avatar
Valeriy Sizov committed
57

58 59
  step 'I click button "Edit"' do
    click_link 'Edit'
Valeriy Sizov's avatar
Valeriy Sizov committed
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
Ciro Santilli's avatar
Ciro Santilli committed
67
    set_new_content
68
    expect(evaluate_script('blob.editor.getValue()')).to eq new_gitignore_content
Valeriy Sizov's avatar
Valeriy Sizov committed
69 70
  end

skv-headless's avatar
skv-headless committed
71
  step 'I edit code' do
Ciro Santilli's avatar
Ciro Santilli committed
72 73 74
    set_new_content
  end

75 76 77 78
  step 'I edit code with new lines at end of file' do
    execute_script('blob.editor.setValue("Sample\n\n\n")')
  end

Ciro Santilli's avatar
Ciro Santilli committed
79 80 81 82
  step 'I fill the new file name' do
    fill_in :file_name, with: new_file_name
  end

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

87
  step 'I fill the new file name with an illegal name' do
Douwe Maan's avatar
Douwe Maan committed
88
    fill_in :file_name, with: 'Spaces Not Allowed'
89 90
  end

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

Ciro Santilli's avatar
Ciro Santilli committed
95
  step 'I fill the commit message' do
96
    fill_in :commit_message, with: 'New commit message', visible: true
skv-headless's avatar
skv-headless committed
97 98 99
  end

  step 'I click link "Diff"' do
Douwe Maan's avatar
Douwe Maan committed
100
    click_link 'Preview Changes'
skv-headless's avatar
skv-headless committed
101 102
  end

103 104
  step 'I click on "Commit Changes"' do
    click_button 'Commit Changes'
Ciro Santilli's avatar
Ciro Santilli committed
105 106
  end

Stan Hu's avatar
Stan Hu committed
107 108 109 110
  step 'I click on "Create directory"' do
    click_button 'Create directory'
  end

Douwe Maan's avatar
Douwe Maan committed
111
  step 'I click on "Delete"' do
112
    click_on 'Delete'
Ciro Santilli's avatar
Ciro Santilli committed
113 114
  end

Douwe Maan's avatar
Douwe Maan committed
115 116
  step 'I click on "Delete file"' do
    click_button 'Delete file'
Ciro Santilli's avatar
Ciro Santilli committed
117 118
  end

119
  step 'I click on "Replace"' do
120
    click_on  "Replace"
121 122 123 124 125 126
  end

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

skv-headless's avatar
skv-headless committed
127
  step 'I see diff' do
128
    expect(page).to have_css '.line_holder.new'
skv-headless's avatar
skv-headless committed
129 130
  end

Stan Hu's avatar
Stan Hu committed
131 132
  step 'I click on "New file" link in repo' do
    find('.add-to-tree').click
Douwe Maan's avatar
Douwe Maan committed
133
    click_link 'New file'
134 135
  end

Stan Hu's avatar
Stan Hu committed
136 137 138 139 140 141 142 143 144 145 146 147
  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
148
  end
149

Stan Hu's avatar
Stan Hu committed
150 151
  step 'I fill an existing directory name' do
    fill_in :dir_name, with: 'files'
152 153
  end

Stan Hu's avatar
Stan Hu committed
154
  step 'I can see new file page' do
155
    expect(page).to have_content "New File"
Stan Hu's avatar
Stan Hu committed
156
    expect(page).to have_content "Commit message"
157 158 159 160 161 162 163
  end

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

  step 'I can see the new commit message' do
164
    expect(page).to have_content "New commit message"
165 166 167 168 169 170 171 172
  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
173
      fill_in :commit_message, with: 'New commit message'
174 175 176 177 178 179 180 181
    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
182
    page.within('#modal-upload-blob') do
183 184 185 186 187 188 189 190 191 192 193 194 195
      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

196 197
  step 'I click on files directory' do
    click_link 'files'
198 199
  end

200 201
  step 'I click on History link' do
    click_link 'History'
202 203 204
  end

  step 'I see Browse dir link' do
Phil Hughes's avatar
Phil Hughes committed
205 206
    expect(page).to have_link 'Browse Directory'
    expect(page).not_to have_link 'Browse Code'
207 208 209
  end

  step 'I click on readme file' do
210
    page.within '.tree-table' do
211 212
      click_link 'README.md'
    end
213 214 215
  end

  step 'I see Browse file link' do
Phil Hughes's avatar
Phil Hughes committed
216 217
    expect(page).to have_link 'Browse File'
    expect(page).not_to have_link 'Browse Files'
218 219 220
  end

  step 'I see Browse code link' do
221
    expect(page).to have_link 'Browse Files'
Phil Hughes's avatar
Phil Hughes committed
222
    expect(page).not_to have_link 'Browse Directory'
223
  end
224

225 226
  step 'I click on Permalink' do
    click_link 'Permalink'
227 228
  end

Ciro Santilli's avatar
Ciro Santilli committed
229
  step 'I am redirected to the files URL' do
230
    expect(current_path).to eq namespace_project_tree_path(@project.namespace, @project, 'master')
Ciro Santilli's avatar
Ciro Santilli committed
231 232 233
  end

  step 'I am redirected to the ".gitignore"' do
Vinnie Okada's avatar
Vinnie Okada committed
234
    expect(current_path).to eq(namespace_project_blob_path(@project.namespace, @project, 'master/.gitignore'))
Ciro Santilli's avatar
Ciro Santilli committed
235 236
  end

237
  step 'I am redirected to the permalink URL' do
Vinnie Okada's avatar
Vinnie Okada committed
238 239 240 241 242
    expect(current_path).to(
      eq(namespace_project_blob_path(@project.namespace, @project,
                                     @project.repository.commit.sha +
                                     '/.gitignore'))
    )
243 244
  end

Ciro Santilli's avatar
Ciro Santilli committed
245
  step 'I am redirected to the new file' do
Gabriel Mazetto's avatar
Gabriel Mazetto committed
246 247
    expect(current_path).to eq(
      namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name))
Ciro Santilli's avatar
Ciro Santilli committed
248 249
  end

250
  step 'I am redirected to the new file with directory' do
Gabriel Mazetto's avatar
Gabriel Mazetto committed
251 252
    expect(current_path).to eq(
      namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name_with_directory))
253 254
  end

Douwe Maan's avatar
Douwe Maan committed
255 256
  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's avatar
Stan Hu committed
257 258
  end

259 260 261 262 263
  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's avatar
Stan Hu committed
264
  step 'I am redirected to the root directory' do
Gabriel Mazetto's avatar
Gabriel Mazetto committed
265
    expect(current_path).to eq(
266
      namespace_project_tree_path(@project.namespace, @project, 'master'))
Stan Hu's avatar
Stan Hu committed
267 268
  end

269 270 271
  step "I don't see the permalink link" do
    expect(page).not_to have_link('permalink')
  end
Ciro Santilli's avatar
Ciro Santilli committed
272

Stan Hu's avatar
Stan Hu committed
273 274 275 276
  step 'I see "Unable to create directory"' do
    expect(page).to have_content('Directory already exists')
  end

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

281 282 283 284
  step 'I create bare repo' do
    click_link 'Create empty bare repository'
  end

Rémy Coutable's avatar
Rémy Coutable committed
285 286
  step 'I click on "README" link' do
    click_link 'README'
287 288

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

292 293 294 295
  step "I switch ref to 'test'" do
    select "'test'", from: 'ref'
  end

296 297 298 299
  step "I switch ref to fix" do
    select "fix", from: 'ref'
  end

300 301 302 303 304 305 306 307
  step "I see the ref 'test' has been selected" do
    expect(page).to have_selector '.select2-chosen', text: "'test'"
  end

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

308 309 310 311
  step "I visit the fix tree" do
    visit namespace_project_tree_path(@project.namespace, @project, "fix/.testdir")
  end

312 313 314 315 316
  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

317 318 319 320 321
  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

322
  step 'I click on "files/lfs/lfs_object.iso" file in repo' do
323
    visit namespace_project_tree_path(@project.namespace, @project, "lfs")
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
    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
340 341 342 343 344 345 346 347 348
    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
349 350
  end

351 352 353 354
  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's avatar
Stan Hu committed
355 356 357 358 359 360 361 362 363 364
  # 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
365
    expect(page).to have_css('.file-content img')
Stan Hu's avatar
Stan Hu committed
366 367
  end

Ciro Santilli's avatar
Ciro Santilli committed
368 369 370
  private

  def set_new_content
371
    execute_script("blob.editor.setValue('#{new_gitignore_content}')")
Ciro Santilli's avatar
Ciro Santilli committed
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
  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
390

391 392 393 394 395 396
  # 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's avatar
Stan Hu committed
397 398 399 400 401 402
  # 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

403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
  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's avatar
Stan Hu committed
427 428 429 430

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