mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
node tests: Add tests for voting_widget.js.
This first commit starts by testing handling of inbound data.
This commit is contained in:
79
frontend_tests/node_tests/voting_widget.js
Normal file
79
frontend_tests/node_tests/voting_widget.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
zrequire('voting_widget');
|
||||||
|
|
||||||
|
set_global('people', {});
|
||||||
|
|
||||||
|
run_test('poll_data_holder my question', () => {
|
||||||
|
const is_my_poll = true;
|
||||||
|
const question = 'Favorite color?';
|
||||||
|
|
||||||
|
const sender_id = 99;
|
||||||
|
people.my_current_user_id = () => sender_id;
|
||||||
|
|
||||||
|
const data_holder = voting_widget.poll_data_holder(is_my_poll, question);
|
||||||
|
|
||||||
|
var data = data_holder.get_widget_data();
|
||||||
|
|
||||||
|
assert.deepEqual(data, {
|
||||||
|
comments: [],
|
||||||
|
question: 'Favorite color?',
|
||||||
|
});
|
||||||
|
|
||||||
|
const question_event = {
|
||||||
|
type: 'question',
|
||||||
|
question: 'best plan?',
|
||||||
|
};
|
||||||
|
|
||||||
|
data_holder.handle_event(sender_id, question_event);
|
||||||
|
data = data_holder.get_widget_data();
|
||||||
|
|
||||||
|
assert.deepEqual(data, {
|
||||||
|
comments: [],
|
||||||
|
question: 'best plan?',
|
||||||
|
});
|
||||||
|
|
||||||
|
const comment_event = {
|
||||||
|
type: 'new_comment',
|
||||||
|
idx: 1,
|
||||||
|
comment: 'release now',
|
||||||
|
};
|
||||||
|
|
||||||
|
people.safe_full_names = () => '';
|
||||||
|
|
||||||
|
data_holder.handle_event(sender_id, comment_event);
|
||||||
|
data = data_holder.get_widget_data();
|
||||||
|
|
||||||
|
assert.deepEqual(data, {
|
||||||
|
comments: [
|
||||||
|
{
|
||||||
|
comment: 'release now',
|
||||||
|
names: '',
|
||||||
|
count: 0,
|
||||||
|
key: '99,1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
question: 'best plan?',
|
||||||
|
});
|
||||||
|
|
||||||
|
const vote_event = {
|
||||||
|
type: 'vote',
|
||||||
|
key: '99,1',
|
||||||
|
vote: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
data_holder.handle_event(sender_id, vote_event);
|
||||||
|
data = data_holder.get_widget_data();
|
||||||
|
data = data_holder.get_widget_data();
|
||||||
|
|
||||||
|
assert.deepEqual(data, {
|
||||||
|
comments: [
|
||||||
|
{
|
||||||
|
comment: 'release now',
|
||||||
|
names: '',
|
||||||
|
count: 1,
|
||||||
|
key: '99,1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
question: 'best plan?',
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
@@ -2,7 +2,7 @@ var voting_widget = (function () {
|
|||||||
|
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
var poll_data_holder = function (is_my_poll, question) {
|
exports.poll_data_holder = function (is_my_poll, question) {
|
||||||
// This object just holds data for a poll, although it
|
// This object just holds data for a poll, although it
|
||||||
// works closely with the widget's concept of how data
|
// works closely with the widget's concept of how data
|
||||||
// should be represented for rendering, plus how the
|
// should be represented for rendering, plus how the
|
||||||
@@ -147,7 +147,7 @@ exports.activate = function (opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var is_my_poll = people.is_my_user_id(opts.message.sender_id);
|
var is_my_poll = people.is_my_user_id(opts.message.sender_id);
|
||||||
var poll_data = poll_data_holder(is_my_poll, question);
|
var poll_data = exports.poll_data_holder(is_my_poll, question);
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
var html = templates.render('poll-widget');
|
var html = templates.render('poll-widget');
|
||||||
|
|||||||
Reference in New Issue
Block a user