mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
test cleanup: Extract a matcher() helper.
This commit is contained in:
@@ -626,39 +626,46 @@ run_test('initialize', () => {
|
|||||||
assert.equal(actual_value, expected_value);
|
assert.equal(actual_value, expected_value);
|
||||||
|
|
||||||
// options.matcher()
|
// options.matcher()
|
||||||
options.query = 'el'; // Matches both "othELlo" and "cordELia"
|
|
||||||
assert.equal(options.matcher(othello), true);
|
|
||||||
assert.equal(options.matcher(cordelia), true);
|
|
||||||
|
|
||||||
options.query = 'bender'; // Doesn't exist
|
function matcher(query, person) {
|
||||||
assert.equal(options.matcher(othello), false);
|
options.query = query;
|
||||||
assert.equal(options.matcher(cordelia), false);
|
return options.matcher(person);
|
||||||
|
}
|
||||||
|
|
||||||
options.query = 'gael';
|
let query;
|
||||||
assert.equal(options.matcher(gael), true);
|
query = 'el'; // Matches both "othELlo" and "cordELia"
|
||||||
|
assert.equal(matcher(query, othello), true);
|
||||||
|
assert.equal(matcher(query, cordelia), true);
|
||||||
|
|
||||||
options.query = 'Gaël';
|
query = 'bender'; // Doesn't exist
|
||||||
assert.equal(options.matcher(gael), true);
|
assert.equal(matcher(query, othello), false);
|
||||||
|
assert.equal(matcher(query, cordelia), false);
|
||||||
|
|
||||||
options.query = 'gaël';
|
query = 'gael';
|
||||||
assert.equal(options.matcher(gael), true);
|
assert.equal(matcher(query, gael), true);
|
||||||
|
|
||||||
|
query = 'Gaël';
|
||||||
|
assert.equal(matcher(query, gael), true);
|
||||||
|
|
||||||
|
query = 'gaël';
|
||||||
|
assert.equal(matcher(query, gael), true);
|
||||||
|
|
||||||
// Don't make suggestions if the last name only has whitespaces
|
// Don't make suggestions if the last name only has whitespaces
|
||||||
// (we're between typing names).
|
// (we're between typing names).
|
||||||
options.query = 'othello@zulip.com, ';
|
query = 'othello@zulip.com, ';
|
||||||
assert.equal(options.matcher(othello), false);
|
assert.equal(matcher(query, othello), false);
|
||||||
assert.equal(options.matcher(cordelia), false);
|
assert.equal(matcher(query, cordelia), false);
|
||||||
|
|
||||||
// options.query = 'othello@zulip.com,, , cord';
|
// query = 'othello@zulip.com,, , cord';
|
||||||
options.query = 'cord';
|
query = 'cord';
|
||||||
assert.equal(options.matcher(othello), false);
|
assert.equal(matcher(query, othello), false);
|
||||||
assert.equal(options.matcher(cordelia), true);
|
assert.equal(matcher(query, cordelia), true);
|
||||||
|
|
||||||
// If the user is already in the list, typeahead doesn't include it
|
// If the user is already in the list, typeahead doesn't include it
|
||||||
// again.
|
// again.
|
||||||
options.query = 'cordelia@zulip.com, cord';
|
query = 'cordelia@zulip.com, cord';
|
||||||
assert.equal(options.matcher(othello), false);
|
assert.equal(matcher(query, othello), false);
|
||||||
assert.equal(options.matcher(cordelia), false);
|
assert.equal(matcher(query, cordelia), false);
|
||||||
|
|
||||||
// options.sorter()
|
// options.sorter()
|
||||||
//
|
//
|
||||||
@@ -684,9 +691,9 @@ run_test('initialize', () => {
|
|||||||
// Adds a `no break-space` at the end. This should fail
|
// Adds a `no break-space` at the end. This should fail
|
||||||
// if there wasn't any logic replacing `no break-space`
|
// if there wasn't any logic replacing `no break-space`
|
||||||
// with normal space.
|
// with normal space.
|
||||||
options.query = 'cordelia' + String.fromCharCode(160);
|
query = 'cordelia' + String.fromCharCode(160);
|
||||||
assert.equal(options.matcher(cordelia), true);
|
assert.equal(matcher(query, cordelia), true);
|
||||||
assert.equal(options.matcher(othello), false);
|
assert.equal(matcher(query, othello), false);
|
||||||
|
|
||||||
const event = {
|
const event = {
|
||||||
target: '#doesnotmatter',
|
target: '#doesnotmatter',
|
||||||
|
|||||||
Reference in New Issue
Block a user