Skip to content

Commit

Permalink
poll-widget: Refactor comment to option.
Browse files Browse the repository at this point in the history
We had initially designed the poll widget like a blog
post with comments beneath it but it makes more sense
to think of it as just a simple poll with options.
  • Loading branch information
aero31aero authored and timabbott committed Jan 29, 2019
1 parent 5641afc commit c176891
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 92 deletions.
82 changes: 41 additions & 41 deletions frontend_tests/node_tests/voting_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ run_test('poll_data_holder my question', () => {
let data = data_holder.get_widget_data();

assert.deepEqual(data, {
comments: [],
options: [],
question: 'Favorite color?',
});

Expand All @@ -36,25 +36,25 @@ run_test('poll_data_holder my question', () => {
data = data_holder.get_widget_data();

assert.deepEqual(data, {
comments: [],
options: [],
question: 'best plan?',
});

const comment_event = {
type: 'new_comment',
const option_event = {
type: 'new_option',
idx: 1,
comment: 'release now',
option: 'release now',
};

people.safe_full_names = () => '';

data_holder.handle_event(sender_id, comment_event);
data_holder.handle_event(sender_id, option_event);
data = data_holder.get_widget_data();

assert.deepEqual(data, {
comments: [
options: [
{
comment: 'release now',
option: 'release now',
names: '',
count: 0,
key: '99,1',
Expand All @@ -73,9 +73,9 @@ run_test('poll_data_holder my question', () => {
data = data_holder.get_widget_data();

assert.deepEqual(data, {
comments: [
options: [
{
comment: 'release now',
option: 'release now',
names: '',
count: 1,
key: '99,1',
Expand All @@ -96,11 +96,11 @@ run_test('poll_data_holder my question', () => {
data_holder.handle_event(sender_id, invalid_vote_event);
data = data_holder.get_widget_data();

const comment_outbound_event = data_holder.handle.new_comment.outbound('new comment');
assert.deepEqual(comment_outbound_event, {
type: 'new_comment',
const option_outbound_event = data_holder.handle.new_option.outbound('new option');
assert.deepEqual(option_outbound_event, {
type: 'new_option',
idx: 2,
comment: 'new comment',
option: 'new option',
});

const new_question = 'Any new plan?';
Expand All @@ -123,9 +123,9 @@ run_test('poll_data_holder my question', () => {
data = data_holder.get_widget_data();

assert.deepEqual(data, {
comments: [
options: [
{
comment: 'release now',
option: 'release now',
names: '',
count: 0,
key: '99,1',
Expand Down Expand Up @@ -170,15 +170,15 @@ run_test('activate another person poll', () => {
return elem;
};

const poll_comment = set_widget_find_result('button.poll-comment');
const poll_comment_input = set_widget_find_result('input.poll-comment');
const widget_comment_container = set_widget_find_result('ul.poll-widget');
const poll_option = set_widget_find_result('button.poll-option');
const poll_option_input = set_widget_find_result('input.poll-option');
const widget_option_container = set_widget_find_result('ul.poll-widget');

const poll_question_submit = set_widget_find_result('button.poll-question-check');
const poll_edit_question = set_widget_find_result('.poll-edit-question');
const poll_question_header = set_widget_find_result('.poll-question-header');
const poll_question_container = set_widget_find_result('.poll-question-bar');
const poll_comment_container = set_widget_find_result('.poll-comment-bar');
const poll_option_container = set_widget_find_result('.poll-option-bar');

const poll_vote_button = set_widget_find_result('button.poll-vote');
const poll_please_wait = set_widget_find_result('.poll-please-wait');
Expand All @@ -187,12 +187,12 @@ run_test('activate another person poll', () => {
set_widget_find_result('button.poll-question-remove');
set_widget_find_result('input.poll-question');

let comment_button_callback;
let option_button_callback;
let vote_button_callback;

poll_comment.on = (event, func) => {
poll_option.on = (event, func) => {
assert.equal(event, 'click');
comment_button_callback = func;
option_button_callback = func;
};

poll_vote_button.on = (event, func) => {
Expand All @@ -217,7 +217,7 @@ run_test('activate another person poll', () => {
assert(!show);
};

poll_comment_container.toggle = (show) => {
poll_option_container.toggle = (show) => {
assert.equal(show, true);
};

Expand All @@ -232,33 +232,33 @@ run_test('activate another person poll', () => {
poll_widget.activate(opts);

assert.equal(widget_elem.html(), 'poll-widget');
assert.equal(widget_comment_container.html(), 'poll-widget-results');
assert.equal(widget_option_container.html(), 'poll-widget-results');
assert.equal(poll_question_header.text(), 'What do you want?');

const e = {
stopPropagation: noop,
};

{
/* Testing data sent to server on adding comment */
poll_comment_input.val('cool choice');
/* Testing data sent to server on adding option */
poll_option_input.val('cool choice');
out_data = undefined;
comment_button_callback(e);
assert.deepEqual(out_data, { type: 'new_comment', idx: 1, comment: 'cool choice' });
option_button_callback(e);
assert.deepEqual(out_data, { type: 'new_option', idx: 1, option: 'cool choice' });

poll_comment_input.val('');
poll_option_input.val('');
out_data = undefined;
comment_button_callback(e);
option_button_callback(e);
assert.deepEqual(out_data, undefined);
}

const vote_events = [
{
sender_id: 100,
data: {
type: 'new_comment',
type: 'new_option',
idx: 1,
comment: 'release now',
option: 'release now',
},
},
{
Expand Down Expand Up @@ -333,16 +333,16 @@ run_test('activate own poll', () => {
return elem;
};

const poll_comment = set_widget_find_result('button.poll-comment');
const poll_comment_input = set_widget_find_result('input.poll-comment');
const widget_comment_container = set_widget_find_result('ul.poll-widget');
const poll_option = set_widget_find_result('button.poll-option');
const poll_option_input = set_widget_find_result('input.poll-option');
const widget_option_container = set_widget_find_result('ul.poll-widget');

const poll_question_submit = set_widget_find_result('button.poll-question-check');
const poll_edit_question = set_widget_find_result('.poll-edit-question');
const poll_question_input = set_widget_find_result('input.poll-question');
const poll_question_header = set_widget_find_result('.poll-question-header');
const poll_question_container = set_widget_find_result('.poll-question-bar');
const poll_comment_container = set_widget_find_result('.poll-comment-bar');
const poll_option_container = set_widget_find_result('.poll-option-bar');

const poll_vote_button = set_widget_find_result('button.poll-vote');
const poll_please_wait = set_widget_find_result('.poll-please-wait');
Expand All @@ -359,7 +359,7 @@ run_test('activate own poll', () => {

// Following event handler are already tested and doesn't make sense
// to test them again
poll_comment.on = noop;
poll_option.on = noop;
poll_vote_button.on = noop;

poll_question_header.toggle = (show) => {
Expand All @@ -379,7 +379,7 @@ run_test('activate own poll', () => {
assert(!show);
};

poll_comment_container.toggle = (show) => {
poll_option_container.toggle = (show) => {
assert(show);
};

Expand All @@ -394,7 +394,7 @@ run_test('activate own poll', () => {
poll_widget.activate(opts);

assert.equal(widget_elem.html(), 'poll-widget');
assert.equal(widget_comment_container.html(), 'poll-widget-results');
assert.equal(widget_option_container.html(), 'poll-widget-results');
assert.equal(poll_question_header.text(), 'Where to go?');

{
Expand All @@ -409,7 +409,7 @@ run_test('activate own poll', () => {
question_button_callback(e);
assert.deepEqual(out_data, { type: 'question', question: 'Is it new?' });

poll_comment_input.val('');
poll_option_input.val('');
out_data = undefined;
question_button_callback(e);
assert.deepEqual(out_data, undefined);
Expand Down
14 changes: 7 additions & 7 deletions frontend_tests/node_tests/widgetize.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ run_test('activate', () => {
const events = [
{
data: {
comment: "First option",
option: "First option",
idx: 1,
type: "new_comment",
type: "new_option",
},
sender_id: 101,
},
{
data: {
comment: "Second option",
option: "Second option",
idx: 1,
type: "new_comment",
type: "new_option",
},
sender_id: 102,
},
{
data: {
comment: "Third option",
option: "Third option",
idx: 1,
type: "new_comment",
type: "new_option",
},
sender_id: 102,
},
Expand Down Expand Up @@ -145,7 +145,7 @@ run_test('activate', () => {
const post_activate_event = {
data: {
idx: 1,
type: "new_comment",
type: "new_option",
},
message_id: 2001,
sender_id: 102,
Expand Down
Loading

0 comments on commit c176891

Please sign in to comment.