mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Add tests for subs.sub_or_unsub().
This commit is contained in:
@@ -7,6 +7,8 @@ add_dependencies({
|
|||||||
i18n: 'i18next',
|
i18n: 'i18next',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
set_global('channel', {});
|
||||||
|
|
||||||
var subs = require('js/subs.js');
|
var subs = require('js/subs.js');
|
||||||
|
|
||||||
var jsdom = require("jsdom");
|
var jsdom = require("jsdom");
|
||||||
@@ -160,3 +162,38 @@ subs.stream_description_match_stream_ids = [];
|
|||||||
assert.equal(subs.stream_name_match_stream_ids[1], 2);
|
assert.equal(subs.stream_name_match_stream_ids[1], 2);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
(function test_sub_or_unsub() {
|
||||||
|
var denmark = {
|
||||||
|
subscribed: false,
|
||||||
|
name: 'Denmark',
|
||||||
|
stream_id: 1,
|
||||||
|
description: 'Copenhagen',
|
||||||
|
};
|
||||||
|
stream_data.clear_subscriptions();
|
||||||
|
stream_data.add_sub("Denmark", denmark);
|
||||||
|
|
||||||
|
var post_params;
|
||||||
|
|
||||||
|
global.channel.post = function (params) {
|
||||||
|
post_params = params;
|
||||||
|
};
|
||||||
|
|
||||||
|
subs.sub_or_unsub(denmark.name);
|
||||||
|
assert.equal(post_params.url, '/json/users/me/subscriptions');
|
||||||
|
assert.deepEqual(post_params.data,
|
||||||
|
{subscriptions: '[{"name":"Denmark"}]'});
|
||||||
|
|
||||||
|
global.channel.post = undefined;
|
||||||
|
|
||||||
|
global.channel.del = function (params) {
|
||||||
|
post_params = params;
|
||||||
|
};
|
||||||
|
|
||||||
|
stream_data.get_sub_by_id(denmark.stream_id).subscribed = true;
|
||||||
|
subs.sub_or_unsub(denmark.name);
|
||||||
|
assert.equal(post_params.url, '/json/users/me/subscriptions');
|
||||||
|
assert.deepEqual(post_params.data,
|
||||||
|
{subscriptions: '["Denmark"]'});
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
|
|||||||
@@ -1051,6 +1051,17 @@ exports.change_stream_name = function (e) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.sub_or_unsub = function (stream_name) {
|
||||||
|
var sub = stream_data.get_sub(stream_name);
|
||||||
|
|
||||||
|
if (sub.subscribed) {
|
||||||
|
ajaxUnsubscribe(stream_name);
|
||||||
|
} else {
|
||||||
|
ajaxSubscribe(stream_name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
stream_data.initialize_from_page_params();
|
stream_data.initialize_from_page_params();
|
||||||
@@ -1262,19 +1273,9 @@ $(function () {
|
|||||||
selectText(this);
|
selectText(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
function sub_or_unsub(stream_name) {
|
|
||||||
var sub = stream_data.get_sub(stream_name);
|
|
||||||
|
|
||||||
if (sub.subscribed) {
|
|
||||||
ajaxUnsubscribe(stream_name);
|
|
||||||
} else {
|
|
||||||
ajaxSubscribe(stream_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#subscriptions_table").on("click", ".sub_unsub_button", function (e) {
|
$("#subscriptions_table").on("click", ".sub_unsub_button", function (e) {
|
||||||
var stream_name = get_stream_name(e.target);
|
var stream_name = get_stream_name(e.target);
|
||||||
sub_or_unsub(stream_name);
|
exports.sub_or_unsub(stream_name);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
@@ -1285,7 +1286,7 @@ $(function () {
|
|||||||
|
|
||||||
var stream_name = $(e.target).data("name");
|
var stream_name = $(e.target).data("name");
|
||||||
|
|
||||||
sub_or_unsub(stream_name);
|
exports.sub_or_unsub(stream_name);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user