/* global AJS:false */
AJS.test.require("com.atlassian.bitbucket.server.bitbucket-web:progress-bar", function() {


    module('widget-progress-bar', {
        setup : function() {
            this.$fixture = jQuery('#qunit-fixture').css({
                width : '800px',
                height: '600px'
            });
        },
        teardown : function() {
        }
    });

    test('Test constructor returns a ProgressBar', function() {
        var ProgressBar = require('bitbucket/internal/widget/progress-bar');
        var $barElement = jQuery(bitbucket.internal.widget.progressBar({
            percentage: 0,
            message: ''
        }));
        var bar = new ProgressBar($barElement);
        ok(bar);
        ok(new ProgressBar($barElement) instanceof ProgressBar);

        bar = ProgressBar($barElement);
        ok(bar);
        ok(ProgressBar($barElement) instanceof ProgressBar);
    });

    test('Test percentage method', function() {
        var ProgressBar = require('bitbucket/internal/widget/progress-bar');
        var $barElement = jQuery(bitbucket.internal.widget.progressBar({
            percentage: 0,
            message: ''
        }));
        var bar = ProgressBar($barElement);
        ok(bar);
        strictEqual(bar.percentage(), 0);
        ok(bar.percentage(20) === bar);
        strictEqual(bar.percentage(), 20);
        ok(bar.percentage(0) === bar);
        strictEqual(bar.percentage(), 0);
        ok(bar.percentage(-5) === bar);
        strictEqual(bar.percentage(), 0);
        ok(bar.percentage(100) === bar);
        strictEqual(bar.percentage(), 100);
        ok(bar.percentage(120) === bar);
        strictEqual(bar.percentage(), 100);
    });

    test('Test message method when message p tag already exists', function() {
        var ProgressBar = require('bitbucket/internal/widget/progress-bar');
        var $barElement = jQuery(bitbucket.internal.widget.progressBar({
            percentage: 0,
            message: ''
        }));
        var bar = ProgressBar($barElement);
        ok(bar);
        strictEqual(bar.message(), '');
        ok(bar.message('Hello') === bar);
        strictEqual(bar.message(), 'Hello');
    });

    test('Test message method when progress bar has no message', function() {
        var ProgressBar = require('bitbucket/internal/widget/progress-bar');
        var $barElement = jQuery(bitbucket.internal.widget.progressBar({
            percentage: 0
        }));
        var bar = ProgressBar($barElement);
        ok(bar);
        strictEqual(bar.message(), '');
        ok(bar.message('Hello') === bar);
        strictEqual(bar.message(), 'Hello');
    });

    test('Test message method when message p tag already exists', function() {
        var ProgressBar = require('bitbucket/internal/widget/progress-bar');
        var $barElement = jQuery(bitbucket.internal.widget.progressBar({
            percentage: 0,
            message: ''
        }));
        var bar = ProgressBar($barElement);
        ok(bar);
        strictEqual(bar.message(), '');
        ok(bar.message('Hello') === bar);
        strictEqual(bar.message(), 'Hello');
    });
});