{% extends "base.html" %}
{% load djblets_extensions pipeline %}

{% block title %}JavaScript Unit Tests{% endblock %}

{% block css %}
{%  stylesheet "js-tests" %}
{% endblock %}

{% block js_extensions %}{% endblock %}

{% block scripts-post %}
{%  javascript "djblets-config-forms" %}
{%  javascript "djblets-forms" %}
{%  javascript "config-forms" %}
{%  javascript "reviews" %}
{%  javascript "review-request-page" %}
{%  javascript "newReviewRequest" %}
{%  javascript "js-test-libs" %}

{%  block scripts-test %}{% endblock %}

<script>
$(document).ready(function() {
    RB.ajaxOptions.enableQueuing = false;
    RB.ajaxOptions.enableIndicator = false;

    // Disable animations so we don't have to worry about them in tests.
    $.fx.off = true;

    // Disable throttling of callbacks when possible.
    _.throttle = function(cb) {
        return cb;
    };

    window.$testsScratch = $("<div id='tests-scratch'/>")
        .width(1)
        .height(1)
        .move(-10000, -10000, 'absolute')
        .appendTo(document.body);

    beforeEach(function() {
        /*
         * Set the session to be authenticated by default. If tests need
         * it to be unauthenticated, they can reset this.
         */
        RB.UserSession.instance = null;
        RB.UserSession.create({
            authenticated: true,
            commentsOpenAnIssue: true,
            username: 'testuser',
            userPageURL: '{{SITE_ROOT}}users/test/'
        });

        /*
         * Capture all assertions, so we can sanely inspect them.
         * We don't want to call the original version, though, or we'll
         * possibly get errors in the console.
         *
         * We do this after creating the UserSession, since that will also
         * assert.
         */
        spyOn(console, 'assert').and.callFake(function(condition, msg) {
            if (!condition) {
                throw Error(msg);
            }
        });

        /*
         * We don't have actual gravatar sources when running tests, so avoid
         * spurious error output and HTTP requests.
         */
        spyOn($.fn, 'retinaGravatar')
            .and.callFake(function() { return this; });
    });

    afterEach(function() {
        $testsScratch.empty();
    });
});
</script>
{% endblock %}
