node_tests: Set narrow_state instead of overriding in stream_events.

Previously, we were overriding narrow_state.is_for_stream_id() to make
sure we test the functions we intend to.

In this commit we:
  * zrequire('narrow_state')
  * set the filter to "stream:frontend" before the test cases which
    were overriding is_for_stream_id to return true (and remove the
    overrides).
  * reset_current_filter() at the end of the above cases (and remove
    the lines overriding is_for_stream_id to return false)

This is a prep commit to adding live update for sub_count in the
navbar.
This commit is contained in:
YashRE42 2020-06-23 14:19:55 +00:00 committed by Tim Abbott
parent 0667925c93
commit db9f2eda5d

View File

@ -9,6 +9,8 @@ set_global('settings_notifications', _settings_notifications);
zrequire('people');
zrequire('stream_data');
zrequire('stream_events');
zrequire('Filter', 'js/filter');
zrequire('narrow_state');
const with_overrides = global.with_overrides;
const george = {
@ -29,6 +31,13 @@ const frontend = {
stream_data.add_sub(frontend);
const frontend_filter_terms = [
{ operator: 'stream', operand: 'frontend' },
];
const frontend_filter = new Filter(frontend_filter_terms);
run_test('update_property', () => {
// Invoke error for non-existent stream/property
with_overrides((override) => {
@ -204,10 +213,10 @@ run_test('marked_subscribed', () => {
stream_data.update_calculated_fields = noop;
set_global('subs', { update_settings_for_subscribed: noop });
set_global('narrow_state', { is_for_stream_id: noop });
set_global('overlays', { streams_open: return_true });
// Test basic dispatching and updating stream color
narrow_state.set_current_filter(frontend_filter);
with_overrides((override) => {
let args;
let list_updated = false;
@ -218,7 +227,6 @@ run_test('marked_subscribed', () => {
override('stream_color.update_stream_color', noop);
override('stream_list.add_sidebar_row', stream_list_stub.f);
override('message_util.do_unread_count_updates', message_util_stub.f);
override('narrow_state.is_for_stream_id', () => true);
override('current_msg_list.update_trailing_bookend', () => {
list_updated = true;
});
@ -235,6 +243,7 @@ run_test('marked_subscribed', () => {
assert.equal(frontend.color, 'blue');
});
narrow_state.reset_current_filter();
// Test assigning generated color
with_overrides((override) => {
@ -245,8 +254,8 @@ run_test('marked_subscribed', () => {
warnings += 1;
});
// narrow state is undefined
global.with_stub((stub) => {
override('narrow_state.is_for_stream_id', noop);
override('message_util.do_unread_count_updates', noop);
override('stream_list.add_sidebar_row', noop);
override('stream_color.update_stream_color', noop);
@ -259,9 +268,8 @@ run_test('marked_subscribed', () => {
});
});
narrow_state.is_for_stream_id = () => false;
// Test assigning subscriber emails
// narrow state is undefined
with_overrides((override) => {
override('stream_color.update_stream_color', noop);
override('message_util.do_unread_count_updates', noop);
@ -337,10 +345,10 @@ run_test('mark_unsubscribed', () => {
});
// Test update bookend and remove done event
narrow_state.set_current_filter(frontend_filter);
with_overrides((override) => {
override('stream_data.unsubscribe_myself', noop);
override('subs.update_settings_for_unsubscribed', noop);
override('narrow_state.is_for_stream_id', () => true);
let updated = false;
override('current_msg_list.update_trailing_bookend', () => {
@ -357,6 +365,7 @@ run_test('mark_unsubscribed', () => {
assert.equal(updated, true);
assert.equal(event_triggered, true);
});
narrow_state.reset_current_filter();
});
stream_data.clear_subscriptions();