diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-03 11:38:33 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 12:57:00 +0100 |
commit | 7639dcb4995b13c2756f9d59e0a67e22cba57a38 (patch) | |
tree | f38f36bfab6ab13fb89497fff1fb5e8d29e787ac /tests | |
parent | 15cabf8ba1b9daa7e28475ea46cc5a8fd478e174 (diff) | |
download | wee-slack-7639dcb4995b13c2756f9d59e0a67e22cba57a38.tar.gz |
Correctly show reactions with more than 50 users in v3.0.0
If a reaction has more than 50 users, the list of users will be cropped
to just 50 users. This made the counts wrong since we used the number of
users rather than the count property. Fix it by using the count property
instead and adding "and others" to the list of users if
show_reaction_nicks is enabled (the same as the Slack client shows when
you hover over the reaction).
This is the same fix as in commit 6b388cd9, but for version 3.0.0.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 17 | ||||
-rw-r--r-- | tests/test_render_reactions.py | 73 |
2 files changed, 88 insertions, 2 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 981faab..cda1833 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -148,13 +148,20 @@ color_reset = "<[color:reset]>" workspace_id = "T0FC8BFQR" -with open("mock_data/slack_users_info_person.json") as f: +with open("mock_data/slack_users_info_person_1.json") as f: user_test1_info_response: SlackUserInfoSuccessResponse[SlackUserInfo] = json.loads( f.read() ) user_test1_info = user_test1_info_response["user"] user_test1_id = user_test1_info["id"] +with open("mock_data/slack_users_info_person_2.json") as f: + user_test2_info_response: SlackUserInfoSuccessResponse[SlackUserInfo] = json.loads( + f.read() + ) + user_test2_info = user_test2_info_response["user"] + user_test2_id = user_test2_info["id"] + with open("mock_data/slack_conversations_info_channel_public.json") as f: channel_public_info_response: SlackConversationsInfoSuccessResponse[ SlackConversationsInfo @@ -172,9 +179,15 @@ def workspace(): user_test1 = SlackUser(w, user_test1_info) user_test1_future = Future[SlackUser]() user_test1_future.set_result(user_test1) - w.my_user = user_test1 w.users[user_test1_id] = user_test1_future + user_test2 = SlackUser(w, user_test2_info) + user_test2_future = Future[SlackUser]() + user_test2_future.set_result(user_test2) + w.users[user_test2_id] = user_test2_future + + w.my_user = user_test1 + channel_public_future = Future[SlackConversation]() w.conversations[channel_public_id] = channel_public_future channel_public = SlackConversation(w, channel_public_info) diff --git a/tests/test_render_reactions.py b/tests/test_render_reactions.py new file mode 100644 index 0000000..dad9696 --- /dev/null +++ b/tests/test_render_reactions.py @@ -0,0 +1,73 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, List + +import pytest + +from slack.shared import shared +from slack.slack_message import SlackMessage +from tests.conftest import ( + color_reset, + user_test1_id, + user_test2_id, +) + +if TYPE_CHECKING: + from slack_api.slack_conversations_history import SlackMessageReaction + from typing_extensions import TypedDict +else: + TypedDict = object + + +class Case(TypedDict): + reactions: List[SlackMessageReaction] + rendered: str + display_reaction_nicks: bool + + +color_reaction_suffix = "<[color:<[config_color:reaction_suffix]>]>" +color_reaction_self_suffix = "<[color:<[config_color:reaction_self_suffix]>]>" + +cases: List[Case] = [ + { + "reactions": [{"name": "custom", "users": [user_test2_id], "count": 1}], + "rendered": f" {color_reaction_suffix}[:custom:1]{color_reset}", + "display_reaction_nicks": False, + }, + { + "reactions": [{"name": "custom", "users": [user_test1_id], "count": 1}], + "rendered": f" {color_reaction_suffix}[{color_reaction_self_suffix}:custom:1{color_reaction_suffix}]{color_reset}", + "display_reaction_nicks": False, + }, + { + "reactions": [{"name": "custom", "users": [user_test2_id], "count": 1}], + "rendered": f" {color_reaction_suffix}[:custom:1(Test_2)]{color_reset}", + "display_reaction_nicks": True, + }, + { + "reactions": [{"name": "custom", "users": [user_test1_id], "count": 1}], + "rendered": f" {color_reaction_suffix}[{color_reaction_self_suffix}:custom:1(Test_1){color_reaction_suffix}]{color_reset}", + "display_reaction_nicks": True, + }, + { + "reactions": [{"name": "custom", "users": [user_test2_id], "count": 2}], + "rendered": f" {color_reaction_suffix}[:custom:2]{color_reset}", + "display_reaction_nicks": False, + }, + { + "reactions": [{"name": "custom", "users": [user_test2_id], "count": 2}], + "rendered": f" {color_reaction_suffix}[:custom:2(Test_2, and others)]{color_reset}", + "display_reaction_nicks": True, + }, +] + + +@pytest.mark.parametrize("case", cases) +def test_create_reactions_string(case: Case, message1_in_channel_public: SlackMessage): + shared.config.look.display_reaction_nicks.value = case["display_reaction_nicks"] + message1_in_channel_public._message_json["reactions"] = case["reactions"] # pyright: ignore [reportPrivateUsage] + + coroutine = message1_in_channel_public._create_reactions_string() # pyright: ignore [reportPrivateUsage] + with pytest.raises(StopIteration) as excinfo: + coroutine.send(None) + assert excinfo.value.value == case["rendered"] |