summaryrefslogtreecommitdiff
path: root/spec/features/merge_requests/diffs_spec.rb
blob: 35f5bfe46bee23c9778a8aa188f8f64da6da7213 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require 'spec_helper'

feature 'Diffs URL', js: true, feature: true do
  before do
    login_as :admin
    @merge_request = create(:merge_request)
    @project = @merge_request.source_project
  end

  context 'when visit with */* as accept header' do
    before(:each) do
      page.driver.add_header('Accept', '*/*')
    end

    it 'renders the notes' do
      create :note_on_merge_request, project: @project, noteable: @merge_request, note: 'Rebasing with master'

      visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)

      # 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

  context 'when hovering over the parallel view diff file' do
    let(:comment_button_class) { '.add-diff-note' }

    before(:each) do
      visit diffs_namespace_project_merge_request_path @project.namespace, @project, @merge_request
      click_link 'Side-by-side'
      @old_line_number = first '.diff-line-num.old_line:not(.empty-cell)'
      @new_line_number = first '.diff-line-num.new_line:not(.empty-cell)'
      @old_line = first '.line_content[data-line-type="old"]'
      @new_line = first '.line_content[data-line-type="new"]'
    end

    it 'shows a comment button on the old side when hovering over an old line number' do
      @old_line_number.hover
      expect(@old_line_number).to have_css comment_button_class
      expect(@new_line_number).not_to have_css comment_button_class
    end

    it 'shows a comment button on the old side when hovering over an old line' do
      @old_line.hover
      expect(@old_line_number).to have_css comment_button_class
      expect(@new_line_number).not_to have_css comment_button_class
    end

    it 'shows a comment button on the new side when hovering over a new line number' do
      @new_line_number.hover
      expect(@new_line_number).to have_css comment_button_class
      expect(@old_line_number).not_to have_css comment_button_class
    end

    it 'shows a comment button on the new side when hovering over a new line' do
      @new_line.hover
      expect(@new_line_number).to have_css comment_button_class
      expect(@old_line_number).not_to have_css comment_button_class
    end
  end

  context 'when hovering over the inline view diff file' do
    let(:comment_button_class) { '.add-diff-note' }

    before(:each) do
      visit diffs_namespace_project_merge_request_path @project.namespace, @project, @merge_request
      click_link 'Inline'
      @old_line_number = first '.diff-line-num.old_line:not(.unfold)'
      @new_line_number = first '.diff-line-num.new_line:not(.unfold)'
      @new_line = first '.line_content:not(.match)'
    end

    it 'shows a comment button on the old side when hovering over an old line number' do
      @old_line_number.hover
      expect(@old_line_number).to have_css comment_button_class
      expect(@new_line_number).not_to have_css comment_button_class
    end

    it 'shows a comment button on the new side when hovering over a new line number' do
      @new_line_number.hover
      expect(@old_line_number).to have_css comment_button_class
      expect(@new_line_number).not_to have_css comment_button_class
    end

    it 'shows a comment button on the new side when hovering over a new line' do
      @new_line.hover
      expect(@old_line_number).to have_css comment_button_class
      expect(@new_line_number).not_to have_css comment_button_class
    end
  end

  context 'when clicking a comment button' do
    let(:test_note_comment) { 'this is a test note!' }
    let(:note_class) { '.new-note' }

    before(:each) do
      visit diffs_namespace_project_merge_request_path @project.namespace, @project, @merge_request
      click_link 'Inline'
      first('.diff-line-num.old_line:not(.unfold)').hover
      find('.add-diff-note').click
    end

    it 'shows a note form' do
      expect(page).to have_css note_class
    end

    it 'can be submitted and viewed' do
      fill_in 'note[note]', with: :test_note_comment
      click_button 'Comment'
      expect(page).to have_content :test_note_comment
    end

    it 'can be closed' do
      find('.note-form-actions .btn-cancel').click
      expect(page).not_to have_css note_class
    end
  end
end