220
220
end
221
221
end
222
222
223
+ # This context has jsut one example in each contexts in order to improve spec performance.
224
+ context 'labels' do
225
+ let! ( :backend ) { create ( :label , project : project , title : 'backend' ) }
226
+ let! ( :bug ) { create ( :label , project : project , title : 'bug' ) }
227
+ let! ( :feature_proposal ) { create ( :label , project : project , title : 'feature proposal' ) }
228
+
229
+ context 'when no labels are assigned' do
230
+ it 'shows labels' do
231
+ note = find ( '#note-body' )
232
+
233
+ # It should show all the labels on "~".
234
+ type ( note , '~' )
235
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
236
+
237
+ # It should show all the labels on "/label ~".
238
+ type ( note , '/label ~' )
239
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
240
+
241
+ # It should show all the labels on "/relabel ~".
242
+ type ( note , '/relabel ~' )
243
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
244
+
245
+ # It should show no labels on "/unlabel ~".
246
+ type ( note , '/unlabel ~' )
247
+ expect_labels ( not_shown : [ backend , bug , feature_proposal ] )
248
+ end
249
+ end
250
+
251
+ context 'when some labels are assigned' do
252
+ before do
253
+ issue . labels << [ backend ]
254
+ end
255
+
256
+ it 'shows labels' do
257
+ note = find ( '#note-body' )
258
+
259
+ # It should show all the labels on "~".
260
+ type ( note , '~' )
261
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
262
+
263
+ # It should show only unset labels on "/label ~".
264
+ type ( note , '/label ~' )
265
+ expect_labels ( shown : [ bug , feature_proposal ] , not_shown : [ backend ] )
266
+
267
+ # It should show all the labels on "/relabel ~".
268
+ type ( note , '/relabel ~' )
269
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
270
+
271
+ # It should show only set labels on "/unlabel ~".
272
+ type ( note , '/unlabel ~' )
273
+ expect_labels ( shown : [ backend ] , not_shown : [ bug , feature_proposal ] )
274
+ end
275
+ end
276
+
277
+ context 'when all labels are assigned' do
278
+ before do
279
+ issue . labels << [ backend , bug , feature_proposal ]
280
+ end
281
+
282
+ it 'shows labels' do
283
+ note = find ( '#note-body' )
284
+
285
+ # It should show all the labels on "~".
286
+ type ( note , '~' )
287
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
288
+
289
+ # It should show no labels on "/label ~".
290
+ type ( note , '/label ~' )
291
+ expect_labels ( not_shown : [ backend , bug , feature_proposal ] )
292
+
293
+ # It should show all the labels on "/relabel ~".
294
+ type ( note , '/relabel ~' )
295
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
296
+
297
+ # It should show all the labels on "/unlabel ~".
298
+ type ( note , '/unlabel ~' )
299
+ expect_labels ( shown : [ backend , bug , feature_proposal ] )
300
+ end
301
+ end
302
+ end
303
+
304
+ private
305
+
223
306
def expect_to_wrap ( should_wrap , item , note , value )
224
307
expect ( item ) . to have_content ( value )
225
308
expect ( item ) . not_to have_content ( "\" #{ value } \" " )
@@ -232,4 +315,27 @@ def expect_to_wrap(should_wrap, item, note, value)
232
315
expect ( note . value ) . not_to include ( "\" #{ value } \" " )
233
316
end
234
317
end
318
+
319
+ def expect_labels ( shown : nil , not_shown : nil )
320
+ page . within ( '.atwho-container' ) do
321
+ if shown
322
+ expect ( page ) . to have_selector ( '.atwho-view li' , count : shown . size )
323
+ shown . each { |label | expect ( page ) . to have_content ( label . title ) }
324
+ end
325
+
326
+ if not_shown
327
+ expect ( page ) . not_to have_selector ( '.atwho-view li' ) unless shown
328
+ not_shown . each { |label | expect ( page ) . not_to have_content ( label . title ) }
329
+ end
330
+ end
331
+ end
332
+
333
+ # `note` is a textarea where the given text should be typed.
334
+ # We don't want to find it each time this function gets called.
335
+ def type ( note , text )
336
+ page . within ( '.timeline-content-form' ) do
337
+ note . set ( '' )
338
+ note . native . send_keys ( text )
339
+ end
340
+ end
235
341
end
0 commit comments