Add hash_util.encodeHashComponent() shim.

This commit is contained in:
Steve Howell 2017-03-18 10:29:20 -07:00 committed by Tim Abbott
parent d75efa19db
commit 27f37e6378
15 changed files with 53 additions and 14 deletions

View File

@ -48,6 +48,7 @@
"topic_list": false,
"gear_menu": false,
"hashchange": false,
"hash_util": false,
"message_list": false,
"Filter": false,
"pointer": false,

View File

@ -28,6 +28,10 @@ set_global('resize', {
resize_page_components: function () {},
});
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
var me = {
email: 'me@zulip.com',
user_id: 999,

View File

@ -54,6 +54,11 @@ set_global('$', function (obj) {
set_global('feature_flags', {local_echo: true});
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
jsdom.changeURL(window, 'http://zulip.zulipdev.com');
set_global('window', window);

View File

@ -6,6 +6,11 @@ add_dependencies({
var hashchange = require('js/hashchange.js');
set_global('hash_util', {
encodeHashComponent: hashchange.encodeHashComponent,
});
(function test_operators_round_trip() {
var operators;
var hash;

View File

@ -12,6 +12,10 @@ var Filter = global.Filter;
var stream_data = global.stream_data;
var _ = global._;
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
function set_filter(operators) {
operators = _.map(operators, function (op) {
return {operator: op[0], operand: op[1]};

View File

@ -14,6 +14,10 @@ set_global('message_store', {
set_global('unread', {});
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
// TODO: move pm_list-related tests to their own module
var pm_list = require('js/pm_list.js');

View File

@ -15,6 +15,10 @@ add_dependencies({
set_global('blueslip', {});
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
var stream_data = require('js/stream_data.js');
var people = global.people;

View File

@ -16,6 +16,11 @@ add_dependencies({
var stream_list = require('js/stream_list.js');
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
var jsdom = require("jsdom");
var window = jsdom.jsdom().defaultView;
global.$ = require('jquery')(window);

View File

@ -15,6 +15,10 @@ global.$ = require('jquery')(window);
var topic_list = require('js/topic_list.js');
set_global('hash_util', {
encodeHashComponent: global.hashchange.encodeHashComponent,
});
global.compile_template('topic_list_item');
(function test_topic_list_build_widget() {

View File

@ -92,7 +92,7 @@ $(function () {
e.preventDefault();
var stream = stream_data.get_sub_by_id($(this).attr('data-stream-id'));
if (stream) {
window.location.href = '/#narrow/stream/' + hashchange.encodeHashComponent(stream.name);
window.location.href = '/#narrow/stream/' + hash_util.encodeHashComponent(stream.name);
return;
}
window.location.href = $(this).attr('href');

View File

@ -352,7 +352,7 @@ function handleStream(streamName) {
}
return '<a class="stream" data-stream-id="' + stream.stream_id + '" ' +
'href="' + window.location.origin + '/#narrow/stream/' +
hashchange.encodeHashComponent(stream.name) + '"' +
hash_util.encodeHashComponent(stream.name) + '"' +
'>' + '#' + stream.name + '</a>';
}

View File

@ -88,7 +88,7 @@ exports.operators_to_hash = function (operators) {
var operand = elem.operand;
var sign = elem.negated ? '-' : '';
hash += '/' + sign + hashchange.encodeHashComponent(operator)
hash += '/' + sign + hash_util.encodeHashComponent(operator)
+ '/' + hashchange.encode_operand(operator, operand);
});
}

View File

@ -614,30 +614,30 @@ exports.by_sender_uri = function (reply_to) {
};
exports.by_stream_uri = function (stream) {
return "#narrow/stream/" + hashchange.encodeHashComponent(stream);
return "#narrow/stream/" + hash_util.encodeHashComponent(stream);
};
exports.by_stream_subject_uri = function (stream, subject) {
return "#narrow/stream/" + hashchange.encodeHashComponent(stream) +
"/subject/" + hashchange.encodeHashComponent(subject);
return "#narrow/stream/" + hash_util.encodeHashComponent(stream) +
"/subject/" + hash_util.encodeHashComponent(subject);
};
exports.by_message_uri = function (message_id) {
return "#narrow/id/" + hashchange.encodeHashComponent(message_id);
return "#narrow/id/" + hash_util.encodeHashComponent(message_id);
};
exports.by_near_uri = function (message_id) {
return "#narrow/near/" + hashchange.encodeHashComponent(message_id);
return "#narrow/near/" + hash_util.encodeHashComponent(message_id);
};
exports.by_conversation_and_time_uri = function (message) {
if (message.type === "stream") {
return "#narrow/stream/" + hashchange.encodeHashComponent(message.stream) +
"/subject/" + hashchange.encodeHashComponent(message.subject) +
"/near/" + hashchange.encodeHashComponent(message.id);
return "#narrow/stream/" + hash_util.encodeHashComponent(message.stream) +
"/subject/" + hash_util.encodeHashComponent(message.subject) +
"/near/" + hash_util.encodeHashComponent(message.id);
}
return "#narrow/pm-with/" + hashchange.encodeHashComponent(message.reply_to) +
"/near/" + hashchange.encodeHashComponent(message.id);
return "#narrow/pm-with/" + hash_util.encodeHashComponent(message.reply_to) +
"/near/" + hash_util.encodeHashComponent(message.id);
};
// Are we narrowed to PMs: all PMs or PMs with particular people.

View File

@ -13,5 +13,8 @@ var compose_actions = {};
compose_actions.start = compose.start;
compose_actions.cancel = compose.cancel;
var hash_util = {};
hash_util.encodeHashComponent = hashchange.encodeHashComponent;
var compose_state = {};
compose_state.has_message_content = compose.has_message_content;

View File

@ -1423,7 +1423,7 @@ $(function () {
window.location.hash = "#streams" + "/" +
stream_id + "/" +
hashchange.encodeHashComponent(sub.name);
hash_util.encodeHashComponent(sub.name);
}
});