browse_files.rb 9.65 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
  step 'I should see files from repository' do
9 10 11
    expect(page).to have_content "VERSION"
    expect(page).to have_content ".gitignore"
    expect(page).to have_content "LICENSE"
12 13
  end

14
  step 'I should see files from repository for "6d39438"' do
15 16 17
    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"
18 19
  end

Ciro Santilli's avatar
Ciro Santilli committed
20
  step 'I see the ".gitignore"' do
21
    expect(page).to have_content '.gitignore'
Ciro Santilli's avatar
Ciro Santilli committed
22 23 24
  end

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

28 29
  step 'I click on ".gitignore" file in repo' do
    click_link ".gitignore"
30 31
  end

Ciro Santilli's avatar
Ciro Santilli committed
32
  step 'I should see its content' do
33
    expect(page).to have_content old_gitignore_content
Ciro Santilli's avatar
Ciro Santilli committed
34 35 36
  end

  step 'I should see its new content' do
37
    expect(page).to have_content new_gitignore_content
38 39
  end

40 41
  step 'I click link "Raw"' do
    click_link 'Raw'
42 43
  end

44
  step 'I should see raw file content' do
45
    expect(source).to eq sample_blob.data
46
  end
Valeriy Sizov's avatar
Valeriy Sizov committed
47

48 49
  step 'I click button "Edit"' do
    click_link 'Edit'
Valeriy Sizov's avatar
Valeriy Sizov committed
50 51
  end

52
  step 'I cannot see the edit button' do
53
    expect(page).not_to have_link 'edit'
54 55 56
  end

  step 'The edit button is disabled' do
57
    expect(page).to have_css '.disabled', text: 'Edit'
58 59
  end

60
  step 'I can edit code' do
Ciro Santilli's avatar
Ciro Santilli committed
61
    set_new_content
62
    expect(evaluate_script('blob.editor.getValue()')).to eq new_gitignore_content
Valeriy Sizov's avatar
Valeriy Sizov committed
63 64
  end

skv-headless's avatar
skv-headless committed
65
  step 'I edit code' do
Ciro Santilli's avatar
Ciro Santilli committed
66 67 68 69 70 71 72
    set_new_content
  end

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

73
  step 'I fill the new branch name' do
Stan Hu's avatar
Stan Hu committed
74
    fill_in :new_branch, with: 'new_branch_name', visible: true
75 76
  end

77
  step 'I fill the new file name with an illegal name' do
Douwe Maan's avatar
Douwe Maan committed
78
    fill_in :file_name, with: 'Spaces Not Allowed'
79 80
  end

81 82 83 84
  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
85
  step 'I fill the commit message' do
86
    fill_in :commit_message, with: 'Not yet a commit message.', visible: true
skv-headless's avatar
skv-headless committed
87 88 89
  end

  step 'I click link "Diff"' do
Douwe Maan's avatar
Douwe Maan committed
90
    click_link 'Preview Changes'
skv-headless's avatar
skv-headless committed
91 92
  end

93 94
  step 'I click on "Commit Changes"' do
    click_button 'Commit Changes'
Ciro Santilli's avatar
Ciro Santilli committed
95 96
  end

Stan Hu's avatar
Stan Hu committed
97 98 99 100
  step 'I click on "Create directory"' do
    click_button 'Create directory'
  end

Douwe Maan's avatar
Douwe Maan committed
101 102
  step 'I click on "Delete"' do
    click_button 'Delete'
Ciro Santilli's avatar
Ciro Santilli committed
103 104
  end

Douwe Maan's avatar
Douwe Maan committed
105 106
  step 'I click on "Delete file"' do
    click_button 'Delete file'
Ciro Santilli's avatar
Ciro Santilli committed
107 108
  end

109 110 111 112 113 114 115 116
  step 'I click on "Replace"' do
    click_button  "Replace"
  end

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

skv-headless's avatar
skv-headless committed
117
  step 'I see diff' do
118
    expect(page).to have_css '.line_holder.new'
skv-headless's avatar
skv-headless committed
119 120
  end

Stan Hu's avatar
Stan Hu committed
121 122 123
  step 'I click on "New file" link in repo' do
    find('.add-to-tree').click
    click_link 'Create file'
124 125
  end

Stan Hu's avatar
Stan Hu committed
126 127 128 129 130 131 132 133 134 135 136 137
  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
138
  end
139

Stan Hu's avatar
Stan Hu committed
140 141
  step 'I fill an existing directory name' do
    fill_in :dir_name, with: 'files'
142 143
  end

Stan Hu's avatar
Stan Hu committed
144
  step 'I can see new file page' do
145
    expect(page).to have_content "New File"
Stan Hu's avatar
Stan Hu committed
146
    expect(page).to have_content "Commit message"
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
  end

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

  step 'I can see the new commit message' do
    expect(page).to have_content "New upload commit message"
  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
      fill_in :commit_message, with: 'New upload commit message'
    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
172
    page.within('#modal-upload-blob') do
173 174 175 176 177 178 179 180 181 182 183 184 185
      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

186 187
  step 'I click on files directory' do
    click_link 'files'
188 189
  end

190 191
  step 'I click on History link' do
    click_link 'History'
192 193 194
  end

  step 'I see Browse dir link' do
195
    expect(page).to have_link 'Browse Directory »'
196
    expect(page).not_to have_link 'Browse Code »'
197 198 199
  end

  step 'I click on readme file' do
200
    page.within '.tree-table' do
201 202
      click_link 'README.md'
    end
203 204 205
  end

  step 'I see Browse file link' do
206
    expect(page).to have_link 'Browse File »'
207
    expect(page).not_to have_link 'Browse Files »'
208 209 210
  end

  step 'I see Browse code link' do
211
    expect(page).to have_link 'Browse Files »'
212
    expect(page).not_to have_link 'Browse File »'
213
    expect(page).not_to have_link 'Browse Directory »'
214
  end
215

216 217
  step 'I click on Permalink' do
    click_link 'Permalink'
218 219
  end

Ciro Santilli's avatar
Ciro Santilli committed
220
  step 'I am redirected to the files URL' do
221
    expect(current_path).to eq namespace_project_tree_path(@project.namespace, @project, 'master')
Ciro Santilli's avatar
Ciro Santilli committed
222 223 224
  end

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

228
  step 'I am redirected to the permalink URL' do
Vinnie Okada's avatar
Vinnie Okada committed
229 230 231 232 233
    expect(current_path).to(
      eq(namespace_project_blob_path(@project.namespace, @project,
                                     @project.repository.commit.sha +
                                     '/.gitignore'))
    )
234 235
  end

Ciro Santilli's avatar
Ciro Santilli committed
236
  step 'I am redirected to the new file' do
Vinnie Okada's avatar
Vinnie Okada committed
237 238
    expect(current_path).to eq(namespace_project_blob_path(
      @project.namespace, @project, 'master/' + new_file_name))
Ciro Santilli's avatar
Ciro Santilli committed
239 240
  end

241 242 243 244 245
  step 'I am redirected to the new file with directory' do
    expect(current_path).to eq(namespace_project_blob_path(
      @project.namespace, @project, 'master/' + new_file_name_with_directory))
  end

Douwe Maan's avatar
Douwe Maan committed
246 247
  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
248 249 250 251 252 253 254
  end

  step 'I am redirected to the root directory' do
    expect(current_path).to eq(namespace_project_tree_path(
      @project.namespace, @project, 'master/'))
  end

255 256 257
  step "I don't see the permalink link" do
    expect(page).not_to have_link('permalink')
  end
Ciro Santilli's avatar
Ciro Santilli committed
258

Stan Hu's avatar
Stan Hu committed
259 260 261 262
  step 'I see "Unable to create directory"' do
    expect(page).to have_content('Directory already exists')
  end

263 264 265 266
  step 'I see a commit error message' do
    expect(page).to have_content('Your changes could not be committed')
  end

267 268 269 270 271
  step 'I create bare repo' do
    click_link 'Create empty bare repository'
  end

  step 'I click on "add a file" link' do
272
    click_link 'adding README'
273 274

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

278 279 280 281
  step "I switch ref to 'test'" do
    select "'test'", from: 'ref'
  end

282 283 284 285
  step "I switch ref to fix" do
    select "fix", from: 'ref'
  end

286 287 288 289 290 291 292 293
  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

294 295 296 297
  step "I visit the fix tree" do
    visit namespace_project_tree_path(@project.namespace, @project, "fix/.testdir")
  end

298 299 300 301 302
  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

303 304 305 306 307
  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

Ciro Santilli's avatar
Ciro Santilli committed
308 309 310
  private

  def set_new_content
311
    execute_script("blob.editor.setValue('#{new_gitignore_content}')")
Ciro Santilli's avatar
Ciro Santilli committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
  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
330

331 332 333 334 335 336
  # 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
337 338 339 340 341 342
  # 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

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
  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
367
end