Skip to content

Commit

Permalink
test_model: Added tests for _handle_typing_event.
Browse files Browse the repository at this point in the history
Added a new parameter of current active_conversation_info.
Constructed a user_dict get full_names out of emails present
in active_converstation_info.
  • Loading branch information
Subhasish-Behera committed May 17, 2023
1 parent a72e357 commit 0ba3cf0
Showing 1 changed file with 140 additions and 2 deletions.
142 changes: 140 additions & 2 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,7 @@ def test_toggle_stream_visual_notifications(
@pytest.mark.parametrize(
(
"narrow, event, is_notification_in_progress,"
"current_active_conversation_info,"
"expected_active_conversation_info, expected_show_typing_notification,"
),
[
Expand All @@ -2899,6 +2900,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{},
False,
id="not_in_pm_narrow",
Expand All @@ -2915,6 +2917,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{},
False,
id="not_in_pm_narrow_with_sender",
Expand All @@ -2931,6 +2934,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{"hamlet@zulip.com"},
True,
id="in_pm_narrow_with_sender_typing:start",
Expand All @@ -2947,6 +2951,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
True,
set(),
{"hamlet@zulip.com"},
False,
id="in_pm_narrow_with_sender_typing:start_while_animation_in_progress",
Expand All @@ -2963,6 +2968,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
True,
set(),
{},
False,
id="in_pm_narrow_with_sender_typing:stop",
Expand All @@ -2979,6 +2985,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{},
False,
id="in_pm_narrow_with_other_myself_typing:start",
Expand All @@ -2995,6 +3002,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{},
False,
id="in_pm_narrow_with_other_myself_typing:stop",
Expand All @@ -3008,6 +3016,7 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{},
False,
id="in_pm_narrow_with_oneself:start",
Expand All @@ -3021,10 +3030,131 @@ def test_toggle_stream_visual_notifications(
"id": 0,
},
False,
set(),
{},
False,
id="in_pm_narrow_with_oneself:stop",
),
case(
[
[
"pm_with",
"hamlet@zulip.com",
"claudius@zulip.com",
"iago@zulip.com",
]
],
{
"op": "start",
"sender": {"user_id": 4, "email": "hamlet@zulip.com"},
"recipients": [
{"user_id": 4, "email": "hamlet@zulip.com"},
{"user_id": 5, "email": "iago@zulip.com"},
],
"id": 0,
},
False,
set(),
{"hamlet@zulip.com"},
True,
id="in_group_pm_narrow_with_sender_typing:start",
),
case(
[
[
"pm_with",
"hamlet@zulip.com",
"claudius@zulip.com",
"iago@zulip.com",
]
],
{
"op": "stop",
"sender": {"user_id": 4, "email": "hamlet@zulip.com"},
"recipients": [
{"user_id": 4, "email": "hamlet@zulip.com"},
{"user_id": 5, "email": "iago@zulip.com"},
],
"id": 0,
},
True,
{"hamlet@zulip.com"},
{},
False,
id="in_group_pm_narrow,sender_typing:stop"
"_while animation is in progress",
),
case(
[["pm_with", "hamlet@zulip.com, claudius@zulip.com"]],
{
"op": "start",
"sender": {"user_id": 6, "email": "claudius@zulip.com"},
"recipients": [
{"user_id": 4, "email": "hamlet@zulip.com"},
{"user_id": 6, "email": "claudius@zulip.com"},
],
"id": 0,
},
True,
{"hamlet@zulip.com"},
{"claudius@zulip.com", "hamlet@zulip.com"},
False,
id="in_group_pm_narrow,second_sender_typing:start"
"_while animation in progress",
),
case(
[["pm_with", "hamlet@zulip.com, claudius@zulip.com"]],
{
"op": "stop",
"sender": {"user_id": 6, "email": "claudius@zulip.com"},
"recipients": [
{"user_id": 4, "email": "hamlet@zulip.com"},
{"user_id": 6, "email": "claudius@zulip.com"},
],
"id": 0,
},
True,
{"claudius@zulip.com", "hamlet@zulip.com"},
{"hamlet@zulip.com"},
False,
id="in_group_pm_narrow,second_sender_typing:stop"
"_while animation in progress",
),
case(
[["pm_with", "hamlet@zulip.com, claudius@zulip.com,iago@zulip.com"]],
{
"op": "start",
"sender": {"user_id": 5, "email": "iago@zulip.com"},
"recipients": [
{"user_id": 4, "email": "hamlet@zulip.com"},
{"user_id": 6, "email": "claudius@zulip.com"},
],
"id": 0,
},
True,
{"claudius@zulip.com", "hamlet@zulip.com"},
{"claudius@zulip.com", "hamlet@zulip.com"},
False,
id="in_group_pm_narrow,user_typing:start"
"_while animation in progress",
),
case(
[["pm_with", "hamlet@zulip.com, claudius@zulip.com,iago@zulip.com"]],
{
"op": "stop",
"sender": {"user_id": 5, "email": "iago@zulip.com"},
"recipients": [
{"user_id": 4, "email": "hamlet@zulip.com"},
{"user_id": 6, "email": "claudius@zulip.com"},
],
"id": 0,
},
True,
{"claudius@zulip.com", "hamlet@zulip.com"},
{"claudius@zulip.com", "hamlet@zulip.com"},
False,
id="in_group_pm_narrow,usertyping:stop_" "while animation in progress",
),
],
)
def test__handle_typing_event(
Expand All @@ -3034,17 +3164,25 @@ def test__handle_typing_event(
narrow,
event,
is_notification_in_progress,
current_active_conversation_info,
expected_active_conversation_info,
expected_show_typing_notification,
):
event["type"] = "typing"

model.narrow = narrow
model.user_dict = {
"hamlet@zulip.com": {"full_name": "hamlet", "email": "hamlet@zulip.com"}
"hamlet@zulip.com": {"full_name": "hamlet", "email": "hamlet@zulip.com"},
"macbeth@zulip.com": {"full_name": "macbeth", "email": "macbeth@zulip.com"},
"iago@zulip.com": {"full_name": "iag0", "email": "iago@zulip.com"},
"verona@zulip.com": {"full_name": "verona", "email": "verona@zulip.com"},
"claudius@zulip.com": {
"full_name": "claudius",
"email": "claudius@zulip.com",
},
}
model.user_id = 5 # Iago's user_id
model.controller.active_conversation_info = set()
model.controller.active_conversation_info = current_active_conversation_info
model.controller.is_typing_notification_in_progress = (
is_notification_in_progress
)
Expand Down

0 comments on commit 0ba3cf0

Please sign in to comment.