Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

node tests: Simplify poll_widget test.

Steve Howellc1b499ea9e85
diff --git a/frontend_tests/node_tests/poll_widget.js b/frontend_tests/node_tests/poll_widget.js
index d497f6b366e..79118cc8e96 100644
--- a/frontend_tests/node_tests/poll_widget.js
+++ b/frontend_tests/node_tests/poll_widget.js
@@ -194,36 +194,16 @@ run_test("activate another person poll", () => {
set_widget_find_result("button.poll-question-remove");
set_widget_find_result("input.poll-question");
- poll_question_header.toggle = (show) => {
- assert(show);
- };
-
- poll_edit_question.toggle = (show) => {
- assert(!show);
- };
-
- const show_submit = false;
- poll_question_submit.toggle = (show) => {
- assert.equal(show, show_submit);
- };
-
- poll_question_container.toggle = (show) => {
- assert(!show);
- };
-
- poll_option_container.toggle = (show) => {
- assert.equal(show, true);
- };
+ poll_widget.activate(opts);
- poll_please_wait.toggle = (show) => {
- assert.equal(show, false);
- };
+ assert(poll_option_container.visible());
+ assert(poll_question_header.visible());
- poll_author_help.toggle = (show) => {
- assert(!show);
- };
-
- poll_widget.activate(opts);
+ assert(!poll_question_container.visible());
+ assert(!poll_question_submit.visible());
+ assert(!poll_edit_question.visible());
+ assert(!poll_please_wait.visible());
+ assert(!poll_author_help.visible());
assert.equal(widget_elem.html(), "widgets/poll_widget");
assert.equal(widget_option_container.html(), "widgets/poll_widget_results");
@@ -337,37 +317,20 @@ run_test("activate own poll", () => {
set_widget_find_result("button.poll-question-remove");
- poll_question_header.toggle = (show) => {
- assert(show);
- };
-
- poll_edit_question.toggle = (show) => {
- assert(show);
- };
-
- let show_submit = false;
- poll_question_submit.toggle = (show) => {
- assert.equal(show, show_submit);
- };
-
- poll_question_container.toggle = (show) => {
- assert(!show);
- };
-
- poll_option_container.toggle = (show) => {
- assert(show);
- };
-
- poll_please_wait.toggle = (show) => {
- assert(!show);
- };
-
- poll_author_help.toggle = (show) => {
- assert(!show);
- };
+ function assert_visibility() {
+ assert(poll_option_container.visible());
+ assert(poll_question_header.visible());
+ assert(!poll_question_container.visible());
+ assert(poll_edit_question.visible());
+ assert(!poll_please_wait.visible());
+ assert(!poll_author_help.visible());
+ }
poll_widget.activate(opts);
+ assert_visibility();
+ assert(!poll_question_submit.visible());
+
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?");
@@ -376,10 +339,12 @@ run_test("activate own poll", () => {
/* 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?"});
+ assert_visibility();
+ assert(poll_question_submit.visible());
+
poll_option_input.val("");
out_data = undefined;
poll_question_submit.trigger("click");
diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js
index 61b0f6abf75..6b1c2fd349f 100644
--- a/frontend_tests/zjsunit/zjquery.js
+++ b/frontend_tests/zjsunit/zjquery.js
@@ -364,6 +364,11 @@ exports.make_new_elem = function (selector, opts) {
}
return text;
},
+ toggle(show) {
+ assert([true, false].includes(show));
+ shown = show;
+ return self;
+ },
trigger(ev) {
event_store.trigger(self, ev);
return self;