summaryrefslogtreecommitdiff
path: root/spec/features/merge_request/user_sees_discussions_navigation_spec.rb
blob: 9d3046a9a72e5e4a458cfe70a755cafc4a416e36 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Merge request > User sees discussions navigation', :js, feature_category: :code_review_workflow do
  let_it_be(:project) { create(:project, :public, :repository) }
  let_it_be(:user) { project.creator }
  let_it_be(:merge_request) { create(:merge_request, source_project: project) }

  before do
    project.add_maintainer(user)
    sign_in(user)
  end

  describe 'Code discussions' do
    let!(:position) do
      build(:text_diff_position, :added,
            file: "files/images/wm.svg",
            new_line: 1,
            diff_refs: merge_request.diff_refs
      )
    end

    let!(:first_discussion) do
      create(:diff_note_on_merge_request,
             noteable: merge_request,
             project: project,
             position: position
            ).to_discussion
    end

    let!(:second_discussion) do
      create(:diff_note_on_merge_request,
             noteable: merge_request,
             project: project,
             position: position
            ).to_discussion
    end

    let(:first_discussion_selector) { ".discussion[data-discussion-id='#{first_discussion.id}']" }
    let(:second_discussion_selector) { ".discussion[data-discussion-id='#{second_discussion.id}']" }

    shared_examples 'a page with a thread navigation' do
      context 'with active threads' do
        it 'navigates to the first thread' do
          goto_next_thread
          expect(page).to have_selector(first_discussion_selector, obscured: false)
        end

        it 'navigates to the last thread' do
          goto_previous_thread
          expect(page).to have_selector(second_discussion_selector, obscured: false)
        end

        it 'navigates through active threads' do
          goto_next_thread
          goto_next_thread
          expect(page).to have_selector(second_discussion_selector, obscured: false)
        end

        it 'cycles back to the first thread' do
          goto_next_thread
          goto_next_thread
          goto_next_thread
          expect(page).to have_selector(first_discussion_selector, obscured: false)
        end

        it 'cycles back to the last thread' do
          goto_previous_thread
          goto_previous_thread
          goto_previous_thread
          expect(page).to have_selector(second_discussion_selector, obscured: false)
        end
      end

      context 'with resolved threads' do
        let!(:resolved_discussion) do
          create(:diff_note_on_merge_request,
                 noteable: merge_request,
                 project: project,
                 position: position
                ).to_discussion
        end

        let(:resolved_discussion_selector) { ".discussion[data-discussion-id='#{resolved_discussion.id}']" }

        before do
          # :resolved attr doesn't actually resolve the thread but just collapses it
          page.within(resolved_discussion_selector) do
            click_button text: 'Resolve thread'
          end
          page.execute_script("window.scrollTo(0,0)")
        end

        it 'excludes resolved threads during navigation' do
          goto_next_thread
          goto_next_thread
          goto_next_thread
          expect(page).to have_selector(first_discussion_selector, obscured: false)
        end
      end
    end

    describe "Overview page discussions navigation" do
      before do
        visit project_merge_request_path(project, merge_request)
      end

      it_behaves_like 'a page with a thread navigation'

      context 'with collapsed threads' do
        before do
          page.within(first_discussion_selector) do
            click_button 'Hide thread'
          end
        end

        it 'expands threads during navigation' do
          goto_next_thread
          expect(page).to have_selector "#note_#{first_discussion.first_note.id}"
        end
      end
    end

    describe "Changes page discussions navigation" do
      before do
        visit diffs_project_merge_request_path(project, merge_request)
      end

      it_behaves_like 'a page with a thread navigation'
    end
  end

  describe 'Merge request discussions' do
    shared_examples 'a page with no code discussions' do
      let!(:first_discussion) do
        create(:discussion_note_on_merge_request,
               noteable: merge_request,
               project: project
              ).to_discussion
      end

      let!(:second_discussion) do
        create(:discussion_note_on_merge_request,
               noteable: merge_request,
               project: project
              ).to_discussion
      end

      let(:first_discussion_selector) { ".discussion[data-discussion-id='#{first_discussion.id}']" }
      let(:second_discussion_selector) { ".discussion[data-discussion-id='#{second_discussion.id}']" }

      describe "Changes page discussions navigation" do
        it 'navigates to the first discussion on the Overview page' do
          goto_next_thread
          expect(page).to have_selector(first_discussion_selector, obscured: false)
        end

        it 'navigates to the last discussion on the Overview page' do
          goto_previous_thread
          expect(page).to have_selector(second_discussion_selector, obscured: false)
        end
      end
    end

    context 'on changes page' do
      before do
        visit diffs_project_merge_request_path(project, merge_request)
      end

      it_behaves_like 'a page with no code discussions'
    end

    context 'on commits page' do
      before do
        # we can't go directly to the commits page since it doesn't load discussions
        visit project_merge_request_path(project, merge_request)
        click_link 'Commits'
      end

      it_behaves_like 'a page with no code discussions'
    end

    context 'on pipelines page' do
      before do
        visit project_merge_request_path(project, merge_request)
        click_link 'Pipelines'
      end

      it_behaves_like 'a page with no code discussions'
    end
  end

  def goto_next_thread
    click_button 'Go to next unresolved thread', obscured: false
  end

  def goto_previous_thread
    click_button 'Go to previous unresolved thread', obscured: false
  end
end