summaryrefslogtreecommitdiff
path: root/spec/features/labels_hierarchy_spec.rb
blob: c66d858a019dee5279ff010f49444ab8e5a2041c (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
# frozen_string_literal: true

require 'spec_helper'

describe 'Labels Hierarchy', :js do
  include FilteredSearchHelpers

  let!(:user) { create(:user) }
  let!(:grandparent) { create(:group) }
  let!(:parent) { create(:group, parent: grandparent) }
  let!(:child) { create(:group, parent: parent) }
  let!(:project_1) { create(:project, namespace: parent) }

  let!(:grandparent_group_label) { create(:group_label, group: grandparent, title: 'Label_1') }
  let!(:parent_group_label) { create(:group_label, group: parent, title: 'Label_2') }
  let!(:child_group_label) { create(:group_label, group: child, title: 'Label_3') }
  let!(:project_label_1) { create(:label, project: project_1, title: 'Label_4') }

  before do
    grandparent.add_owner(user)

    sign_in(user)
  end

  shared_examples 'assigning labels from sidebar' do
    it 'can assign all ancestors labels', :quarantine do
      [grandparent_group_label, parent_group_label, project_label_1].each do |label|
        page.within('.block.labels') do
          find('.edit-link').click
        end

        wait_for_requests

        find('a.label-item', text: label.title).click
        find('.dropdown-menu-close-icon').click

        wait_for_requests

        expect(page).to have_selector('.badge', text: label.title)
      end
    end

    it 'does not find child group labels on dropdown' do
      page.within('.block.labels') do
        find('.edit-link').click
      end

      wait_for_requests

      expect(page).not_to have_selector('.badge', text: child_group_label.title)
    end
  end

  shared_examples 'filtering by ancestor labels for projects' do |board = false|
    it 'filters by ancestor labels' do
      [grandparent_group_label, parent_group_label, project_label_1].each do |label|
        select_label_on_dropdown(label.title)

        wait_for_requests

        if board
          expect(page).to have_selector('.board-card-title') do |card|
            expect(card).to have_selector('a', text: labeled_issue.title)
          end
        else
          expect_issues_list_count(1)
          expect(page).to have_selector('span.issue-title-text', text: labeled_issue.title)
        end
      end
    end

    it 'does not filter by descendant group labels' do
      filtered_search.set("label=")

      wait_for_requests

      expect(page).not_to have_selector('.btn-link', text: child_group_label.title)
    end
  end

  shared_examples 'filtering by ancestor labels for groups' do |board = false|
    let(:project_2) { create(:project, namespace: parent) }
    let!(:project_label_2) { create(:label, project: project_2, title: 'Label_4') }

    let(:project_3) { create(:project, namespace: child) }
    let!(:group_label_3) { create(:group_label, group: child, title: 'Label_5') }
    let!(:project_label_3) { create(:label, project: project_3, title: 'Label_6') }

    let!(:labeled_issue_2) { create(:labeled_issue, project: project_2, labels: [grandparent_group_label, parent_group_label, project_label_2]) }
    let!(:labeled_issue_3) { create(:labeled_issue, project: project_3, labels: [grandparent_group_label, parent_group_label, group_label_3]) }

    let!(:issue_2) { create(:issue, project: project_2) }

    it 'filters by ancestors and current group labels' do
      [grandparent_group_label, parent_group_label].each do |label|
        select_label_on_dropdown(label.title)

        wait_for_requests

        if board
          expect(page).to have_selector('.board-card-title') do |card|
            expect(card).to have_selector('a', text: labeled_issue.title)
          end

          expect(page).to have_selector('.board-card-title') do |card|
            expect(card).to have_selector('a', text: labeled_issue_2.title)
          end
        else
          expect_issues_list_count(3)
          expect(page).to have_selector('span.issue-title-text', text: labeled_issue.title)
          expect(page).to have_selector('span.issue-title-text', text: labeled_issue_2.title)
          expect(page).to have_selector('span.issue-title-text', text: labeled_issue_3.title)
        end
      end
    end

    it 'filters by descendant group labels' do
      wait_for_requests

      select_label_on_dropdown(group_label_3.title)

      if board
        expect(page).to have_selector('.board-card-title') do |card|
          expect(card).not_to have_selector('a', text: labeled_issue_2.title)
        end

        expect(page).to have_selector('.board-card-title') do |card|
          expect(card).to have_selector('a', text: labeled_issue_3.title)
        end
      else
        expect_issues_list_count(1)
        expect(page).to have_selector('span.issue-title-text', text: labeled_issue_3.title)
      end
    end

    it 'does not filter by descendant group project labels' do
      filtered_search.set("label=")

      wait_for_requests

      expect(page).not_to have_selector('.btn-link', text: project_label_3.title)
    end
  end

  context 'when creating new issuable' do
    before do
      visit new_project_issue_path(project_1)
    end

    it 'is able to assign ancestor group labels' do
      fill_in 'issue_title', with: 'new created issue'
      fill_in 'issue_description', with: 'new issue description'

      find(".js-label-select").click
      wait_for_requests

      find('a.label-item', text: grandparent_group_label.title).click
      find('a.label-item', text: parent_group_label.title).click
      find('a.label-item', text: project_label_1.title).click

      find('.btn-success').click

      expect(page.find('.issue-details h2.title')).to have_content('new created issue')
      expect(page).to have_selector('span.gl-label-text', text: grandparent_group_label.title)
      expect(page).to have_selector('span.gl-label-text', text: parent_group_label.title)
      expect(page).to have_selector('span.gl-label-text', text: project_label_1.title)
    end
  end

  context 'issuable sidebar' do
    let!(:issue) { create(:issue, project: project_1) }

    context 'on issue sidebar' do
      before do
        project_1.add_developer(user)

        visit project_issue_path(project_1, issue)
      end

      it_behaves_like 'assigning labels from sidebar'
    end

    context 'on project board issue sidebar' do
      let(:board) { create(:board, project: project_1) }

      before do
        project_1.add_developer(user)

        visit project_board_path(project_1, board)

        wait_for_requests

        find('.board-card').click
      end

      it_behaves_like 'assigning labels from sidebar'
    end

    context 'on group board issue sidebar' do
      let(:board) { create(:board, group: parent) }

      before do
        parent.add_developer(user)

        visit group_board_path(parent, board)

        wait_for_requests

        find('.board-card').click
      end

      it_behaves_like 'assigning labels from sidebar'
    end
  end

  context 'issuable filtering' do
    let!(:labeled_issue) { create(:labeled_issue, project: project_1, labels: [grandparent_group_label, parent_group_label, project_label_1]) }
    let!(:issue) { create(:issue, project: project_1) }

    context 'on project issuable list' do
      before do
        project_1.add_developer(user)

        visit project_issues_path(project_1)
      end

      it_behaves_like 'filtering by ancestor labels for projects'

      it 'does not filter by descendant group labels' do
        filtered_search.set("label=")

        wait_for_requests

        expect(page).not_to have_selector('.btn-link', text: child_group_label.title)
      end
    end

    context 'on group issuable list' do
      before do
        visit issues_group_path(parent)
      end

      it_behaves_like 'filtering by ancestor labels for groups'
    end

    context 'on project boards filter' do
      let(:board) { create(:board, project: project_1) }

      before do
        project_1.add_developer(user)

        visit project_board_path(project_1, board)
      end

      it_behaves_like 'filtering by ancestor labels for projects', true
    end

    context 'on group boards filter' do
      let(:board) { create(:board, group: parent) }

      before do
        parent.add_developer(user)

        visit group_board_path(parent, board)
      end

      it_behaves_like 'filtering by ancestor labels for groups', true
    end
  end

  context 'creating boards lists' do
    context 'on project boards' do
      let(:board) { create(:board, project: project_1) }

      before do
        project_1.add_developer(user)
        visit project_board_path(project_1, board)
        find('.js-new-board-list').click
        wait_for_requests
      end

      it 'creates lists from all ancestor labels' do
        [grandparent_group_label, parent_group_label, project_label_1].each do |label|
          find('a', text: label.title).click
        end

        wait_for_requests

        expect(page).to have_selector('.board-title-text', text: grandparent_group_label.title)
        expect(page).to have_selector('.board-title-text', text: parent_group_label.title)
        expect(page).to have_selector('.board-title-text', text: project_label_1.title)
      end
    end

    context 'on group boards' do
      let(:board) { create(:board, group: parent) }

      before do
        parent.add_developer(user)
        visit group_board_path(parent, board)
        find('.js-new-board-list').click
        wait_for_requests
      end

      it 'creates lists from all ancestor group labels' do
        [grandparent_group_label, parent_group_label].each do |label|
          find('a', text: label.title).click
        end

        wait_for_requests

        expect(page).to have_selector('.board-title-text', text: grandparent_group_label.title)
        expect(page).to have_selector('.board-title-text', text: parent_group_label.title)
      end

      it 'does not create lists from descendant groups' do
        expect(page).not_to have_selector('a', text: child_group_label.title)
      end
    end
  end
end