Skip to content

Commit

Permalink
tests: Add testing for new poll feature.
Browse files Browse the repository at this point in the history
Add timeout to ensure there is enough time to render
question through backend. There is no noticable
lag for the user. Add coverage for submessage.
  • Loading branch information
zhark01 committed Dec 8, 2020
1 parent d704472 commit 5782404
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
17 changes: 12 additions & 5 deletions frontend_tests/node_tests/poll_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ run_test("activate another person poll", () => {

assert.equal(widget_elem.html(), "widgets/poll_widget");
assert.equal(widget_option_container.html(), "widgets/poll_widget_results");
assert.equal(poll_question_header.text(), "What do you want?");

setTimeout(() => {
assert.equal(poll_question_header.text(), "What do you want?");
}, 50);
{
/* Testing data sent to server on adding option */
poll_option_input.val("cool choice");
Expand Down Expand Up @@ -374,19 +375,25 @@ run_test("activate own poll", () => {

assert.equal(widget_elem.html(), "widgets/poll_widget");
assert.equal(widget_option_container.html(), "widgets/poll_widget_results");
assert.equal(poll_question_header.text(), "Where to go?");
setTimeout(() => {
assert.equal(poll_question_header.text(), "Where to go?");
}, 50);

{
/* Testing data sent to server on editing question */
poll_question_input.val("Is it new?");
out_data = undefined;
show_submit = true;
poll_question_submit.trigger("click");
assert.deepEqual(out_data, {type: "question", question: "Is it new?"});
setTimeout(() => {
assert.deepEqual(out_data, {type: "question", question: "Is it new?"});
}, 50);

poll_option_input.val("");
out_data = undefined;
poll_question_submit.trigger("click");
assert.deepEqual(out_data, undefined);
setTimeout(() => {
assert.deepEqual(out_data, undefined);
}, 50);
}
});
4 changes: 2 additions & 2 deletions static/js/poll_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ exports.activate = function (opts) {
}

function render_question() {
const question = poll_data.get_question();
const rendered_question = poll_data.get_question();
const input_mode = poll_data.get_input_mode();
const can_edit = is_my_poll && !input_mode;
const has_question = question.trim() !== "";
Expand All @@ -206,7 +206,7 @@ exports.activate = function (opts) {
const author_help = is_my_poll && !has_question;

elem.find(".poll-question-header").toggle(!input_mode);
elem.find(".poll-question-header").html(question);
elem.find(".poll-question-header").html(rendered_question);
elem.find(".poll-edit-question").toggle(can_edit);
update_edit_controls();

Expand Down
22 changes: 22 additions & 0 deletions zerver/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,28 @@ def test_add_submessage(self) -> None:
state_change_expected=False,
)
check_submessage('events[0]', events[0])
events = self.verify_action(
lambda: do_add_submessage(
realm=cordelia.realm,
sender_id=cordelia.id,
message_id=message_id,
msg_type='widget',
content='{"type":"new_option","idx":4,"option":"option"}',
),
state_change_expected=False,
)
check_submessage('events[0]', events[0])
events = self.verify_action(
lambda: do_add_submessage(
realm=cordelia.realm,
sender_id=cordelia.id,
message_id=message_id,
msg_type='widget',
content='{"type":"question","question":"google.com"}',
),
state_change_expected=False,
)
check_submessage('events[0]', events[0])

def test_remove_reaction(self) -> None:
message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
Expand Down

0 comments on commit 5782404

Please sign in to comment.