mirror of
https://github.com/zulip/zulip.git
synced 2026-06-21 21:32:29 +08:00
This commit was originally automatically generated using `tools/lint --only=eslint --fix`. It was then modified by tabbott to contain only changes to a set of files that are unlikely to result in significant merge conflicts with any open pull request, excluding about 20 files. His plan is to merge the remaining changes with more precise care, potentially involving merging parts of conflicting pull requests before running the `eslint --fix` operation. Signed-off-by: Anders Kaseorg <[email protected]>
118 lines
2.9 KiB
JavaScript
118 lines
2.9 KiB
JavaScript
zrequire('people');
|
|
set_global('md5', function (s) {
|
|
return 'md5-' + s;
|
|
});
|
|
zrequire('user_pill');
|
|
|
|
set_global('page_params', {
|
|
});
|
|
|
|
const alice = {
|
|
email: '[email protected]',
|
|
user_id: 99,
|
|
full_name: 'Alice Barson',
|
|
};
|
|
|
|
const isaac = {
|
|
email: '[email protected]',
|
|
user_id: 102,
|
|
full_name: 'Isaac Newton',
|
|
};
|
|
|
|
const bogus_item = {
|
|
email: '[email protected]',
|
|
display_value: '[email protected]',
|
|
};
|
|
|
|
const isaac_item = {
|
|
email: '[email protected]',
|
|
display_value: 'Isaac Newton',
|
|
user_id: isaac.user_id,
|
|
img_src: 'https://secure.gravatar.com/avatar/[email protected]?d=identicon&s=50',
|
|
};
|
|
|
|
run_test('setup', () => {
|
|
people.add_in_realm(alice);
|
|
people.add_in_realm(isaac);
|
|
});
|
|
|
|
run_test('create_item', () => {
|
|
|
|
function test_create_item(email, current_items, expected_item) {
|
|
const item = user_pill.create_item_from_email(email, current_items);
|
|
assert.deepEqual(item, expected_item);
|
|
}
|
|
|
|
page_params.realm_is_zephyr_mirror_realm = true;
|
|
|
|
test_create_item('[email protected]', [], bogus_item);
|
|
test_create_item('[email protected]', [bogus_item], undefined);
|
|
|
|
test_create_item('[email protected]', [], isaac_item);
|
|
test_create_item('[email protected]', [isaac_item], undefined);
|
|
|
|
page_params.realm_is_zephyr_mirror_realm = false;
|
|
|
|
test_create_item('[email protected]', [], undefined);
|
|
test_create_item('[email protected]', [], isaac_item);
|
|
test_create_item('[email protected]', [isaac_item], undefined);
|
|
});
|
|
|
|
run_test('get_email', () => {
|
|
assert.equal(user_pill.get_email_from_item({email: '[email protected]'}), '[email protected]');
|
|
});
|
|
|
|
run_test('append', () => {
|
|
let appended;
|
|
let cleared;
|
|
|
|
function fake_append(opts) {
|
|
appended = true;
|
|
assert.equal(opts.email, isaac.email);
|
|
assert.equal(opts.display_value, isaac.full_name);
|
|
assert.equal(opts.user_id, isaac.user_id);
|
|
assert.equal(opts.img_src, isaac_item.img_src);
|
|
}
|
|
|
|
function fake_clear() {
|
|
cleared = true;
|
|
}
|
|
|
|
const pill_widget = {
|
|
appendValidatedData: fake_append,
|
|
clear_text: fake_clear,
|
|
};
|
|
|
|
user_pill.append_person({
|
|
person: isaac,
|
|
pill_widget: pill_widget,
|
|
});
|
|
|
|
assert(appended);
|
|
assert(cleared);
|
|
});
|
|
|
|
run_test('get_items', () => {
|
|
const items = [isaac_item, bogus_item];
|
|
|
|
const pill_widget = {
|
|
items: function () { return items; },
|
|
};
|
|
|
|
assert.deepEqual(user_pill.get_user_ids(pill_widget), [isaac.user_id]);
|
|
});
|
|
|
|
run_test('typeahead', () => {
|
|
const items = [isaac_item, bogus_item];
|
|
|
|
const pill_widget = {
|
|
items: function () { return items; },
|
|
};
|
|
|
|
// Both alice and isaac are in our realm, but isaac will be
|
|
// excluded by virtue of already being one of the widget items.
|
|
// And then bogus_item is just a red herring to test robustness.
|
|
const result = user_pill.typeahead_source(pill_widget);
|
|
assert.deepEqual(result, [alice]);
|
|
});
|