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

    var __wrmData = {};
    __wrmData['com.atlassian.bitbucket.server.config-wrm-data:attachment.upload.max.size.data'] = {
        value: 10485760,
        type: 'NUMBER'
    };

    // TODO Yuck - we need a better way of mocking out WRM data, or fix WRM for qunit tests
    // https://ecosystem.atlassian.net/browse/PLUGWEB-57
    window.WRM = {
        data : {
            claim: function(key){
                return __wrmData[key];
            }
        }
    };

var $ = jQuery;
var FileContent = require('bitbucket/internal/feature/file-content');
var modeAdd = "added";
var modeRem = "removed";

module('file-content');

test('Correct file state lozenge is created', function () {
    var fileContent = new FileContent();

    //   srcExecutable  executable   result
    //        null         null
    //        null         true        +x (addition)
    //        null         false          (addition)
    //
    //        true         null           (deletion)
    //        true         true
    //        true         false       -x
    //
    //        false        null           (deletion)
    //        false        true        +x
    //        false        false

    var getLozenge = function (srcExecutable, executable) {
        var fileChange = {
            getSrcExecutable: function () { return srcExecutable; },
            getExecutable: function () { return executable; }
        };
        return fileContent.getFileChangedModeLozenge(fileChange);
    };

    equal(getFileChangeLozengeType(getLozenge(null, null)), null, "No lozenge – invalid args");
    equal(getFileChangeLozengeType(getLozenge(null, true)), modeAdd, "Add lozenge – new file with +x");
    equal(getFileChangeLozengeType(getLozenge(null, false)), null, "No lozenge – new file without +x");
    equal(getFileChangeLozengeType(getLozenge(undefined, true)), modeAdd, "Add lozenge – new file with +x");
    equal(getFileChangeLozengeType(getLozenge(undefined, false)), null, "No lozenge – new file without +x");

    equal(getFileChangeLozengeType(getLozenge(true, null)), null, "No lozenge – deleted file with +x");
    equal(getFileChangeLozengeType(getLozenge(true, undefined)), null, "No lozenge – deleted file with +x");
    equal(getFileChangeLozengeType(getLozenge(true, true)), null, "No lozenge – no +x change");
    equal(getFileChangeLozengeType(getLozenge(true, false)), modeRem, "Remove lozenge – removed +x");

    equal(getFileChangeLozengeType(getLozenge(false, null)), null, "No lozenge – deleted file without +x");
    equal(getFileChangeLozengeType(getLozenge(false, undefined)), null, "No lozenge – deleted file without +x");
    equal(getFileChangeLozengeType(getLozenge(false, true)), modeAdd, "Add lozenge – added +x");
    equal(getFileChangeLozengeType(getLozenge(false, false)), null, "No lozenge – no +x change");
});

var getFileChangeLozengeType = function (lozenge) {
    if (!lozenge) {
        return null;
    }
    if ($(lozenge).hasClass("change-mode-added")) {
        return modeAdd;
    } else if ($(lozenge).hasClass("change-mode-removed")) {
        return modeRem;
    }
    throw new Error("Could not determine type of mode change");
};


});