-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Polls Widget on ZT. #1551
Open
rsashank
wants to merge
7
commits into
zulip:main
Choose a base branch
from
rsashank:polls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
827ef2c
widget: Add process_poll_widget function.
rsashank af39cee
messages: Implement logic to display polls on ZT.
rsashank 17d3ade
keys: Add SHOW_POLL_VOTES hotkey.
rsashank 3b29642
views: Add PollResultsView class.
rsashank 990118a
core: Add show_poll_vote method to Controller.
rsashank 78fd5df
messages: Add logic to handle the SHOW_POLL_VOTES hotkey.
rsashank 9d75f50
messages: Update poll_question with a default text if empty.
rsashank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,12 @@ | |
import pytest | ||
from pytest import param as case | ||
|
||
from zulipterminal.widget import Submessage, find_widget_type, process_todo_widget | ||
from zulipterminal.widget import ( | ||
Submessage, | ||
find_widget_type, | ||
process_poll_widget, | ||
process_todo_widget, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -343,3 +348,318 @@ def test_process_todo_widget( | |
|
||
assert title == expected_title | ||
assert tasks == expected_tasks | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"submessage, expected_poll_question, expected_options", | ||
[ | ||
case( | ||
[ | ||
{ | ||
"id": 12082, | ||
"message_id": 1957499, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {' | ||
'"question": "Do polls work on ZT?", "options": ["Yes", "No"]}}' | ||
), | ||
}, | ||
{ | ||
"id": 12083, | ||
"message_id": 1957499, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
{ | ||
"id": 12084, | ||
"message_id": 1957499, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":-1}', | ||
}, | ||
{ | ||
"id": 12085, | ||
"message_id": 1957499, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,1","vote":1}', | ||
}, | ||
{ | ||
"id": 12086, | ||
"message_id": 1957499, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
{ | ||
"id": 12087, | ||
"message_id": 1957499, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,1","vote":-1}', | ||
}, | ||
], | ||
"Do polls work on ZT?", | ||
{ | ||
"canned,0": {"option": "Yes", "votes": [27294]}, | ||
"canned,1": {"option": "No", "votes": []}, | ||
}, | ||
id="poll_widget_with_votes", | ||
), | ||
case( | ||
[ | ||
{ | ||
"id": 12089, | ||
"message_id": 1957662, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {"question": "Is ' | ||
'this a poll with options added later?", ' | ||
'"options": ["Yes", "No"]}}' | ||
), | ||
}, | ||
{ | ||
"id": 12090, | ||
"message_id": 1957662, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"new_option","idx":1,"option":"Maybe"}', | ||
}, | ||
{ | ||
"id": 12091, | ||
"message_id": 1957662, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,1","vote":1}', | ||
}, | ||
{ | ||
"id": 12092, | ||
"message_id": 1957662, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,1","vote":-1}', | ||
}, | ||
{ | ||
"id": 12093, | ||
"message_id": 1957662, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"27294,1","vote":1}', | ||
}, | ||
{ | ||
"id": 12094, | ||
"message_id": 1957662, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
], | ||
"Is this a poll with options added later?", | ||
{ | ||
"canned,0": {"option": "Yes", "votes": [27294]}, | ||
"canned,1": {"option": "No", "votes": []}, | ||
"27294,1": {"option": "Maybe", "votes": [27294]}, | ||
}, | ||
id="poll_widget_with_new_option_and_votes", | ||
), | ||
case( | ||
[ | ||
{ | ||
"id": 12095, | ||
"message_id": 1957682, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {"question": ' | ||
'"Let\'s change this question later?", "options": ["Yes"]}}' | ||
), | ||
}, | ||
{ | ||
"id": 12096, | ||
"message_id": 1957682, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
{ | ||
"id": 12097, | ||
"message_id": 1957682, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"new_option","idx":1,"option":"No"}', | ||
}, | ||
{ | ||
"id": 12098, | ||
"message_id": 1957682, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":-1}', | ||
}, | ||
{ | ||
"id": 12099, | ||
"message_id": 1957682, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"question",' | ||
'"question":"Has this question stayed the same?"}', | ||
}, | ||
{ | ||
"id": 12100, | ||
"message_id": 1957682, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"27294,1","vote":1}', | ||
}, | ||
], | ||
"Has this question stayed the same?", | ||
{ | ||
"canned,0": {"option": "Yes", "votes": []}, | ||
"27294,1": {"option": "No", "votes": [27294]}, | ||
}, | ||
id="poll_widget_with_new_question_and_votes", | ||
), | ||
case( | ||
[ | ||
{ | ||
"id": 12101, | ||
"message_id": 1957693, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {"question": "",' | ||
' "options": ["Yes", "No"]}}' | ||
), | ||
} | ||
], | ||
"", | ||
{ | ||
"canned,0": {"option": "Yes", "votes": []}, | ||
"canned,1": {"option": "No", "votes": []}, | ||
}, | ||
id="poll_widget_with_empty_question", | ||
), | ||
case( | ||
[ | ||
{ | ||
"id": 12102, | ||
"message_id": 1957700, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {' | ||
'"question": "Does this poll have options?", "options": []}}' | ||
), | ||
} | ||
], | ||
"Does this poll have options?", | ||
{}, | ||
id="poll_widget_with_empty_options", | ||
), | ||
case( | ||
[ | ||
{ | ||
"id": 12112, | ||
"message_id": 1957722, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {"question": "",' | ||
' "options": []}}' | ||
), | ||
} | ||
], | ||
"", | ||
{}, | ||
id="poll_widget_with_empty_question_and_options", | ||
), | ||
case( | ||
[ | ||
{ | ||
"id": 12103, | ||
"message_id": 1957719, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": ( | ||
'{"widget_type": "poll", "extra_data": {"question": "Does' | ||
' this poll have multiple voters?", "options": ["Yes", "No"]}}' | ||
), | ||
}, | ||
{ | ||
"id": 12104, | ||
"message_id": 1957719, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
{ | ||
"id": 12105, | ||
"message_id": 1957719, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,1","vote":1}', | ||
}, | ||
{ | ||
"id": 12106, | ||
"message_id": 1957719, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":-1}', | ||
}, | ||
{ | ||
"id": 12107, | ||
"message_id": 1957719, | ||
"sender_id": 32159, | ||
"msg_type": "widget", | ||
"content": '{"type":"new_option","idx":1,"option":"Maybe"}', | ||
}, | ||
{ | ||
"id": 12108, | ||
"message_id": 1957719, | ||
"sender_id": 32159, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"32159,1","vote":1}', | ||
}, | ||
{ | ||
"id": 12109, | ||
"message_id": 1957719, | ||
"sender_id": 32159, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
{ | ||
"id": 12110, | ||
"message_id": 1957719, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,1","vote":-1}', | ||
}, | ||
{ | ||
"id": 12111, | ||
"message_id": 1957719, | ||
"sender_id": 27294, | ||
"msg_type": "widget", | ||
"content": '{"type":"vote","key":"canned,0","vote":1}', | ||
}, | ||
], | ||
"Does this poll have multiple voters?", | ||
{ | ||
"canned,0": {"option": "Yes", "votes": [32159, 27294]}, | ||
"canned,1": {"option": "No", "votes": []}, | ||
"32159,1": {"option": "Maybe", "votes": [32159]}, | ||
}, | ||
id="poll_widget_with_multiple_voters", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This test is known to be a poll_widget already, as with other PR. |
||
), | ||
], | ||
) | ||
def test_process_poll_widget( | ||
submessage: List[Submessage], | ||
expected_poll_question: str, | ||
expected_options: Dict[str, Dict[str, Union[str, List[str]]]], | ||
) -> None: | ||
poll_question, options = process_poll_widget(submessage) | ||
|
||
assert poll_question == expected_poll_question | ||
assert options == expected_options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: plural, as in other PR.