mirror of https://github.com/zulip/zulip.git
tests: Improve hashchange coverage for operators.
Test round tripping of operators in hashchange.js.
This commit is contained in:
parent
da84ff3746
commit
030c6649ae
|
@ -1,8 +1,9 @@
|
||||||
var hashchange = require('js/hashchange.js');
|
var hashchange = require('js/hashchange.js');
|
||||||
|
|
||||||
(function test_basics() {
|
(function test_operators_round_trip() {
|
||||||
var operators;
|
var operators;
|
||||||
var hash;
|
var hash;
|
||||||
|
var narrow;
|
||||||
|
|
||||||
operators = [
|
operators = [
|
||||||
{operator: 'stream', operand: 'devel'},
|
{operator: 'stream', operand: 'devel'},
|
||||||
|
@ -11,10 +12,23 @@ var hashchange = require('js/hashchange.js');
|
||||||
hash = hashchange.operators_to_hash(operators);
|
hash = hashchange.operators_to_hash(operators);
|
||||||
assert.equal(hash, '#narrow/stream/devel/topic/algol');
|
assert.equal(hash, '#narrow/stream/devel/topic/algol');
|
||||||
|
|
||||||
|
narrow = hashchange.parse_narrow(hash.split('/'));
|
||||||
|
assert.deepEqual(narrow, [
|
||||||
|
{operator: 'stream', operand: 'devel', negated: false},
|
||||||
|
{operator: 'topic', operand: 'algol', negated: false},
|
||||||
|
]);
|
||||||
|
|
||||||
operators = [
|
operators = [
|
||||||
{operator: 'stream', operand: 'devel'},
|
{operator: 'stream', operand: 'devel'},
|
||||||
{operator: 'topic', operand: 'visual c++', negated: true},
|
{operator: 'topic', operand: 'visual c++', negated: true},
|
||||||
];
|
];
|
||||||
hash = hashchange.operators_to_hash(operators);
|
hash = hashchange.operators_to_hash(operators);
|
||||||
assert.equal(hash, '#narrow/stream/devel/-topic/visual.20c.2B.2B');
|
assert.equal(hash, '#narrow/stream/devel/-topic/visual.20c.2B.2B');
|
||||||
|
|
||||||
|
narrow = hashchange.parse_narrow(hash.split('/'));
|
||||||
|
assert.deepEqual(narrow, [
|
||||||
|
{operator: 'stream', operand: 'devel', negated: false},
|
||||||
|
{operator: 'topic', operand: 'visual c++', negated: true},
|
||||||
|
]);
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -82,7 +82,7 @@ exports.save_narrow = function (operators) {
|
||||||
exports.changehash(new_hash);
|
exports.changehash(new_hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
function parse_narrow(hash) {
|
exports.parse_narrow = function (hash) {
|
||||||
var i;
|
var i;
|
||||||
var operators = [];
|
var operators = [];
|
||||||
for (i=1; i<hash.length; i+=2) {
|
for (i=1; i<hash.length; i+=2) {
|
||||||
|
@ -102,7 +102,7 @@ function parse_narrow(hash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return operators;
|
return operators;
|
||||||
}
|
};
|
||||||
|
|
||||||
function activate_home_tab() {
|
function activate_home_tab() {
|
||||||
ui.change_tab_to("#home");
|
ui.change_tab_to("#home");
|
||||||
|
@ -135,7 +135,7 @@ function do_hashchange(from_reload) {
|
||||||
switch (hash[0]) {
|
switch (hash[0]) {
|
||||||
case "#narrow":
|
case "#narrow":
|
||||||
ui.change_tab_to("#home");
|
ui.change_tab_to("#home");
|
||||||
var operators = parse_narrow(hash);
|
var operators = exports.parse_narrow(hash);
|
||||||
if (operators === undefined) {
|
if (operators === undefined) {
|
||||||
// If the narrow URL didn't parse, clear
|
// If the narrow URL didn't parse, clear
|
||||||
// window.location.hash and send them to the home tab
|
// window.location.hash and send them to the home tab
|
||||||
|
|
Loading…
Reference in New Issue