zulip/frontend_tests/node_tests/pm_list.js
Steve Howell dfab993e7d node tests: Avoid narrow_state mocking in pm_list* tests.
We now use narrow_state directly in pm_list and pm_list_data
tests, rather than mocking it with our `override*` helpers.

In some places I use an actual Filter() object, but
in places where the only testing concern is that the
active is narrow, I use a stub value.

We will continue to mock narrow_state in most places.
In addition to avoiding test-setup complications, we want
to avoid incidental line coverage on narrow_state that
only indirectly validates its behavior. Part of the
trickiness in avoiding narrow_state mocking is that
you often would have to introduce "real" Filter objects,
and the API for Filter objects is somewhat less than
ideal, and its wordiness can distract from the main
point of the tests.

Hopefully the changes here reflect the correct tradeoffs.
2022-03-16 11:57:58 -04:00

39 lines
1.0 KiB
JavaScript

"use strict";
const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const narrow_state = zrequire("narrow_state");
const pm_list = zrequire("pm_list");
run_test("update_dom_with_unread_counts", () => {
let counts;
// simulate an active narrow
narrow_state.set_current_filter("stub");
assert.equal(narrow_state.active(), true);
const total_count = $.create("total-count-stub");
const private_li = $(".top_left_private_messages .private_messages_header");
private_li.set_find_results(".unread_count", total_count);
counts = {
private_message_count: 10,
};
pm_list.update_dom_with_unread_counts(counts);
assert.equal(total_count.text(), "10");
assert.ok(total_count.visible());
counts = {
private_message_count: 0,
};
pm_list.update_dom_with_unread_counts(counts);
assert.equal(total_count.text(), "");
assert.ok(!total_count.visible());
});