Skip to content

Commit

Permalink
test_core: Add tests for show_typing_notification
Browse files Browse the repository at this point in the history
Add diffrernt cases of footer notification.Earlier
just one test was presnt as not much scenarios were
possible.The test now has it's own user_dict which is
used to extract name for footer notifcation out of emails
present in active_conversation_info.
  • Loading branch information
Subhasish-Behera committed Apr 14, 2023
1 parent c40149d commit 1c6a648
Showing 1 changed file with 110 additions and 30 deletions.
140 changes: 110 additions & 30 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,18 @@ def test_maximum_popup_dimensions(
[
case({"[email protected]"}, id="in_pm_narrow_with_sender_typing:start"),
case(set(), id="in_pm_narrow_with_sender_typing:stop"),
case(
{"[email protected]", "[email protected]"},
id="in_group_pm_narrow_1_member_active",
),
case(
{"[email protected]", "[email protected]"},
id="in_group_pm_where_3_members_active",
),
case(
{"[email protected]", "[email protected]", "[email protected]"},
id="in_group_pm_where_4_members_active",
),
],
)
def test_show_typing_notification(
Expand All @@ -568,7 +580,16 @@ def test_show_typing_notification(
setattr(
controller.model,
USER_DICT,
{"[email protected]": {"full_name": "hamlet"}},
{
"[email protected]": {"full_name": "hamlet"},
"[email protected]": {"full_name": "iago"},
"[email protected]": {"full_name": "verona"},
"[email protected]": {"full_name": "fan"},
},
)
length = len(active_conversation_info)
active_conversation_info = ", ".join(
controller.model.user_dict[x]["full_name"] for x in active_conversation_info
)

def mock_typing() -> None:
Expand All @@ -578,35 +599,94 @@ def mock_typing() -> None:
Thread(controller.show_typing_notification()).start()

if active_conversation_info:
set_footer_text.assert_has_calls(
[
mocker.call(
[
("footer_contrast", "hamlet "),
("footer", " is typing"),
]
),
mocker.call(
[
("footer_contrast", "hamlet "),
("footer", " is typing."),
]
),
mocker.call(
[
("footer_contrast", "hamlet "),
("footer", " is typing.."),
]
),
mocker.call(
[
("footer_contrast", "hamlet "),
("footer", " is typing..."),
]
),
]
)
set_footer_text.assert_called_with()
if length == 1:
set_footer_text.assert_has_calls(
[
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " is typing"),
]
),
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " is typing."),
]
),
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " is typing.."),
]
),
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " is typing..."),
]
),
]
)
elif length < 4:
set_footer_text.assert_has_calls(
[
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " are typing"),
]
),
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " are typing."),
]
),
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " are typing.."),
]
),
mocker.call(
[
("footer_contrast", f"{active_conversation_info} "),
("footer", " are typing..."),
]
),
]
)
else:
set_footer_text.assert_has_calls(
[
mocker.call(
[
("footer_contrast", "Multiple people "),
("footer", " are typing"),
]
),
mocker.call(
[
("footer_contrast", "Multiple people "),
("footer", " are typing."),
]
),
mocker.call(
[
("footer_contrast", "Multiple people "),
("footer", " are typing.."),
]
),
mocker.call(
[
("footer_contrast", "Multiple people "),
("footer", " is typing..."),
]
),
]
)
set_footer_text.assert_called_with()
else:
set_footer_text.assert_called_once_with()
assert controller.is_typing_notification_in_progress is False
Expand Down

0 comments on commit 1c6a648

Please sign in to comment.