Extract write_handlebars_output() in node tests.

This commit is contained in:
Steve Howell
2016-07-29 19:02:09 -07:00
committed by Tim Abbott
parent 6b8e2c406b
commit 87dbdaac68
2 changed files with 42 additions and 38 deletions

View File

@@ -123,6 +123,10 @@ global.write_test_output = function (label, output) {
fs.appendFileSync(output_fn, data); fs.appendFileSync(output_fn, data);
}; };
global.write_handlebars_output = function (label, output) {
global.write_test_output(label + '.handlebars', output);
};
global.append_test_output = function (output) { global.append_test_output = function (output) {
fs.appendFileSync(output_fn, output); fs.appendFileSync(output_fn, output);
}; };

View File

@@ -69,7 +69,7 @@ function render(template_name, args) {
html += "</div>"; html += "</div>";
var link = $(html).find("a.respond_button"); var link = $(html).find("a.respond_button");
assert.equal(link.text().trim(), 'Reply'); assert.equal(link.text().trim(), 'Reply');
global.write_test_output("actions_popover_content.handlebars", html); global.write_handlebars_output("actions_popover_content", html);
}()); }());
(function admin_tab() { (function admin_tab() {
@@ -83,7 +83,7 @@ function render(template_name, args) {
assert.notEqual($(html).find("#" + admin_feature).length, 0); assert.notEqual($(html).find("#" + admin_feature).length, 0);
}); });
assert.equal($(html).find("input.admin-realm-name").val(), 'Zulip'); assert.equal($(html).find("input.admin-realm-name").val(), 'Zulip');
global.write_test_output("admin_tab.handlebars", html); global.write_handlebars_output("admin_tab", html);
}()); }());
(function admin_default_streams_list() { (function admin_default_streams_list() {
@@ -96,7 +96,7 @@ function render(template_name, args) {
html += "</table>"; html += "</table>";
var span = $(html).find(".default_stream_name:first"); var span = $(html).find(".default_stream_name:first");
assert.equal(span.text(), "devel"); assert.equal(span.text(), "devel");
global.write_test_output("admin_default_streams_list.handlebars", html); global.write_handlebars_output("admin_default_streams_list", html);
}()); }());
(function admin_streams_list() { (function admin_streams_list() {
@@ -109,7 +109,7 @@ function render(template_name, args) {
html += "</table>"; html += "</table>";
var span = $(html).find(".stream_name:first"); var span = $(html).find(".stream_name:first");
assert.equal(span.text(), "devel"); assert.equal(span.text(), "devel");
global.write_test_output("admin_streams_list.handlebars", html); global.write_handlebars_output("admin_streams_list", html);
}()); }());
(function admin_user_list() { (function admin_user_list() {
@@ -136,7 +136,7 @@ function render(template_name, args) {
assert.equal(button.text().trim(), "Make admin"); assert.equal(button.text().trim(), "Make admin");
assert(button.hasClass("make-admin")); assert(button.hasClass("make-admin"));
global.write_test_output("admin_user_list.handlebars", html); global.write_handlebars_output("admin_user_list", html);
}()); }());
(function alert_word_settings_item() { (function alert_word_settings_item() {
@@ -149,14 +149,14 @@ function render(template_name, args) {
html += render('alert_word_settings_item', args); html += render('alert_word_settings_item', args);
}); });
html += "</ul>"; html += "</ul>";
global.write_test_output("alert_word_settings_item.handlebars", html); global.write_handlebars_output("alert_word_settings_item", html);
var li = $(html).find("li.alert-word-item:first"); var li = $(html).find("li.alert-word-item:first");
assert.equal(li.attr('data-word'),'lunch'); assert.equal(li.attr('data-word'),'lunch');
}()); }());
(function announce_stream_docs() { (function announce_stream_docs() {
var html = render('announce_stream_docs'); var html = render('announce_stream_docs');
global.write_test_output("announce_stream_docs.handlebars", html); global.write_handlebars_output("announce_stream_docs", html);
}()); }());
(function bankruptcy_modal() { (function bankruptcy_modal() {
@@ -164,7 +164,7 @@ function render(template_name, args) {
unread_count: 99 unread_count: 99
}; };
var html = render('bankruptcy_modal', args); var html = render('bankruptcy_modal', args);
global.write_test_output("bankruptcy_modal.handlebars", html); global.write_handlebars_output("bankruptcy_modal", html);
var count = $(html).find("p b"); var count = $(html).find("p b");
assert.equal(count.text(), 99); assert.equal(count.text(), 99);
}()); }());
@@ -187,7 +187,7 @@ function render(template_name, args) {
html += '</div>'; html += '</div>';
html += '</div>'; html += '</div>';
global.write_test_output("bot_avatar_row.handlebars", html); global.write_handlebars_output("bot_avatar_row", html);
var img = $(html).find("img"); var img = $(html).find("img");
assert.equal(img.attr('src'), '/hamlet/avatar/url'); assert.equal(img.attr('src'), '/hamlet/avatar/url');
}()); }());
@@ -198,7 +198,7 @@ function render(template_name, args) {
name: 'Hamlet' name: 'Hamlet'
}; };
var html = render('compose-invite-users', args); var html = render('compose-invite-users', args);
global.write_test_output("compose-invite-users.handlebars", html); global.write_handlebars_output("compose-invite-users", html);
var button = $(html).find("button:first"); var button = $(html).find("button:first");
assert.equal(button.text(), "Subscribe"); assert.equal(button.text(), "Subscribe");
}()); }());
@@ -209,7 +209,7 @@ function render(template_name, args) {
name: 'all' name: 'all'
}; };
var html = render('compose_all_everyone', args); var html = render('compose_all_everyone', args);
global.write_test_output("compose_all_everyone.handlebars", html); global.write_handlebars_output("compose_all_everyone", html);
var button = $(html).find("button:first"); var button = $(html).find("button:first");
assert.equal(button.text(), "YES"); assert.equal(button.text(), "YES");
var error_msg = $(html).find('span.compose-all-everyone-msg').text().trim(); var error_msg = $(html).find('span.compose-all-everyone-msg').text().trim();
@@ -226,14 +226,14 @@ function render(template_name, args) {
var html = '<div id="out-of-view-notification" class="notification-alert">'; var html = '<div id="out-of-view-notification" class="notification-alert">';
html += render('compose_notification', args); html += render('compose_notification', args);
html += '</div>'; html += '</div>';
global.write_test_output("compose_notification.handlebars", html); global.write_handlebars_output("compose_notification", html);
var a = $(html).find("a.compose_notification_narrow_by_subject"); var a = $(html).find("a.compose_notification_narrow_by_subject");
assert.equal(a.text(), "Narrow to here"); assert.equal(a.text(), "Narrow to here");
}()); }());
(function email_address_hint() { (function email_address_hint() {
var html = render('email_address_hint'); var html = render('email_address_hint');
global.write_test_output("email_address_hint.handlebars", html); global.write_handlebars_output("email_address_hint", html);
var li = $(html).find("li:first"); var li = $(html).find("li:first");
assert.equal(li.text(), 'The email will be forwarded to this stream'); assert.equal(li.text(), 'The email will be forwarded to this stream');
}()); }());
@@ -250,7 +250,7 @@ function render(template_name, args) {
] ]
}; };
var html = render('group_pms', args); var html = render('group_pms', args);
global.write_test_output("group_pms.handlebars", html); global.write_handlebars_output("group_pms", html);
var a = $(html).find("a:first"); var a = $(html).find("a:first");
assert.equal(a.text(), 'Alice and Bob'); assert.equal(a.text(), 'Alice and Bob');
@@ -268,7 +268,7 @@ function render(template_name, args) {
] ]
}; };
var html = render('invite_subscription', args); var html = render('invite_subscription', args);
global.write_test_output("invite_subscription.handlebars", html); global.write_handlebars_output("invite_subscription", html);
var input = $(html).find("label:first"); var input = $(html).find("label:first");
assert.equal(input.text().trim(), "devel"); assert.equal(input.text().trim(), "devel");
@@ -290,7 +290,7 @@ function render(template_name, args) {
var html = render('single_message', message); var html = render('single_message', message);
html = '<div class="message_table focused_table" id="zfilt">' + html + '</div>'; html = '<div class="message_table focused_table" id="zfilt">' + html + '</div>';
global.write_test_output("message.handlebars", html); global.write_handlebars_output("message", html);
var first_message = $(html).find("div.messagebox:first"); var first_message = $(html).find("div.messagebox:first");
@@ -353,7 +353,7 @@ function render(template_name, args) {
var highlighted_subject_word = $(html).find('a.narrows_by_subject .highlight').text(); var highlighted_subject_word = $(html).find('a.narrows_by_subject .highlight').text();
assert.equal(highlighted_subject_word, 'two'); assert.equal(highlighted_subject_word, 'two');
global.write_test_output("message_group.handlebars", html); global.write_handlebars_output("message_group", html);
}()); }());
(function message_edit_form() { (function message_edit_form() {
@@ -363,7 +363,7 @@ function render(template_name, args) {
"is_stream": true "is_stream": true
}; };
var html = render('message_edit_form', args); var html = render('message_edit_form', args);
global.write_test_output("message_edit_form.handlebars", html); global.write_handlebars_output("message_edit_form", html);
var textarea = $(html).find("textarea.message_edit_content"); var textarea = $(html).find("textarea.message_edit_content");
assert.equal(textarea.text(), "Let's go to lunch!"); assert.equal(textarea.text(), "Let's go to lunch!");
@@ -382,7 +382,7 @@ function render(template_name, args) {
}; };
var html = render('message_info_popover_content', args); var html = render('message_info_popover_content', args);
global.write_test_output("message_info_popover_content.handlebars", html); global.write_handlebars_output("message_info_popover_content", html);
var a = $(html).find("a.respond_personal_button"); var a = $(html).find("a.respond_personal_button");
assert.equal(a.text().trim(), 'Send Alice Smith a private message'); assert.equal(a.text().trim(), 'Send Alice Smith a private message');
@@ -398,7 +398,7 @@ function render(template_name, args) {
}; };
var html = render('message_info_popover_title', args); var html = render('message_info_popover_title', args);
global.write_test_output("message_info_popover_title.handlebars", html); global.write_handlebars_output("message_info_popover_title", html);
assert($(html).text().trim(), "Message to stream devel"); assert($(html).text().trim(), "Message to stream devel");
}()); }());
@@ -418,7 +418,7 @@ function render(template_name, args) {
}; };
var html = render('new_stream_users', args); var html = render('new_stream_users', args);
global.write_test_output("new_stream_users.handlebars", html); global.write_handlebars_output("new_stream_users", html);
var label = $(html).find("label:first"); var label = $(html).find("label:first");
assert.equal(label.text().trim(), 'King Lear (lear@zulip.com)'); assert.equal(label.text().trim(), 'King Lear (lear@zulip.com)');
@@ -432,7 +432,7 @@ function render(template_name, args) {
}; };
var html = render('notification', args); var html = render('notification', args);
global.write_test_output("notification.handlebars", html); global.write_handlebars_output("notification", html);
var title = $(html).find(".title"); var title = $(html).find(".title");
assert.equal(title.text().trim(), 'You have a notification'); assert.equal(title.text().trim(), 'You have a notification');
@@ -466,7 +466,7 @@ function render(template_name, args) {
html += '</li>'; html += '</li>';
html += '</ul>'; html += '</ul>';
global.write_test_output("sidebar_subject_list.handlebars", html); global.write_handlebars_output("sidebar_subject_list", html);
var li = $(html).find("li.expanded_subject:first"); var li = $(html).find("li.expanded_subject:first");
assert.equal(li.attr('data-name'), 'lunch'); assert.equal(li.attr('data-name'), 'lunch');
@@ -497,7 +497,7 @@ function render(template_name, args) {
assert.equal($(html).find("." + item).length, 1); assert.equal($(html).find("." + item).length, 1);
}); });
global.write_test_output("stream_member_list_entry.handlebars", html); global.write_handlebars_output("stream_member_list_entry", html);
}()); }());
(function stream_sidebar_actions() { (function stream_sidebar_actions() {
@@ -511,7 +511,7 @@ function render(template_name, args) {
}; };
var html = render('stream_sidebar_actions', args); var html = render('stream_sidebar_actions', args);
global.write_test_output("stream_sidebar_actions.handlebars", html); global.write_handlebars_output("stream_sidebar_actions", html);
var li = $(html).find("li:first"); var li = $(html).find("li:first");
assert.equal(li.text().trim(), 'Narrow to stream devel'); assert.equal(li.text().trim(), 'Narrow to stream devel');
@@ -530,7 +530,7 @@ function render(template_name, args) {
html += render('stream_sidebar_row', args); html += render('stream_sidebar_row', args);
html += '</ul>'; html += '</ul>';
global.write_test_output("stream_sidebar_row.handlebars", html); global.write_handlebars_output("stream_sidebar_row", html);
var swatch = $(html).find(".streamlist_swatch"); var swatch = $(html).find(".streamlist_swatch");
assert.equal(swatch.attr('id'), 'stream_sidebar_swatch_999'); assert.equal(swatch.attr('id'), 'stream_sidebar_swatch_999');
@@ -571,7 +571,7 @@ function render(template_name, args) {
html += render('subscription_table_body', args); html += render('subscription_table_body', args);
html += '</div>'; html += '</div>';
global.write_test_output("subscription_table_body.handlebars", html); global.write_handlebars_output("subscription_table_body", html);
var span = $(html).find(".subscription_name:first"); var span = $(html).find(".subscription_name:first");
assert.equal(span.text(), 'devel'); assert.equal(span.text(), 'devel');
@@ -604,7 +604,7 @@ function render(template_name, args) {
var html = render('tab_bar', args); var html = render('tab_bar', args);
global.write_test_output("tab_bar.handlebars", html); global.write_handlebars_output("tab_bar", html);
var a = $(html).find("li:first"); var a = $(html).find("li:first");
assert.equal(a.text().trim(), 'Home'); assert.equal(a.text().trim(), 'Home');
@@ -613,7 +613,7 @@ function render(template_name, args) {
(function topic_edit_form() { (function topic_edit_form() {
var html = render('topic_edit_form'); var html = render('topic_edit_form');
global.write_test_output("topic_edit_form.handlebars", html); global.write_handlebars_output("topic_edit_form", html);
var button = $(html).find("button:first"); var button = $(html).find("button:first");
assert.equal(button.find("i").attr("class"), 'icon-vector-ok'); assert.equal(button.find("i").attr("class"), 'icon-vector-ok');
@@ -627,7 +627,7 @@ function render(template_name, args) {
}; };
var html = render('topic_sidebar_actions', args); var html = render('topic_sidebar_actions', args);
global.write_test_output("topic_sidebar_actions.handlebars", html); global.write_handlebars_output("topic_sidebar_actions", html);
var a = $(html).find("a.narrow_to_topic"); var a = $(html).find("a.narrow_to_topic");
assert.equal(a.text().trim(), 'Narrow to topic lunch'); assert.equal(a.text().trim(), 'Narrow to topic lunch');
@@ -643,7 +643,7 @@ function render(template_name, args) {
var html = ''; var html = '';
html += render('bookend', args); html += render('bookend', args);
global.write_test_output("bookend.handlebars", html); global.write_handlebars_output("bookend", html);
assert.equal($(html).text().trim(), "subscribed to stream\n \n \n \n Unsubscribe"); assert.equal($(html).text().trim(), "subscribed to stream\n \n \n \n Unsubscribe");
}()); }());
@@ -656,7 +656,7 @@ function render(template_name, args) {
var html = ''; var html = '';
html += render('bookend', args); html += render('bookend', args);
global.write_test_output("bookend.handlebars", html); global.write_handlebars_output("bookend", html);
assert.equal($(html).text().trim(), 'Not subscribed to stream\n \n \n \n Subscribe'); assert.equal($(html).text().trim(), 'Not subscribed to stream\n \n \n \n Subscribe');
}()); }());
@@ -676,7 +676,7 @@ function render(template_name, args) {
title: 'Title' title: 'Title'
}; };
html = render(tutorial, args); html = render(tutorial, args);
global.write_test_output(tutorial + '.handlebars', html); global.write_handlebars_output(tutorial, html);
}); });
}()); }());
@@ -707,7 +707,7 @@ function render(template_name, args) {
html += render('user_presence_rows', args); html += render('user_presence_rows', args);
html += '</ul>'; html += '</ul>';
global.write_test_output("user_presence_rows.handlebars", html); global.write_handlebars_output("user_presence_rows", html);
var a = $(html).find("a.my_fullname:first"); var a = $(html).find("a.my_fullname:first");
assert.equal(a.text(), 'King Lear'); assert.equal(a.text(), 'King Lear');
@@ -721,7 +721,7 @@ function render(template_name, args) {
var html = render('user_sidebar_actions', args); var html = render('user_sidebar_actions', args);
global.write_test_output("user_sidebar_actions.handlebars", html); global.write_handlebars_output("user_sidebar_actions", html);
var a = $(html).find("a.narrow_to_private_messages"); var a = $(html).find("a.narrow_to_private_messages");
assert.equal(a.text().trim(), 'Narrow to private messages with Hamlet'); assert.equal(a.text().trim(), 'Narrow to private messages with Hamlet');
@@ -729,7 +729,7 @@ function render(template_name, args) {
(function notification_docs() { (function notification_docs() {
var html = render('propagate_notification_change'); var html = render('propagate_notification_change');
global.write_test_output("propagate_notification_change.handlebars", html); global.write_handlebars_output("propagate_notification_change", html);
var button_area = $(html).find(".propagate-notifications-controls"); var button_area = $(html).find(".propagate-notifications-controls");
assert.equal(button_area.find(".yes_propagate_notifications").text().trim(), 'Yes'); assert.equal(button_area.find(".yes_propagate_notifications").text().trim(), 'Yes');
@@ -758,7 +758,7 @@ function render(template_name, args) {
// Render with all booleans set to true. // Render with all booleans set to true.
var html = render('settings_tab', {page_params: page_params}); var html = render('settings_tab', {page_params: page_params});
global.write_test_output("settings_tab.handlebars", html); global.write_handlebars_output("settings_tab", html);
// All checkboxes should be checked. // All checkboxes should be checked.
_.each(checkbox_ids, function (checkbox) { _.each(checkbox_ids, function (checkbox) {
@@ -794,7 +794,7 @@ function render(template_name, args) {
html += render('admin_emoji_list', args); html += render('admin_emoji_list', args);
html += '</tbody>'; html += '</tbody>';
global.write_test_output('admin_emoji_list.handlebars', html); global.write_handlebars_output('admin_emoji_list', html);
var emoji_name = $(html).find('tr.emoji_row:first span.emoji_name'); var emoji_name = $(html).find('tr.emoji_row:first span.emoji_name');
var emoji_url = $(html).find('tr.emoji_row:first span.emoji_image img'); var emoji_url = $(html).find('tr.emoji_row:first span.emoji_image img');