set_global('$', global.make_zjquery());

add_dependencies({
    Handlebars: 'handlebars',
    templates: 'js/templates',
    hash_util: 'js/hash_util',
    hashchange: 'js/hashchange',
    narrow: 'js/narrow',
    people: 'js/people',
});

set_global('message_store', {
    recent_private_messages: new global.Array(),
});

set_global('unread', {});

// TODO: move pm_list-related tests to their own module
var pm_list = require('js/pm_list.js');

global.compile_template('sidebar_private_message_list');

var alice = {
    email: 'alice@zulip.com',
    user_id: 101,
    full_name: 'Alice',
};
var bob = {
    email: 'bob@zulip.com',
    user_id: 102,
    full_name: 'Bob',
};
var me = {
    email: 'me@zulip.com',
    user_id: 103,
    full_name: 'Me Myself',
};
global.people.add_in_realm(alice);
global.people.add_in_realm(bob);
global.people.add_in_realm(me);
global.people.initialize_current_user(me.user_id);

(function test_build_private_messages_list() {
    var active_conversation = "alice@zulip.com,bob@zulip.com";
    var max_conversations = 5;


    var conversations = {user_ids_string: '101,102',
                         timestamp: 0 };
    global.message_store.recent_private_messages.push(conversations);

    global.unread.num_unread_for_person = function () {
        return 1;
    };

    var template_data;

    global.templates.render = function (template_name, data) {
        assert.equal(template_name, 'sidebar_private_message_list');
        template_data = data;
    };

    pm_list._build_private_messages_list(active_conversation, max_conversations);

    var expected_data = {
        messages: [
            {
                recipients: 'Alice, Bob',
                user_ids_string: '101,102',
                unread: 1,
                is_zero: false,
                zoom_out_hide: false,
                url: '#narrow/pm-with/101,102-group',
            },
        ],
        zoom_class: 'zoomed-out',
        want_show_more_messages_links: false,
    };

    assert.deepEqual(template_data, expected_data);

}());

@@ -342,16 +342,45 @@
 d', %7B%7D);
+%0Aset_global('unread_ui', %7B%7D);
 %0A%0A// TOD
@@ -2072,12 +2072,1242 @@
 ta);%0A%0A%7D());%0A
+%0A(function test_update_dom_with_unread_counts() %7B%0A    var total_value = $('total-value-stub');%0A    var total_count = $('total-count-stub');%0A    var private_li = $(%22#global_filters %3E li%5Bdata-name='private'%5D%22);%0A    private_li.add_child('.count', total_count);%0A    total_count.add_child('.value', total_value);%0A%0A    var child_value = $('child-value-stub');%0A    var child_count = $('child-count-stub');%0A    var child_li = $('child-li-stub');%0A    private_li.add_child(%22li%5Bdata-user-ids-string='101,102'%5D%22, child_li);%0A    child_li.add_child('.private_message_count', child_count);%0A    child_count.add_child('.value', child_value);%0A%0A    var pm_count = new Dict();%0A    var user_ids_string = '101,102';%0A    pm_count.set(user_ids_string, 7);%0A%0A    var counts = %7B%0A        private_message_count: 10,%0A        pm_count: pm_count,%0A    %7D;%0A%0A    var toggle_button_set;%0A    unread_ui.set_count_toggle_button = function (elt, count) %7B%0A        toggle_button_set = true;%0A        assert.equal(count, 10);%0A    %7D;%0A%0A    unread_ui.animate_private_message_changes = function () %7B%7D;%0A%0A    pm_list.update_dom_with_unread_counts(counts);%0A%0A    assert(toggle_button_set);%0A    assert.equal(child_value.text(), '7');%0A    assert.equal(total_value.text(), '10');%0A%7D());%0A

Add test_update_dom_with_unread_counts().