"use strict";
var log_filter_1 = require("../../mobile/log-filter");
var yok_1 = require("../../yok");
var device_platforms_constants_1 = require("../../mobile/device-platforms-constants");
var logging_levels_1 = require("../../mobile/logging-levels");
var assert = require("assert");
function createTestInjector() {
    var testInjector = new yok_1.Yok();
    testInjector.register("injector", testInjector);
    testInjector.register("devicePlatformsConstants", device_platforms_constants_1.DevicePlatformsConstants);
    testInjector.register("loggingLevels", logging_levels_1.LoggingLevels);
    testInjector.register("logFilter", log_filter_1.LogFilter);
    testInjector.register("iOSLogFilter", {
        filterData: function (data, logLevel, pid) {
            return "ios: " + data + " " + logLevel;
        }
    });
    testInjector.register("androidLogFilter", {
        filterData: function (data, logLevel, pid) {
            return "android: " + data + " " + logLevel;
        }
    });
    return testInjector;
}
describe("logFilter", function () {
    var testInjector, logFilter, testData = "testData", infoLogLevel = "INFO", fullLogLevel = "FULL", androidInfoTestData = "android: " + testData + " " + infoLogLevel, androidFullTestData = "android: " + testData + " " + fullLogLevel, iosInfoTestData = "ios: " + testData + " " + infoLogLevel, iosFullTestData = "ios: " + testData + " " + fullLogLevel, logLevel = null;
    beforeEach(function () {
        testInjector = createTestInjector();
        logFilter = testInjector.resolve("logFilter");
        logLevel = null;
    });
    describe("loggingLevel", function () {
        it("verify default value is INFO", function () {
            assert.deepEqual(logFilter.loggingLevel, infoLogLevel, "Default level should be INFO.");
        });
        it("sets default value to FULL", function () {
            logFilter.loggingLevel = fullLogLevel;
            assert.deepEqual(logFilter.loggingLevel, fullLogLevel, "Default level should be FULL.");
        });
        it("keeps default value to INFO when invalid value is passed", function () {
            logFilter.loggingLevel = "invalidValue";
            assert.deepEqual(logFilter.loggingLevel, infoLogLevel, "Default level should be INFO.");
        });
        it("keeps default value to INFO when falsey value is passed", function () {
            logFilter.loggingLevel = null;
            assert.deepEqual(logFilter.loggingLevel, infoLogLevel, "Default level should be INFO.");
        });
    });
    describe("filterData", function () {
        describe("when logLevel is not specified and default log level is not changed", function () {
            it("returns same data when platform is not correct", function () {
                var actualData = logFilter.filterData("invalidPlatform", testData);
                assert.deepEqual(actualData, testData);
            });
            it("returns same data when platform is not passed", function () {
                var actualData = logFilter.filterData(null, testData);
                assert.deepEqual(actualData, testData);
            });
            it("returns correct data when platform is android", function () {
                var actualData = logFilter.filterData("android", testData);
                assert.deepEqual(actualData, androidInfoTestData);
            });
            it("returns correct data when platform is ios", function () {
                var actualData = logFilter.filterData("ios", testData);
                assert.deepEqual(actualData, iosInfoTestData);
            });
        });
        describe("when logLevel is not specified and default log level is set to full", function () {
            beforeEach(function () { return logFilter.loggingLevel = fullLogLevel; });
            it("returns same data when platform is not correct", function () {
                var actualData = logFilter.filterData("invalidPlatform", testData);
                assert.deepEqual(actualData, testData);
            });
            it("returns correct data when platform is android", function () {
                var actualData = logFilter.filterData("android", testData);
                assert.deepEqual(actualData, androidFullTestData);
            });
            it("returns correct data when platform is ios", function () {
                var actualData = logFilter.filterData("ios", testData);
                assert.deepEqual(actualData, iosFullTestData);
            });
        });
        describe("when logLevel is INFO", function () {
            beforeEach(function () { return logLevel = infoLogLevel; });
            it("returns same data when platform is not correct", function () {
                var actualData = logFilter.filterData("invalidPlatform", testData, null, logLevel);
                assert.deepEqual(actualData, testData, logLevel);
            });
            it("returns correct data when platform is android", function () {
                var actualData = logFilter.filterData("android", testData, null, logLevel);
                assert.deepEqual(actualData, androidInfoTestData);
            });
            it("returns correct data when platform is ios", function () {
                var actualData = logFilter.filterData("ios", testData, null, logLevel);
                assert.deepEqual(actualData, iosInfoTestData);
            });
        });
        describe("when logLevel is FULL", function () {
            beforeEach(function () { return logLevel = fullLogLevel; });
            it("returns same data when platform is not correct", function () {
                var actualData = logFilter.filterData("invalidPlatform", testData, null, logLevel);
                assert.deepEqual(actualData, testData, logLevel);
            });
            it("returns correct data when platform is android", function () {
                var actualData = logFilter.filterData("android", testData, null, logLevel);
                assert.deepEqual(actualData, androidFullTestData);
            });
            it("returns correct data when platform is ios", function () {
                var actualData = logFilter.filterData("ios", testData, null, logLevel);
                assert.deepEqual(actualData, iosFullTestData);
            });
        });
    });
});
