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 Apr 14, 2023
1 parent 1c6a648 commit 06cb1ec
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(),
{"[email protected]"},
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(),
{"[email protected]"},
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",
"[email protected]",
"[email protected]",
"[email protected]",
]
],
{
"op": "start",
"sender": {"user_id": 4, "email": "[email protected]"},
"recipients": [
{"user_id": 4, "email": "[email protected]"},
{"user_id": 5, "email": "[email protected]"},
],
"id": 0,
},
False,
set(),
{"[email protected]"},
True,
id="in_group_pm_narrow_with_sender_typing:start",
),
case(
[
[
"pm_with",
"[email protected]",
"[email protected]",
"[email protected]",
]
],
{
"op": "stop",
"sender": {"user_id": 4, "email": "[email protected]"},
"recipients": [
{"user_id": 4, "email": "[email protected]"},
{"user_id": 5, "email": "[email protected]"},
],
"id": 0,
},
True,
{"[email protected]"},
{},
False,
id="in_group_pm_narrow,sender_typing:stop"
"_while animation is in progress",
),
case(
[["pm_with", "[email protected], [email protected]"]],
{
"op": "start",
"sender": {"user_id": 6, "email": "[email protected]"},
"recipients": [
{"user_id": 4, "email": "[email protected]"},
{"user_id": 6, "email": "[email protected]"},
],
"id": 0,
},
True,
{"[email protected]"},
{"[email protected]", "[email protected]"},
False,
id="in_group_pm_narrow,second_sender_typing:start"
"_while animation in progress",
),
case(
[["pm_with", "[email protected], [email protected]"]],
{
"op": "stop",
"sender": {"user_id": 6, "email": "[email protected]"},
"recipients": [
{"user_id": 4, "email": "[email protected]"},
{"user_id": 6, "email": "[email protected]"},
],
"id": 0,
},
True,
{"[email protected]", "[email protected]"},
{"[email protected]"},
False,
id="in_group_pm_narrow,second_sender_typing:stop"
"_while animation in progress",
),
case(
[["pm_with", "[email protected], [email protected],[email protected]"]],
{
"op": "start",
"sender": {"user_id": 5, "email": "[email protected]"},
"recipients": [
{"user_id": 4, "email": "[email protected]"},
{"user_id": 6, "email": "[email protected]"},
],
"id": 0,
},
True,
{"[email protected]", "[email protected]"},
{"[email protected]", "[email protected]"},
False,
id="in_group_pm_narrow,user_typing:start"
"_while animation in progress",
),
case(
[["pm_with", "[email protected], [email protected],[email protected]"]],
{
"op": "stop",
"sender": {"user_id": 5, "email": "[email protected]"},
"recipients": [
{"user_id": 4, "email": "[email protected]"},
{"user_id": 6, "email": "[email protected]"},
],
"id": 0,
},
True,
{"[email protected]", "[email protected]"},
{"[email protected]", "[email protected]"},
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 = {
"[email protected]": {"full_name": "hamlet", "email": "[email protected]"}
"[email protected]": {"full_name": "hamlet", "email": "[email protected]"},
"[email protected]": {"full_name": "macbeth", "email": "[email protected]"},
"[email protected]": {"full_name": "iag0", "email": "[email protected]"},
"[email protected]": {"full_name": "verona", "email": "[email protected]"},
"[email protected]": {
"full_name": "claudius",
"email": "[email protected]",
},
}
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 06cb1ec

Please sign in to comment.