<commit_before>var common = require('../common.js').common;

// Silence jslint errors about the global
/*global keep_pointer_in_view: true */
/*global process_visible_unread_messages: true */

function send_with_content(content) {
    common.send_message('stream', {
            stream:  'Verona',
            subject: 'unread test',
            content: content
    });
}

// Iago
common.start_and_log_in(undefined, {width: 1280, height: 600});
casper.then(function () {
    send_with_content('Iago unread test 0');
});
common.then_log_out();

// Othello
casper.open("http://localhost:9981/accounts/login");
common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});

casper.then(function () {
    // Force a pointer update so we no longer have a -1 pointer in the db
    var a = casper.evaluate(function () {
        $.post("/json/update_pointer", {pointer: 1});
    });
});

common.then_log_out();
common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});

send_with_content('Iago unread test 1');
send_with_content('Iago unread test 2');
send_with_content('Iago unread test 3');
send_with_content('Iago unread test 4');
send_with_content('Iago unread test 5');
send_with_content('Iago unread test 6');
send_with_content('Iago unread test 7');
send_with_content('Iago unread test 8');
send_with_content('Iago unread test 9');
send_with_content('Iago unread test 10');
send_with_content('Iago unread test 11');
send_with_content('Iago unread test 12');
send_with_content('Iago unread test 13');
common.then_log_out();

common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});
casper.then(function () {
    // Make sure we have 3 unread messages
    casper.test.assertSelectorHasText("a[href='#narrow/stream/Verona']", 'Verona', 'Unread count in sidebar is correct');
});

// Sending a message should not increase the count
send_with_content('Othello unread test 4');
send_with_content('Othello unread test 5');

casper.then(function () {
    function get_sidebar() { return casper.evaluate(function () { return $("a[href='#narrow/stream/Verona']").text(); }); }
    function get_sidebar_num() {
        var match = get_sidebar().match(/\w+\s*\((\d+)\)/);
        if (match) {
           return parseInt(match[1], 10);
        } else {
           return 0;
        }
    }

    function send_key(key) { casper.page.sendEvent('keypress', key); casper.wait(50); }

    function scroll_to(ypos) {
        // Changing the scroll position in phantomjs doesn't seem to trigger on-scroll
        // handlers, so unread messages are not handled
        casper.page.scrollPosition = {top: ypos, left: 0};
        casper.evaluate(function () { keep_pointer_in_view();
                                      process_visible_unread_messages(); });
    }
    var i = 0;
    scroll_to(0);

    // Due to font size and height variance across platforms, we are restricted from checking specific
    // unread counts as they might not be consistent. However, we do know that after scrolling
    // down more messages should be marked as read
    var sidebar_initial = get_sidebar_num();
    for(i = 0; i < 1500; i += 100) {
        scroll_to(i);
    }

    var sidebar_end = get_sidebar_num();
    casper.test.assert(sidebar_end < sidebar_initial, "Unread count in sidebar decreases after scrolling");

});
common.then_log_out();
common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});
casper.then(function () {
    casper.test.assertSelectorHasText("a[href='#narrow/stream/Verona']", 'Verona', 'Sidebar unread correct on login');
});

// Run the above queued actions.
casper.run(function () {
    casper.test.done(3);
});
<commit_msg>Remove deprecated parameter in Casper unread test<commit_after>var common = require('../common.js').common;

// Silence jslint errors about the global
/*global keep_pointer_in_view: true */
/*global process_visible_unread_messages: true */

function send_with_content(content) {
    common.send_message('stream', {
            stream:  'Verona',
            subject: 'unread test',
            content: content
    });
}

// Iago
common.start_and_log_in(undefined, {width: 1280, height: 600});
casper.then(function () {
    send_with_content('Iago unread test 0');
});
common.then_log_out();

// Othello
casper.open("http://localhost:9981/accounts/login");
common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});

casper.then(function () {
    // Force a pointer update so we no longer have a -1 pointer in the db
    var a = casper.evaluate(function () {
        $.post("/json/update_pointer", {pointer: 1});
    });
});

common.then_log_out();
common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});

send_with_content('Iago unread test 1');
send_with_content('Iago unread test 2');
send_with_content('Iago unread test 3');
send_with_content('Iago unread test 4');
send_with_content('Iago unread test 5');
send_with_content('Iago unread test 6');
send_with_content('Iago unread test 7');
send_with_content('Iago unread test 8');
send_with_content('Iago unread test 9');
send_with_content('Iago unread test 10');
send_with_content('Iago unread test 11');
send_with_content('Iago unread test 12');
send_with_content('Iago unread test 13');
common.then_log_out();

common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});
casper.then(function () {
    // Make sure we have 3 unread messages
    casper.test.assertSelectorHasText("a[href='#narrow/stream/Verona']", 'Verona', 'Unread count in sidebar is correct');
});

// Sending a message should not increase the count
send_with_content('Othello unread test 4');
send_with_content('Othello unread test 5');

casper.then(function () {
    function get_sidebar() { return casper.evaluate(function () { return $("a[href='#narrow/stream/Verona']").text(); }); }
    function get_sidebar_num() {
        var match = get_sidebar().match(/\w+\s*\((\d+)\)/);
        if (match) {
           return parseInt(match[1], 10);
        } else {
           return 0;
        }
    }

    function send_key(key) { casper.page.sendEvent('keypress', key); casper.wait(50); }

    function scroll_to(ypos) {
        // Changing the scroll position in phantomjs doesn't seem to trigger on-scroll
        // handlers, so unread messages are not handled
        casper.page.scrollPosition = {top: ypos, left: 0};
        casper.evaluate(function () { keep_pointer_in_view();
                                      process_visible_unread_messages(); });
    }
    var i = 0;
    scroll_to(0);

    // Due to font size and height variance across platforms, we are restricted from checking specific
    // unread counts as they might not be consistent. However, we do know that after scrolling
    // down more messages should be marked as read
    var sidebar_initial = get_sidebar_num();
    for(i = 0; i < 1500; i += 100) {
        scroll_to(i);
    }

    var sidebar_end = get_sidebar_num();
    casper.test.assert(sidebar_end < sidebar_initial, "Unread count in sidebar decreases after scrolling");

});
common.then_log_out();
common.then_log_in({username: '<EMAIL>', password: '<PASSWORD>'});
casper.then(function () {
    casper.test.assertSelectorHasText("a[href='#narrow/stream/Verona']", 'Verona', 'Sidebar unread correct on login');
});

// Run the above queued actions.
casper.run(function () {
    casper.test.done();
});

{'fraction_non_alphanumeric': 0.14318769565809175, 'fraction_numerical': 0.014019327616714304, 'mean_word_length': 3.843770599868161, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7646964', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2290, 'n_words': 598}