@@ -228,16 +228,18 @@ def test_keypress_USER_INFO(
228
228
229
229
class TestEmojiButton :
230
230
@pytest .mark .parametrize (
231
- "emoji_unit, to_vary_in_message" ,
231
+ "emoji_unit, to_vary_in_message, count " ,
232
232
[
233
233
case (
234
234
("working_on_it" , "1f6e0" , ["hammer_and_wrench" , "tools" ]),
235
235
{"reactions" : [{"emoji_name" : "thumbs_up" , "user" : [{"id" : 232 }]}]},
236
+ 0 ,
236
237
id = "emoji_button_with_no_reaction" ,
237
238
),
238
239
case (
239
240
("+1" , "1f44d" , ["thumbs_up" , "like" ]),
240
241
{"reactions" : [{"emoji_name" : "+1" , "user" : [{"id" : 10 }]}]},
242
+ 1 ,
241
243
id = "emoji_button_with_a_reaction" ,
242
244
),
243
245
],
@@ -248,9 +250,11 @@ def test_init_calls_top_button(
248
250
emoji_unit : Tuple [str , str , List [str ]],
249
251
to_vary_in_message : Dict [str , Any ],
250
252
message_fixture : Message ,
253
+ count : int ,
251
254
) -> None :
252
255
controller = mocker .Mock ()
253
256
controller .model .has_user_reacted_to_message = mocker .Mock (return_value = False )
257
+ update_widget = mocker .patch (MODULE + ".EmojiButton.update_widget" )
254
258
top_button = mocker .patch (MODULE + ".TopButton.__init__" )
255
259
caption = ", " .join ([emoji_unit [0 ], * emoji_unit [2 ]])
256
260
message_fixture ["reactions" ] = to_vary_in_message ["reactions" ]
@@ -259,6 +263,7 @@ def test_init_calls_top_button(
259
263
controller = controller ,
260
264
emoji_unit = emoji_unit ,
261
265
message = message_fixture ,
266
+ reaction_count = count ,
262
267
is_selected = lambda * _ : False ,
263
268
toggle_selection = lambda * _ : None ,
264
269
)
@@ -270,15 +275,16 @@ def test_init_calls_top_button(
270
275
show_function = emoji_button .update_emoji_button ,
271
276
)
272
277
assert emoji_button .emoji_name == emoji_unit [0 ]
278
+ assert emoji_button .reaction_count == count
273
279
274
280
@pytest .mark .parametrize ("key" , keys_for_command ("ENTER" ))
275
281
@pytest .mark .parametrize (
276
- "emoji, has_user_reacted, is_selected_final" ,
282
+ "emoji, has_user_reacted, is_selected_final, expected_reaction_count " ,
277
283
[
278
- case (("smile" , "1f642" , []), True , False , id = "reacted_unselected_emoji" ),
279
- case (("smile" , "1f642" , []), True , True , id = "reacted_selected_emoji" ),
280
- case (("+1" , "1f44d" , []), False , False , id = "unreacted_unselected_emoji" ),
281
- case (("+1" , "1f44d" , []), False , True , id = "unreacted_selected_emoji" ),
284
+ case (("smile" , "1f642" , []), True , False , 2 , id = "reacted_unselected_emoji" ),
285
+ case (("smile" , "1f642" , []), True , True , 0 , id = "reacted_selected_emoji" ),
286
+ case (("+1" , "1f44d" , []), False , False , 0 , id = "unreacted_unselected_emoji" ),
287
+ case (("+1" , "1f44d" , []), False , True , 2 , id = "unreacted_selected_emoji" ),
282
288
],
283
289
)
284
290
def test_keypress_emoji_button (
@@ -290,6 +296,7 @@ def test_keypress_emoji_button(
290
296
is_selected_final : bool ,
291
297
widget_size : Callable [[Widget ], urwid_Size ],
292
298
message_fixture : Message ,
299
+ expected_reaction_count : int ,
293
300
) -> None :
294
301
controller = mocker .Mock ()
295
302
controller .model .has_user_reacted_to_message = mocker .Mock (
@@ -307,15 +314,23 @@ def test_keypress_emoji_button(
307
314
controller = controller ,
308
315
emoji_unit = emoji ,
309
316
message = message_fixture ,
317
+ reaction_count = 1 ,
310
318
is_selected = lambda * _ : is_selected_final ,
311
319
toggle_selection = lambda * _ : None ,
312
320
)
313
321
size = widget_size (emoji_button )
314
322
315
323
emoji_button .keypress (size , key )
316
324
317
- suffix_text = f"{ CHECK_MARK } " if has_user_reacted != is_selected_final else ""
325
+ reaction_count = emoji_button .reaction_count
326
+ reaction_count_text = "" if reaction_count == 0 else f"{ reaction_count } "
327
+ suffix_text = (
328
+ f"{ CHECK_MARK } " + reaction_count_text
329
+ if has_user_reacted != is_selected_final
330
+ else reaction_count_text
331
+ )
318
332
assert emoji_button .emoji_name == emoji [0 ]
333
+ assert reaction_count == expected_reaction_count
319
334
assert emoji_button .button_suffix .get_text ()[0 ].strip () == suffix_text
320
335
321
336
0 commit comments