user_sees_diff_spec.rb 3.35 KB
Newer Older
1
require 'rails_helper'
2

3
describe 'Merge request > User sees diff', :js do
4 5
  include ProjectForksHelper

6
  let(:project) { create(:project, :public, :repository) }
7
  let(:merge_request) { create(:merge_request, source_project: project) }
8 9 10

  context 'when visit with */* as accept header' do
    it 'renders the notes' do
11
      create :note_on_merge_request, project: project, noteable: merge_request, note: 'Rebasing with master'
12

13 14 15
      inspect_requests(inject_headers: { 'Accept' => '*/*' }) do
        visit diffs_project_merge_request_path(project, merge_request)
      end
16 17 18 19 20 21

      # Load notes and diff through AJAX
      expect(page).to have_css('.note-text', visible: false, text: 'Rebasing with master')
      expect(page).to have_css('.diffs.tab-pane.active')
    end
  end
22

23 24 25 26 27 28
  context 'when linking to note' do
    describe 'with unresolved note' do
      let(:note) { create :diff_note_on_merge_request, project: project, noteable: merge_request }
      let(:fragment) { "#note_#{note.id}" }

      before do
29
        visit "#{diffs_project_merge_request_path(project, merge_request)}#{fragment}"
30 31 32 33 34 35 36 37 38 39 40 41
      end

      it 'shows expanded note' do
        expect(page).to have_selector(fragment, visible: true)
      end
    end

    describe 'with resolved note' do
      let(:note) { create :diff_note_on_merge_request, :resolved, project: project, noteable: merge_request }
      let(:fragment) { "#note_#{note.id}" }

      before do
42
        visit "#{diffs_project_merge_request_path(project, merge_request)}#{fragment}"
43 44
      end

45 46
      it 'shows expanded note' do
        expect(page).to have_selector(fragment, visible: true)
47 48 49 50
      end
    end
  end

51 52
  context 'when merge request has overflow' do
    it 'displays warning' do
53
      allow(Commit).to receive(:max_diff_options).and_return(max_files: 3)
54

55
      visit diffs_project_merge_request_path(project, merge_request)
56 57 58

      page.within('.alert') do
        expect(page).to have_text("Too many changes to show. Plain diff Email patch To preserve
59
          performance only 3 of 3+ files are displayed.")
60 61 62 63
      end
    end
  end

64 65 66
  context 'when editing file' do
    let(:author_user) { create(:user) }
    let(:user) { create(:user) }
67
    let(:forked_project) { fork_project(project, author_user, repository: true) }
68 69
    let(:merge_request) { create(:merge_request_with_diffs, source_project: forked_project, target_project: project, author: author_user) }
    let(:changelog_id) { Digest::SHA1.hexdigest("CHANGELOG") }
70

71 72 73 74
    before do
      forked_project.repository.after_import
    end

75 76
    context 'as author' do
      it 'shows direct edit link' do
77
        sign_in(author_user)
78
        visit diffs_project_merge_request_path(project, merge_request)
79 80 81 82 83 84 85 86

        # Throws `Capybara::Poltergeist::InvalidSelector` if we try to use `#hash` syntax
        expect(page).to have_selector("[id=\"#{changelog_id}\"] a.js-edit-blob")
      end
    end

    context 'as user who needs to fork' do
      it 'shows fork/cancel confirmation' do
87
        sign_in(user)
88
        visit diffs_project_merge_request_path(project, merge_request)
89 90

        # Throws `Capybara::Poltergeist::InvalidSelector` if we try to use `#hash` syntax
91
        find("[id=\"#{changelog_id}\"] .js-edit-blob").click
92 93 94

        expect(page).to have_selector('.js-fork-suggestion-button', count: 1)
        expect(page).to have_selector('.js-cancel-fork-suggestion-button', count: 1)
95 96 97
      end
    end
  end
98
end