Read about our upcoming Code of Conduct on this issue

resolve_outdated_diff_discussions.rb 2.88 KB
Newer Older
1
2
require 'spec_helper'

3
feature 'Resolve outdated diff discussions', js: true do
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  let(:merge_request) { create(:merge_request, importing: true) }
  let(:project) { merge_request.source_project }

  let!(:outdated_discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: outdated_position).to_discussion }
  let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }

  let(:outdated_position) do
    Gitlab::Diff::Position.new(
      old_path: "files/ruby/popen.rb",
      new_path: "files/ruby/popen.rb",
      old_line: nil,
      new_line: 9,
      diff_refs: outdated_diff_refs
    )
  end

  let(:outdated_diff_refs) { project.commit("874797c3a73b60d2187ed6e2fcabd289ff75171e").diff_refs }

  before do
    sign_in(create(:admin))
  end

26
  context 'when project.resolve_outdated_diff_discussions == true' do
27
    before do
28
      project.update_column(:resolve_outdated_diff_discussions, true)
29
30
31
32
33
34
35
    end

    context 'with unresolved outdated discussions' do
      it 'does not show outdated discussion' do
        visit_merge_request(merge_request)
        within(".discussion[data-discussion-id='#{outdated_discussion.id}']") do
          expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: false)
36
          expect(page).to have_content('Automatically resolved')
37
38
39
40
41
42
43
44
45
        end
      end
    end

    context 'with unresolved active discussions' do
      it 'shows active discussion' do
        visit_merge_request(merge_request)
        within(".discussion[data-discussion-id='#{active_discussion.id}']") do
          expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: true)
46
          expect(page).not_to have_content('Automatically resolved')
47
48
49
50
51
        end
      end
    end
  end

52
  context 'when project.resolve_outdated_diff_discussions == false' do
53
    before do
54
      project.update_column(:resolve_outdated_diff_discussions, false)
55
56
57
58
59
60
61
    end

    context 'with unresolved outdated discussions' do
      it 'shows outdated discussion' do
        visit_merge_request(merge_request)
        within(".discussion[data-discussion-id='#{outdated_discussion.id}']") do
          expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: true)
62
          expect(page).not_to have_content('Automatically resolved')
63
64
65
66
67
68
69
70
71
        end
      end
    end

    context 'with unresolved active discussions' do
      it 'shows active discussion' do
        visit_merge_request(merge_request)
        within(".discussion[data-discussion-id='#{active_discussion.id}']") do
          expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: true)
72
          expect(page).not_to have_content('Automatically resolved')
73
74
75
76
77
78
79
80
        end
      end
    end
  end
  def visit_merge_request(merge_request)
    visit project_merge_request_path(project, merge_request)
  end
end