conflicts_spec.rb 6.4 KB
Newer Older
S
Sean McGivern 已提交
1 2 3 4 5 6 7 8 9 10 11 12
require 'spec_helper'

feature 'Merge request conflict resolution', js: true, feature: true do
  let(:user) { create(:user) }
  let(:project) { create(:project) }

  def create_merge_request(source_branch)
    create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start', source_project: project) do |mr|
      mr.mark_as_unmergeable
    end
  end

13 14 15 16 17
  shared_examples "conflicts are resolved in Interactive mode" do
    it 'conflicts are resolved in Interactive mode' do
      within find('.files-wrapper .diff-file', text: 'files/ruby/popen.rb') do
        click_button 'Use ours'
      end
S
Sean McGivern 已提交
18

19 20
      within find('.files-wrapper .diff-file', text: 'files/ruby/regex.rb') do
        all('button', text: 'Use ours').each do |button|
21
          button.trigger('click')
22 23
        end
      end
S
Sean McGivern 已提交
24

25
      click_button 'Commit conflict resolution'
26
      wait_for_requests
S
Sean McGivern 已提交
27

28 29
      expect(page).to have_content('All merge conflicts were resolved')
      merge_request.reload_diff
S
Sean McGivern 已提交
30

31
      click_on 'Changes'
32
      wait_for_requests
S
Sean McGivern 已提交
33

34 35 36
      within find('.diff-file', text: 'files/ruby/popen.rb') do
        expect(page).to have_selector('.line_content.new', text: "vars = { 'PWD' => path }")
        expect(page).to have_selector('.line_content.new', text: "options = { chdir: path }")
S
Sean McGivern 已提交
37
      end
38

39 40 41 42 43 44 45 46 47 48
      within find('.diff-file', text: 'files/ruby/regex.rb') do
        expect(page).to have_selector('.line_content.new', text: "def username_regexp")
        expect(page).to have_selector('.line_content.new', text: "def project_name_regexp")
        expect(page).to have_selector('.line_content.new', text: "def path_regexp")
        expect(page).to have_selector('.line_content.new', text: "def archive_formats_regexp")
        expect(page).to have_selector('.line_content.new', text: "def git_reference_regexp")
        expect(page).to have_selector('.line_content.new', text: "def default_regexp")
      end
    end
  end
49

50 51 52
  shared_examples "conflicts are resolved in Edit inline mode" do
    it 'conflicts are resolved in Edit inline mode' do
      expect(find('#conflicts')).to have_content('popen.rb')
53

54 55
      within find('.files-wrapper .diff-file', text: 'files/ruby/popen.rb') do
        click_button 'Edit inline'
56
        wait_for_requests
57
        execute_script('ace.edit($(".files-wrapper .diff-file pre")[0]).setValue("One morning");')
58
      end
59 60 61

      within find('.files-wrapper .diff-file', text: 'files/ruby/regex.rb') do
        click_button 'Edit inline'
62
        wait_for_requests
63 64 65 66
        execute_script('ace.edit($(".files-wrapper .diff-file pre")[1]).setValue("Gregor Samsa woke from troubled dreams");')
      end

      click_button 'Commit conflict resolution'
67
      wait_for_requests
68 69 70 71
      expect(page).to have_content('All merge conflicts were resolved')
      merge_request.reload_diff

      click_on 'Changes'
72
      wait_for_requests
73 74 75

      expect(page).to have_content('One morning')
      expect(page).to have_content('Gregor Samsa woke from troubled dreams')
S
Sean McGivern 已提交
76 77 78
    end
  end

79
  context 'can be resolved in the UI' do
80 81 82
    before do
      project.team << [user, :developer]
      login_as(user)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    end

    context 'the conflicts are resolvable' do
      let(:merge_request) { create_merge_request('conflict-resolvable') }

      before { visit namespace_project_merge_request_path(project.namespace, project, merge_request) }

      it 'shows a link to the conflict resolution page' do
        expect(page).to have_link('conflicts', href: /\/conflicts\Z/)
      end

      context 'in Inline view mode' do
        before { click_link('conflicts', href: /\/conflicts\Z/) }

        include_examples "conflicts are resolved in Interactive mode"
        include_examples "conflicts are resolved in Edit inline mode"
      end

      context 'in Parallel view mode' do
        before do
103
          click_link('conflicts', href: /\/conflicts\Z/)
104 105
          click_button 'Side-by-side'
        end
106

107 108 109
        include_examples "conflicts are resolved in Interactive mode"
        include_examples "conflicts are resolved in Edit inline mode"
      end
110 111
    end

112 113 114 115 116 117 118 119 120 121 122 123 124 125
    context 'the conflict contain markers' do
      let(:merge_request) { create_merge_request('conflict-contains-conflict-markers') }

      before do
        visit namespace_project_merge_request_path(project.namespace, project, merge_request)
        click_link('conflicts', href: /\/conflicts\Z/)
      end

      it 'conflicts can not be resolved in Interactive mode' do
        within find('.files-wrapper .diff-file', text: 'files/markdown/ruby-style-guide.md') do
          expect(page).not_to have_content 'Interactive mode'
          expect(page).not_to have_content 'Edit inline'
        end
      end
126

127
      it 'conflicts are resolved in Edit inline mode' do
128
        within find('.files-wrapper .diff-file', text: 'files/markdown/ruby-style-guide.md') do
129
          wait_for_requests
130
          execute_script('ace.edit($(".files-wrapper .diff-file pre")[0]).setValue("Gregor Samsa woke from troubled dreams");')
131 132 133
        end

        click_button 'Commit conflict resolution'
134
        wait_for_requests
135 136 137 138 139 140

        expect(page).to have_content('All merge conflicts were resolved')

        merge_request.reload_diff

        click_on 'Changes'
141
        wait_for_requests
142
        click_link 'Expand all'
143
        wait_for_requests
144 145 146 147 148 149

        expect(page).to have_content('Gregor Samsa woke from troubled dreams')
      end
    end
  end

S
Sean McGivern 已提交
150 151 152
  UNRESOLVABLE_CONFLICTS = {
    'conflict-too-large' => 'when the conflicts contain a large file',
    'conflict-binary-file' => 'when the conflicts contain a binary file',
153
    'conflict-missing-side' => 'when the conflicts contain a file edited in one branch and deleted in another',
154
    'conflict-non-utf8' => 'when the conflicts contain a non-UTF-8 file'
D
Douwe Maan 已提交
155
  }.freeze
S
Sean McGivern 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

  UNRESOLVABLE_CONFLICTS.each do |source_branch, description|
    context description do
      let(:merge_request) { create_merge_request(source_branch) }

      before do
        project.team << [user, :developer]
        login_as(user)

        visit namespace_project_merge_request_path(project.namespace, project, merge_request)
      end

      it 'does not show a link to the conflict resolution page' do
        expect(page).not_to have_link('conflicts', href: /\/conflicts\Z/)
      end

      it 'shows an error if the conflicts page is visited directly' do
        visit current_url + '/conflicts'
174
        wait_for_requests
S
Sean McGivern 已提交
175

176
        expect(find('#conflicts')).to have_content('Please try to resolve them locally.')
S
Sean McGivern 已提交
177 178 179 180
      end
    end
  end
end