2018-04-13 23:44:10 +02:00
|
|
|
zrequire('hash_util');
|
|
|
|
zrequire('stream_data');
|
|
|
|
zrequire('people');
|
2018-12-22 23:04:23 +01:00
|
|
|
zrequire('util');
|
2018-04-13 23:44:10 +02:00
|
|
|
|
2019-07-25 09:13:22 +02:00
|
|
|
set_global('location', {
|
|
|
|
protocol: "https:",
|
|
|
|
host: "example.com",
|
|
|
|
pathname: "/",
|
|
|
|
});
|
2018-08-05 01:30:23 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const hamlet = {
|
2018-04-13 23:44:10 +02:00
|
|
|
user_id: 1,
|
|
|
|
email: 'hamlet@example.com',
|
|
|
|
full_name: 'Hamlet',
|
|
|
|
};
|
|
|
|
|
|
|
|
people.add_in_realm(hamlet);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const frontend = {
|
2018-04-13 23:44:10 +02:00
|
|
|
stream_id: 99,
|
|
|
|
name: 'frontend',
|
|
|
|
};
|
|
|
|
|
2018-12-14 19:02:26 +01:00
|
|
|
stream_data.add_sub('frontend', frontend);
|
2018-04-13 23:44:10 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('hash_util', () => {
|
2018-04-13 23:44:10 +02:00
|
|
|
// Test encodeHashComponent
|
2019-11-02 00:06:25 +01:00
|
|
|
const str = 'https://www.zulipexample.com';
|
|
|
|
const result1 = hash_util.encodeHashComponent(str);
|
2018-04-13 23:44:10 +02:00
|
|
|
assert.equal(result1, 'https.3A.2F.2Fwww.2Ezulipexample.2Ecom');
|
|
|
|
|
|
|
|
// Test decodeHashComponent
|
2019-11-02 00:06:25 +01:00
|
|
|
const result2 = hash_util.decodeHashComponent(result1);
|
2018-04-13 23:44:10 +02:00
|
|
|
assert.equal(result2, str);
|
|
|
|
|
|
|
|
// Test encode_operand and decode_operand
|
|
|
|
|
|
|
|
function encode_decode_operand(operator, operand, expected_val) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const encode_result = hash_util.encode_operand(operator, operand);
|
2018-04-13 23:44:10 +02:00
|
|
|
assert.equal(encode_result, expected_val);
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_operand = encode_result;
|
|
|
|
const decode_result = hash_util.decode_operand(operator, new_operand);
|
2018-04-13 23:44:10 +02:00
|
|
|
assert.equal(decode_result, operand);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let operator = 'sender';
|
|
|
|
let operand = hamlet.email;
|
2018-04-13 23:44:10 +02:00
|
|
|
|
|
|
|
encode_decode_operand(operator, operand, '1-hamlet');
|
|
|
|
|
|
|
|
operator = 'stream';
|
|
|
|
operand = 'frontend';
|
|
|
|
|
|
|
|
encode_decode_operand(operator, operand, '99-frontend');
|
|
|
|
|
|
|
|
operator = 'topic';
|
|
|
|
operand = 'testing 123';
|
|
|
|
|
|
|
|
encode_decode_operand(operator, operand, 'testing.20123');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-08-05 01:30:23 +02:00
|
|
|
|
2018-12-04 23:48:07 +01:00
|
|
|
run_test('test_get_hash_category', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
hash_util.get_hash_category('streams/subscribed'),
|
|
|
|
'streams'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
hash_util.get_hash_category('#settings/display-settings'),
|
|
|
|
'settings'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
hash_util.get_hash_category('#drafts'),
|
|
|
|
'drafts'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
hash_util.get_hash_category('invites'),
|
|
|
|
'invites'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-12-05 20:33:52 +01:00
|
|
|
run_test('test_get_hash_section', () => {
|
|
|
|
assert.equal(
|
|
|
|
hash_util.get_hash_section('streams/subscribed'),
|
|
|
|
'subscribed'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
hash_util.get_hash_section('#settings/your-account'),
|
|
|
|
'your-account'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
hash_util.get_hash_section('settings/10/general/'),
|
|
|
|
'10'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
hash_util.get_hash_section('#drafts'),
|
|
|
|
''
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
hash_util.get_hash_section(''),
|
|
|
|
''
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-12-04 23:24:03 +01:00
|
|
|
run_test('test_parse_narrow', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
hash_util.parse_narrow(['narrow', 'stream', '11-social']),
|
|
|
|
[{negated: false, operator: 'stream', operand: '11-social'}]
|
|
|
|
);
|
|
|
|
|
2018-12-04 23:29:43 +01:00
|
|
|
assert.equal(
|
2018-12-04 23:24:03 +01:00
|
|
|
hash_util.parse_narrow(['narrow', 'BOGUS']),
|
2018-12-04 23:29:43 +01:00
|
|
|
undefined
|
2018-12-04 23:24:03 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-12-02 19:42:34 +01:00
|
|
|
run_test('test_stream_edit_uri', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = {
|
2018-12-02 19:42:34 +01:00
|
|
|
name: 'research & development',
|
|
|
|
stream_id: 42,
|
|
|
|
};
|
|
|
|
assert.equal(hash_util.stream_edit_uri(sub),
|
|
|
|
'#streams/42/research.20.26.20development');
|
|
|
|
});
|
|
|
|
|
2018-08-05 01:30:23 +02:00
|
|
|
run_test('test_by_conversation_and_time_uri', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let message = {
|
2018-08-05 01:30:23 +02:00
|
|
|
type: 'stream',
|
2018-12-14 19:02:26 +01:00
|
|
|
stream_id: frontend.stream_id,
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'testing',
|
2018-08-05 01:30:23 +02:00
|
|
|
id: 42,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(hash_util.by_conversation_and_time_uri(message),
|
2018-12-22 23:04:23 +01:00
|
|
|
'https://example.com/#narrow/stream/99-frontend/topic/testing/near/42');
|
2018-08-05 01:30:23 +02:00
|
|
|
|
|
|
|
message = {
|
|
|
|
type: 'private',
|
2018-10-18 22:05:43 +02:00
|
|
|
display_recipient: [
|
|
|
|
{
|
2020-01-01 13:02:34 +01:00
|
|
|
id: hamlet.user_id,
|
2018-10-18 22:05:43 +02:00
|
|
|
},
|
|
|
|
],
|
2018-08-05 01:30:23 +02:00
|
|
|
id: 43,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(hash_util.by_conversation_and_time_uri(message),
|
2018-10-18 22:05:43 +02:00
|
|
|
'https://example.com/#narrow/pm-with/1-pm/near/43');
|
2018-08-05 01:30:23 +02:00
|
|
|
});
|