Welcome to mirror list, hosted at ThFree Co, Russian Federation.

related_issues_spec.rb « issues « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f460b4b1c7ffd5488ba120aaae71fa2744d44e58 (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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Related issues', :js, feature_category: :team_planning do
  let_it_be(:user) { create(:user) }

  let_it_be(:project) { create(:project_empty_repo, :public) }
  let_it_be(:project_b) { create(:project_empty_repo, :public) }
  let_it_be(:project_unauthorized) { create(:project_empty_repo, :public) }
  let_it_be(:internal_project) { create(:project_empty_repo, :internal) }
  let_it_be(:private_project) { create(:project_empty_repo, :private) }
  let_it_be(:public_project) { create(:project_empty_repo, :public) }

  let_it_be(:issue_a) { create(:issue, project: project) }
  let_it_be(:issue_b) { create(:issue, project: project) }
  let_it_be(:issue_c) { create(:issue, project: project) }
  let_it_be(:issue_d) { create(:issue, project: project) }
  let_it_be(:issue_project_b_a) { create(:issue, project: project_b) }
  let_it_be(:issue_project_unauthorized_a) { create(:issue, project: project_unauthorized) }
  let_it_be(:internal_issue) { create(:issue, project: internal_project) }
  let_it_be(:private_issue) { create(:issue, project: private_project) }
  let_it_be(:public_issue) { create(:issue, project: public_project) }

  context 'widget visibility' do
    context 'when not logged in' do
      it 'does not show widget when internal project' do
        visit project_issue_path(internal_project, internal_issue)

        expect(page).not_to have_css('.related-issues-block')
      end

      it 'does not show widget when private project' do
        visit project_issue_path(private_project, private_issue)

        expect(page).not_to have_css('.related-issues-block')
      end

      it 'shows widget when public project' do
        visit project_issue_path(public_project, public_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end
    end

    context 'when logged in but not a member' do
      before do
        sign_in(user)
      end

      it 'shows widget when internal project' do
        visit project_issue_path(internal_project, internal_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end

      it 'does not show widget when private project' do
        visit project_issue_path(private_project, private_issue)

        expect(page).not_to have_css('.related-issues-block')
      end

      it 'shows widget when public project' do
        visit project_issue_path(public_project, public_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end

      it 'shows widget on their own public issue' do
        issue = create :issue, project: public_project, author: user

        visit project_issue_path(public_project, issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end
    end

    context 'when logged in and a guest' do
      before do
        sign_in(user)
      end

      it 'shows widget when internal project' do
        internal_project.add_guest(user)

        visit project_issue_path(internal_project, internal_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end

      it 'shows widget when private project' do
        private_project.add_guest(user)

        visit project_issue_path(private_project, private_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end

      it 'shows widget when public project' do
        public_project.add_guest(user)

        visit project_issue_path(public_project, public_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).not_to have_button 'Add a related issue'
      end
    end

    context 'when logged in and a reporter' do
      before do
        sign_in(user)
      end

      it 'shows widget when internal project' do
        internal_project.add_reporter(user)

        visit project_issue_path(internal_project, internal_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).to have_button 'Add a related issue'
      end

      it 'shows widget when private project' do
        private_project.add_reporter(user)

        visit project_issue_path(private_project, private_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).to have_button 'Add a related issue'
      end

      it 'shows widget when public project' do
        public_project.add_reporter(user)

        visit project_issue_path(public_project, public_issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).to have_button 'Add a related issue'
      end

      it 'shows widget on their own public issue' do
        issue = create :issue, project: public_project, author: user
        public_project.add_reporter(user)

        visit project_issue_path(public_project, issue)

        expect(page).to have_css('.related-issues-block')
        expect(page).to have_button 'Add a related issue'
      end
    end
  end

  context 'when user has no permission to manage related issues' do
    let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b }
    let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }

    before_all do
      project.add_guest(user)
    end

    before do
      sign_in(user)
    end

    context 'visiting some issue someone else created' do
      before do
        visit project_issue_path(project, issue_a)
        wait_for_requests
      end

      it 'shows related issues count' do
        expect(find('.js-related-issues-header-issue-count')).to have_content('2')
      end
    end

    context 'visiting issue_b which was targeted by issue_a' do
      before do
        visit project_issue_path(project, issue_b)
        wait_for_requests
      end

      it 'shows related issues count' do
        expect(find('.js-related-issues-header-issue-count')).to have_content('1')
      end
    end
  end

  context 'when user has permission to manage related issues' do
    before_all do
      project.add_maintainer(user)
      project_b.add_maintainer(user)
    end

    before do
      sign_in(user)
    end

    context 'without existing related issues' do
      before do
        visit project_issue_path(project, issue_a)
        wait_for_requests
      end

      it 'shows related issues count' do
        expect(find('.js-related-issues-header-issue-count')).to have_content('0')
      end

      it 'add related issue' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: "#{issue_b.to_reference(project)} "
        page.within('.linked-issues-card-body') do
          click_button 'Add'
        end

        wait_for_requests

        items = all('.item-title a')

        # Form gets hidden after submission
        expect(page).not_to have_selector('.js-add-related-issues-form-area')
        # Check if related issues are present
        expect(items.count).to eq(1)
        expect(items[0].text).to eq(issue_b.title)
        expect(find('.js-related-issues-header-issue-count')).to have_content('1')
      end

      it 'add cross-project related issue' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: "#{issue_project_b_a.to_reference(project)} "
        page.within('.linked-issues-card-body') do
          click_button 'Add'
        end

        wait_for_requests

        items = all('.item-title a')

        expect(items.count).to eq(1)
        expect(items[0].text).to eq(issue_project_b_a.title)
        expect(find('.js-related-issues-header-issue-count')).to have_content('1')
      end

      it 'pressing enter should submit the form' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: "#{issue_project_b_a.to_reference(project)} "
        find_field('Paste issue link').native.send_key(:enter)

        wait_for_requests

        items = all('.item-title a')

        expect(items.count).to eq(1)
        expect(items[0].text).to eq(issue_project_b_a.title)
        expect(find('.js-related-issues-header-issue-count')).to have_content('1')
      end

      it 'disallows duplicate entries' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: 'duplicate duplicate duplicate'

        items = all('.issue-token')
        expect(items.count).to eq(1)
        expect(items[0].text).to eq('duplicate')

        # Pending issues aren't counted towards the related issue count
        expect(find('.js-related-issues-header-issue-count')).to have_content('0')
      end

      it 'allows us to remove pending issues' do
        # Tests against https://gitlab.com/gitlab-org/gitlab/issues/11625
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: 'issue1 issue2 issue3 '

        items = all('.issue-token')
        expect(items.count).to eq(3)
        expect(items[0].text).to eq('issue1')
        expect(items[1].text).to eq('issue2')
        expect(items[2].text).to eq('issue3')

        # Remove pending issues left to right to make sure none get stuck
        within items[0] do
          click_button 'Remove'
        end
        items = all('.issue-token')
        expect(items.count).to eq(2)
        expect(items[0].text).to eq('issue2')
        expect(items[1].text).to eq('issue3')

        within items[0] do
          click_button 'Remove'
        end
        items = all('.issue-token')
        expect(items.count).to eq(1)
        expect(items[0].text).to eq('issue3')

        within items[0] do
          click_button 'Remove'
        end
        items = all('.issue-token')
        expect(items.count).to eq(0)
      end
    end

    context 'with existing related issues' do
      let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b }
      let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }

      before do
        visit project_issue_path(project, issue_a)
        wait_for_requests
      end

      it 'shows related issues count' do
        expect(find('.js-related-issues-header-issue-count')).to have_content('2')
      end

      it 'shows related issues' do
        items = all('.item-title a')

        expect(items.count).to eq(2)
        expect(items[0].text).to eq(issue_b.title)
        expect(items[1].text).to eq(issue_c.title)
      end

      it 'allows us to remove a related issues' do
        items_before = all('.item-title a')

        expect(items_before.count).to eq(2)

        first('.js-issue-item-remove-button').click

        wait_for_requests

        items_after = all('.item-title a')

        expect(items_after.count).to eq(1)
      end

      it 'add related issue' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: "##{issue_d.iid} "
        page.within('.linked-issues-card-body') do
          click_button 'Add'
        end

        wait_for_requests

        items = all('.item-title a')

        expect(items.count).to eq(3)
        expect(items[0].text).to eq(issue_b.title)
        expect(items[1].text).to eq(issue_c.title)
        expect(items[2].text).to eq(issue_d.title)
        expect(find('.js-related-issues-header-issue-count')).to have_content('3')
      end

      it 'add invalid related issue' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: '#9999999 '
        page.within('.linked-issues-card-body') do
          click_button 'Add'
        end

        wait_for_requests

        items = all('.item-title a')

        expect(items.count).to eq(2)
        expect(items[0].text).to eq(issue_b.title)
        expect(items[1].text).to eq(issue_c.title)
        expect(find('.js-related-issues-header-issue-count')).to have_content('2')
      end

      it 'add unauthorized related issue' do
        click_button 'Add a related issue'
        fill_in 'Paste issue link', with: "#{issue_project_unauthorized_a.to_reference(project)} "
        page.within('.linked-issues-card-body') do
          click_button 'Add'
        end

        wait_for_requests

        items = all('.item-title a')

        expect(items.count).to eq(2)
        expect(items[0].text).to eq(issue_b.title)
        expect(items[1].text).to eq(issue_c.title)
        expect(find('.js-related-issues-header-issue-count')).to have_content('2')
      end
    end
  end
end