mirror of https://github.com/zulip/zulip.git
tests: Test "all" mentions more realistically.
We don't have people named "all". Instead, we create pseudo person objects with email/full_name of "all" (along with some other fields). The tests now reflect this.
This commit is contained in:
parent
d227988519
commit
773161cbb7
|
@ -19,6 +19,13 @@ zrequire('settings_org');
|
||||||
const th = zrequire('typeahead_helper');
|
const th = zrequire('typeahead_helper');
|
||||||
const LazySet = zrequire('lazy_set.js').LazySet;
|
const LazySet = zrequire('lazy_set.js').LazySet;
|
||||||
|
|
||||||
|
function assertSameEmails(lst1, lst2) {
|
||||||
|
assert.deepEqual(
|
||||||
|
_.map(lst1, (r) => r.email),
|
||||||
|
_.map(lst2, (r) => r.email)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
stream_data.create_streams([
|
stream_data.create_streams([
|
||||||
{name: 'Dev', subscribed: true, color: 'blue', stream_id: 1},
|
{name: 'Dev', subscribed: true, color: 'blue', stream_id: 1},
|
||||||
{name: 'Linux', subscribed: true, color: 'red', stream_id: 2},
|
{name: 'Linux', subscribed: true, color: 'red', stream_id: 2},
|
||||||
|
@ -301,29 +308,32 @@ run_test('sort_recipients', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const all_obj = {
|
||||||
|
email: 'all',
|
||||||
|
full_name: 'all',
|
||||||
|
};
|
||||||
|
|
||||||
run_test('sort_recipients all mention', () => {
|
run_test('sort_recipients all mention', () => {
|
||||||
// Test person email is "all" or "everyone"
|
// Test person email is "all" or "everyone"
|
||||||
const person = {
|
const test_objs = matches.concat([all_obj]);
|
||||||
email: "all",
|
|
||||||
full_name: "All",
|
|
||||||
is_admin: false,
|
|
||||||
is_bot: false,
|
|
||||||
user_id: 42,
|
|
||||||
};
|
|
||||||
people.add_in_realm(person);
|
|
||||||
|
|
||||||
assert.deepEqual(get_typeahead_result("a", "Linux", "Linux Topic"), [
|
const results = th.sort_recipients(
|
||||||
'all',
|
test_objs,
|
||||||
'a_user@zulip.org',
|
'a',
|
||||||
'a_bot@zulip.com',
|
'Linux',
|
||||||
'zman@test.net',
|
'Linux Topic'
|
||||||
'b_user_3@zulip.net',
|
);
|
||||||
'b_bot@example.com',
|
|
||||||
'b_user_1@zulip.net',
|
assertSameEmails(results, [
|
||||||
'b_user_2@zulip.net',
|
all_obj,
|
||||||
|
a_user,
|
||||||
|
a_bot,
|
||||||
|
zman,
|
||||||
|
b_user_3,
|
||||||
|
b_bot,
|
||||||
|
b_user_1,
|
||||||
|
b_user_2,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
people.deactivate(person);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('sort_recipients pm counts', () => {
|
run_test('sort_recipients pm counts', () => {
|
||||||
|
@ -368,39 +378,21 @@ run_test('sort_recipients dup bots', () => {
|
||||||
|
|
||||||
run_test('sort_recipients dup alls', () => {
|
run_test('sort_recipients dup alls', () => {
|
||||||
// full_name starts with same character but emails are 'all'
|
// full_name starts with same character but emails are 'all'
|
||||||
const small_matches = [
|
const test_objs = [
|
||||||
{
|
all_obj,
|
||||||
email: "all",
|
a_user,
|
||||||
full_name: "All 1",
|
all_obj,
|
||||||
is_admin: false,
|
|
||||||
is_bot: false,
|
|
||||||
user_id: 43,
|
|
||||||
}, {
|
|
||||||
email: "a_user@zulip.net",
|
|
||||||
full_name: "A user",
|
|
||||||
is_admin: false,
|
|
||||||
is_bot: false,
|
|
||||||
user_id: 44,
|
|
||||||
}, {
|
|
||||||
email: "all",
|
|
||||||
full_name: "All 2",
|
|
||||||
is_admin: false,
|
|
||||||
is_bot: false,
|
|
||||||
user_id: 45,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const recipients = th.sort_recipients(small_matches, "a", "Linux", "Linux Topic");
|
const recipients = th.sort_recipients(
|
||||||
|
test_objs, "a", "Linux", "Linux Topic");
|
||||||
|
|
||||||
const recipients_email = _.map(recipients, function (person) {
|
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
const expected = [
|
const expected = [
|
||||||
'all',
|
all_obj,
|
||||||
'all',
|
all_obj,
|
||||||
'a_user@zulip.net',
|
a_user,
|
||||||
];
|
];
|
||||||
assert.deepEqual(recipients_email, expected);
|
assertSameEmails(recipients, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('sort_recipients subscribers', () => {
|
run_test('sort_recipients subscribers', () => {
|
||||||
|
|
Loading…
Reference in New Issue