versions_spec.rb 6.7 KB
Newer Older
1 2 3
require 'spec_helper'

feature 'Merge Request versions', js: true, feature: true do
4 5
  let(:merge_request) { create(:merge_request, importing: true) }
  let(:project) { merge_request.source_project }
6 7 8
  let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
  let!(:merge_request_diff2) { merge_request.merge_request_diffs.create(head_commit_sha: nil) }
  let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
9

10
  before do
11
    sign_in(create(:admin))
12
    visit diffs_project_merge_request_path(project, merge_request)
13 14 15
  end

  it 'show the latest version of the diff' do
16
    page.within '.mr-version-dropdown' do
17
      expect(page).to have_content 'latest version'
18 19 20 21 22 23 24
    end

    expect(page).to have_content '8 changed files'
  end

  describe 'switch between versions' do
    before do
25
      page.within '.mr-version-dropdown' do
26
        find('.btn-default').click
27 28 29 30 31 32
        click_link 'version 1'
      end

      # Wait for the page to load
      page.within '.mr-version-dropdown' do
        expect(page).to have_content 'version 1'
33 34 35 36
      end
    end

    it 'should show older version' do
37
      page.within '.mr-version-dropdown' do
38
        expect(page).to have_content 'version 1'
39 40 41 42
      end

      expect(page).to have_content '5 changed files'
    end
43

44 45
    it 'show the message about comments' do
      expect(page).to have_content 'Not all comments are displayed'
46
    end
Douwe Maan's avatar
Douwe Maan committed
47 48 49 50 51 52 53 54 55 56 57 58 59

    it 'shows comments that were last relevant at that version' do
      position = Gitlab::Diff::Position.new(
        old_path: ".gitmodules",
        new_path: ".gitmodules",
        old_line: nil,
        new_line: 4,
        diff_refs: merge_request_diff1.diff_refs
      )
      outdated_diff_note = create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position)
      outdated_diff_note.position = outdated_diff_note.original_position
      outdated_diff_note.save!

60 61
      visit current_url

Douwe Maan's avatar
Douwe Maan committed
62 63
      expect(page).to have_css(".diffs .notes[data-discussion-id='#{outdated_diff_note.discussion_id}']")
    end
64 65 66 67 68 69 70 71 72 73 74 75 76 77

    it 'allows commenting' do
      diff_file_selector = ".diff-file[id='7445606fbf8f3683cd42bdc54b05d7a0bc2dfc44']"
      line_code = '7445606fbf8f3683cd42bdc54b05d7a0bc2dfc44_2_2'

      page.within(diff_file_selector) do
        find(".line_holder[id='#{line_code}'] td:nth-of-type(1)").trigger 'mouseover'
        find(".line_holder[id='#{line_code}'] button").trigger 'click'

        page.within("form[data-line-code='#{line_code}']") do
          fill_in "note[note]", with: "Typo, please fix"
          find(".js-comment-button").click
        end

78
        wait_for_requests
79 80 81 82

        expect(page).to have_content("Typo, please fix")
      end
    end
83 84 85 86 87
  end

  describe 'compare with older version' do
    before do
      page.within '.mr-version-compare-dropdown' do
88
        find('.btn-default').click
89 90 91 92 93 94
        click_link 'version 1'
      end

      # Wait for the page to load
      page.within '.mr-version-compare-dropdown' do
        expect(page).to have_content 'version 1'
95 96 97
      end
    end

98
    it 'has a path with comparison context' do
99
      expect(page).to have_current_path diffs_project_merge_request_path(
100 101
        project,
        merge_request.iid,
102
        diff_id: merge_request_diff3.id,
103 104 105 106
        start_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9'
      )
    end

107
    it 'should have correct value in the compare dropdown' do
108
      page.within '.mr-version-compare-dropdown' do
109
        expect(page).to have_content 'version 1'
110
      end
111
    end
112

113 114 115 116 117 118 119 120 121 122 123 124 125
    it 'show the message about comments' do
      expect(page).to have_content 'Not all comments are displayed'
    end

    it 'shows comments that were last relevant at that version' do
      position = Gitlab::Diff::Position.new(
        old_path: ".gitmodules",
        new_path: ".gitmodules",
        old_line: 4,
        new_line: 4,
        diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs
      )
      outdated_diff_note = create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position)
126 127
      outdated_diff_note.position = outdated_diff_note.original_position
      outdated_diff_note.save!
128 129

      visit current_url
130
      wait_for_requests
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

      expect(page).to have_css(".diffs .notes[data-discussion-id='#{outdated_diff_note.discussion_id}']")
    end

    it 'allows commenting' do
      diff_file_selector = ".diff-file[id='7445606fbf8f3683cd42bdc54b05d7a0bc2dfc44']"
      line_code = '7445606fbf8f3683cd42bdc54b05d7a0bc2dfc44_4_4'

      page.within(diff_file_selector) do
        find(".line_holder[id='#{line_code}'] td:nth-of-type(1)").trigger 'mouseover'
        find(".line_holder[id='#{line_code}'] button").trigger 'click'

        page.within("form[data-line-code='#{line_code}']") do
          fill_in "note[note]", with: "Typo, please fix"
          find(".js-comment-button").click
        end

148
        wait_for_requests
149 150 151

        expect(page).to have_content("Typo, please fix")
      end
152 153 154 155 156 157
    end

    it 'show diff between new and old version' do
      expect(page).to have_content '4 changed files with 15 additions and 6 deletions'
    end

158 159 160 161 162 163 164
    it 'should return to latest version when "Show latest version" button is clicked' do
      click_link 'Show latest version'
      page.within '.mr-version-dropdown' do
        expect(page).to have_content 'latest version'
      end
      expect(page).to have_content '8 changed files'
    end
165
  end
166 167 168 169 170 171 172 173 174 175 176

  describe 'compare with same version' do
    before do
      page.within '.mr-version-compare-dropdown' do
        find('.btn-default').click
        click_link 'version 1'
      end
    end

    it 'should have 0 chages between versions' do
      page.within '.mr-version-compare-dropdown' do
177
        expect(find('.dropdown-toggle')).to have_content 'version 1'
178 179 180 181
      end

      page.within '.mr-version-dropdown' do
        find('.btn-default').click
182
        click_link 'version 1'
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
      end
      expect(page).to have_content '0 changed files'
    end
  end

  describe 'compare with newer version' do
    before do
      page.within '.mr-version-compare-dropdown' do
        find('.btn-default').click
        click_link 'version 2'
      end
    end

    it 'should set the compared versions to be the same' do
      page.within '.mr-version-compare-dropdown' do
198
        expect(find('.dropdown-toggle')).to have_content 'version 2'
199 200 201 202
      end

      page.within '.mr-version-dropdown' do
        find('.btn-default').click
203
        click_link 'version 1'
204 205 206 207 208 209 210 211 212
      end

      page.within '.mr-version-compare-dropdown' do
        expect(page).to have_content 'version 1'
      end

      expect(page).to have_content '0 changed files'
    end
  end
213
end