mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
We now treat util like a leaf module and use "require" to import it everywhere it's used. An earlier version of this commit moved util into our "shared" library, but we decided to wait on that. Once we're ready to do that, we should only need to do a simple search/replace on various require/zrequire statements plus a small tweak to one of the custom linter checks. It turns out we don't really need util.js for our most immediate code-sharing goal, which is to reuse our markdown code on mobile. There's a little bit of cleanup still remaining to break the dependency, but it's minor. The util module still calls the global blueslip module in one place, but that code is about to be removed in the next few commits. I am pretty confident that once we start sharing things like the typeahead code more aggressively, we'll start having dependencies on util. The module is barely more than 300 lines long, so we'll probably just move the whole thing into shared rather than break it apart. Also, we can continue to nibble away at the cruftier parts of the module.
102 lines
3.0 KiB
JavaScript
102 lines
3.0 KiB
JavaScript
set_global('i18n', global.stub_i18n);
|
|
|
|
zrequire('stream_data');
|
|
zrequire('stream_sort');
|
|
const with_overrides = global.with_overrides;
|
|
|
|
run_test('no_subscribed_streams', () => {
|
|
assert.equal(stream_sort.sort_groups(''), undefined);
|
|
assert.equal(stream_sort.first_stream_id(), undefined);
|
|
});
|
|
|
|
const scalene = {
|
|
subscribed: true,
|
|
name: 'scalene',
|
|
stream_id: 1,
|
|
pin_to_top: true,
|
|
};
|
|
const fast_tortoise = {
|
|
subscribed: true,
|
|
name: 'fast tortoise',
|
|
stream_id: 2,
|
|
pin_to_top: false,
|
|
};
|
|
const pneumonia = {
|
|
subscribed: true,
|
|
name: 'pneumonia',
|
|
stream_id: 3,
|
|
pin_to_top: false,
|
|
};
|
|
const clarinet = {
|
|
subscribed: true,
|
|
name: 'clarinet',
|
|
stream_id: 4,
|
|
pin_to_top: false,
|
|
};
|
|
const weaving = {
|
|
subscribed: false,
|
|
name: 'weaving',
|
|
stream_id: 5,
|
|
pin_to_top: false,
|
|
};
|
|
|
|
stream_data.add_sub(scalene);
|
|
stream_data.add_sub(fast_tortoise);
|
|
stream_data.add_sub(pneumonia);
|
|
stream_data.add_sub(clarinet);
|
|
stream_data.add_sub(weaving);
|
|
|
|
function sort_groups(query) {
|
|
const streams = stream_data.subscribed_streams();
|
|
return stream_sort.sort_groups(streams, query);
|
|
}
|
|
|
|
with_overrides(function (override) {
|
|
override('stream_data.is_active', function (sub) {
|
|
return sub.name !== "pneumonia";
|
|
});
|
|
|
|
// Test sorting into categories/alphabetized
|
|
let sorted = sort_groups("");
|
|
assert.deepEqual(sorted.pinned_streams, ['scalene']);
|
|
assert.deepEqual(sorted.normal_streams, ['clarinet', 'fast tortoise']);
|
|
assert.deepEqual(sorted.dormant_streams, ['pneumonia']);
|
|
|
|
// Test cursor helpers.
|
|
assert.equal(stream_sort.first_stream_id(), scalene.stream_id);
|
|
|
|
assert.equal(stream_sort.prev_stream_id(scalene.stream_id), undefined);
|
|
assert.equal(stream_sort.prev_stream_id(clarinet.stream_id), scalene.stream_id);
|
|
|
|
assert.equal(stream_sort.next_stream_id(fast_tortoise.stream_id), pneumonia.stream_id);
|
|
assert.equal(stream_sort.next_stream_id(pneumonia.stream_id), undefined);
|
|
|
|
// Test filtering
|
|
sorted = sort_groups("s");
|
|
assert.deepEqual(sorted.pinned_streams, ['scalene']);
|
|
assert.deepEqual(sorted.normal_streams, []);
|
|
assert.deepEqual(sorted.dormant_streams, []);
|
|
|
|
assert.equal(stream_sort.prev_stream_id(clarinet.stream_id), undefined);
|
|
|
|
assert.equal(stream_sort.next_stream_id(clarinet.stream_id), undefined);
|
|
|
|
// Test searching entire word, case-insensitive
|
|
sorted = sort_groups("PnEuMoNiA");
|
|
assert.deepEqual(sorted.pinned_streams, []);
|
|
assert.deepEqual(sorted.normal_streams, []);
|
|
assert.deepEqual(sorted.dormant_streams, ['pneumonia']);
|
|
|
|
// Test searching part of word
|
|
sorted = sort_groups("tortoise");
|
|
assert.deepEqual(sorted.pinned_streams, []);
|
|
assert.deepEqual(sorted.normal_streams, ['fast tortoise']);
|
|
assert.deepEqual(sorted.dormant_streams, []);
|
|
|
|
// Test searching stream with spaces
|
|
sorted = sort_groups("fast t");
|
|
assert.deepEqual(sorted.pinned_streams, []);
|
|
assert.deepEqual(sorted.normal_streams, ['fast tortoise']);
|
|
assert.deepEqual(sorted.dormant_streams, []);
|
|
});
|