"use strict";
var src_1 = require('../../../src');
function run() {
    it('should set activator setting to none for old Android Browser on a linux device', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
        platform.setNavigatorPlatform('linux');
        platform.load(null);
        config.setPlatform(platform);
        expect(config.get('activator')).toEqual('none');
    });
    it('should set activator setting to ripple for Android dev tools simulation on a mac', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
        platform.setNavigatorPlatform('MacIntel');
        platform.load(null);
        config.setPlatform(platform);
        expect(config.get('activator')).toEqual('ripple');
    });
    it('should set activator setting to none for Android Chrome versions below v36 on a linux device', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1650.59 Mobile Safari/537.36');
        platform.setNavigatorPlatform('linux');
        platform.load(null);
        config.setPlatform(platform);
        expect(config.get('activator')).toEqual('none');
    });
    it('should set activator setting to ripple for Android Chrome v36 and above on a linux device', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1650.59 Mobile Safari/537.36');
        platform.setNavigatorPlatform('linux');
        platform.load(null);
        config.setPlatform(platform);
        expect(config.get('activator')).toEqual('ripple');
    });
    it('should set activator setting to ripple for Android v5.0 and above on a linux device not using Chrome', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUserAgent('Mozilla/5.0 (Android 5.0; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
        platform.setNavigatorPlatform('linux');
        platform.load(null);
        config.setPlatform(platform);
        expect(config.get('activator')).toEqual('ripple');
    });
    it('should set activator setting to none for Android versions below v5.0 on a linux device not using Chrome', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUserAgent('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
        platform.setNavigatorPlatform('linux');
        platform.load(null);
        config.setPlatform(platform);
        expect(config.get('activator')).toEqual('none');
    });
    it('should create a new Config instace when no confg passed in ionicProviders', function () {
        var providers = src_1.ionicProviders();
        var config = providers.find(function (provider) { return provider.useValue instanceof src_1.Config; }).useValue;
        expect(config.get('mode')).toEqual('md');
    });
    it('should used passed in Config instance in ionicProviders', function () {
        var userConfig = new src_1.Config({
            mode: 'configInstance'
        });
        var providers = src_1.ionicProviders({ config: userConfig });
        var config = providers.find(function (provider) { return provider.useValue instanceof src_1.Config; }).useValue;
        expect(config.get('mode')).toEqual('configInstance');
    });
    it('should create new Config instance from config object in ionicProviders', function () {
        var providers = src_1.ionicProviders({ config: {
                mode: 'configObj'
            } });
        var config = providers.find(function (provider) { return provider.useValue instanceof src_1.Config; }).useValue;
        expect(config.get('mode')).toEqual('configObj');
    });
    it('should override mode settings', function () {
        var config = new src_1.Config({
            mode: 'md'
        });
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('md');
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should override mode settings from platforms setting', function () {
        var config = new src_1.Config({
            platforms: {
                ios: {
                    mode: 'md'
                }
            }
        });
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('md');
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should get boolean value from querystring', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform();
        platform.setUrl('http://biff.com/?ionicanimate=true');
        config.setPlatform(platform);
        expect(config.get('animate')).toEqual(true);
        config = new src_1.Config();
        platform = new src_1.Platform();
        platform.setUrl('http://biff.com/?ionicanimate=false');
        config.setPlatform(platform);
        expect(config.get('animate')).toEqual(false);
    });
    it('should get value from case insensitive querystring key', function () {
        var config = new src_1.Config({
            mode: 'a'
        });
        var platform = new src_1.Platform();
        platform.setUrl('http://biff.com/?ionicConfigKey=b');
        config.setPlatform(platform);
        expect(config.get('configKey')).toEqual('b');
    });
    it('should get value from querystring', function () {
        var config = new src_1.Config({
            mode: 'modeA'
        });
        var platform = new src_1.Platform();
        platform.setUrl('http://biff.com/?ionicmode=modeB');
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('modeB');
    });
    it('should override mode platform', function () {
        var config = new src_1.Config({
            mode: 'modeA',
            platforms: {
                mobile: {
                    mode: 'modeB'
                },
                ios: {
                    mode: 'modeC'
                }
            }
        });
        var platform = new src_1.Platform(['mobile']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('modeB');
    });
    it('should override mode', function () {
        var config = new src_1.Config({
            mode: 'modeA'
        });
        var platform = new src_1.Platform(['core']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('modeA');
    });
    it('should get user settings after user platform settings', function () {
        var config = new src_1.Config({
            hoverCSS: true
        });
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        expect(config.get('hoverCSS')).toEqual(true);
    });
    it('should get md mode for core platform', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['core']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('md');
    });
    it('should get ios mode for ipad platform', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['mobile', 'ios', 'ipad', 'tablet']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('ios');
    });
    it('should get md mode for windows platform', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['mobile', 'windows']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('wp');
    });
    it('should get md mode for android platform', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['mobile', 'android']);
        config.setPlatform(platform);
        expect(config.get('mode')).toEqual('md');
    });
    it('should override ios mode config with user platform setting', function () {
        var config = new src_1.Config({
            tabbarPlacement: 'hide',
            platforms: {
                ios: {
                    tabbarPlacement: 'top'
                }
            }
        });
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should override ios mode config with user setting', function () {
        var config = new src_1.Config({
            tabbarPlacement: 'top'
        });
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should get setting from md mode', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['android']);
        config.setPlatform(platform);
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should get setting from ios mode', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        expect(config.get('tabbarPlacement')).toEqual('bottom');
    });
    it('should set/get platform setting from set()', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        config.set('tabbarPlacement', 'bottom');
        config.set('ios', 'tabbarPlacement', 'top');
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should set/get setting from set()', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        config.set('tabbarPlacement', 'top');
        expect(config.get('tabbarPlacement')).toEqual('top');
    });
    it('should set ios platform settings from settings()', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        config.settings('ios', {
            key: 'iosValue'
        });
        expect(config.get('key')).toEqual('iosValue');
    });
    it('should set/get mobile setting even w/ higher priority ios', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['mobile', 'ios']);
        config.setPlatform(platform);
        config.settings({
            key: 'defaultValue',
            platforms: {
                mobile: {
                    key: 'mobileValue'
                }
            }
        });
        expect(config.get('key')).toEqual('mobileValue');
    });
    it('should set/get mobile setting even w/ higher priority ios', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['mobile', 'ios']);
        config.setPlatform(platform);
        config.settings({
            key: 'defaultValue',
            platforms: {
                mobile: {
                    key: 'mobileValue'
                }
            }
        });
        expect(config.get('key')).toEqual('mobileValue');
    });
    it('should set/get android setting w/ higher priority than mobile', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['mobile', 'android']);
        config.setPlatform(platform);
        config.settings({
            key: 'defaultValue',
            platforms: {
                mobile: {
                    key: 'mobileValue'
                },
                android: {
                    key: 'androidValue'
                }
            }
        });
        expect(config.get('key')).toEqual('androidValue');
    });
    it('should set/get ios setting w/ platforms set', function () {
        var config = new src_1.Config();
        var platform = new src_1.Platform(['ios']);
        config.setPlatform(platform);
        config.settings({
            key: 'defaultValue',
            platforms: {
                ios: {
                    key: 'iosValue'
                },
                android: {
                    key: 'androidValue'
                }
            }
        });
        expect(config.get('key')).toEqual('iosValue');
    });
    it('should set/get default setting w/ platforms set, but no platform match', function () {
        var config = new src_1.Config();
        config.settings({
            key: 'defaultValue',
            platforms: {
                ios: {
                    key: 'iosValue'
                },
                android: {
                    key: 'androidValue'
                }
            }
        });
        expect(config.get('key')).toEqual('defaultValue');
    });
    it('should set setting object', function () {
        var config = new src_1.Config();
        config.settings({
            name: 'Doc Brown',
            occupation: 'Weather Man'
        });
        expect(config.get('name')).toEqual('Doc Brown');
        expect(config.get('name')).toEqual('Doc Brown');
        expect(config.get('occupation')).toEqual('Weather Man');
        expect(config.get('occupation')).toEqual('Weather Man');
    });
    it('should get null setting', function () {
        var config = new src_1.Config();
        expect(config.get('name')).toEqual(null);
        expect(config.get('name')).toEqual(null);
        expect(config.get('occupation')).toEqual(null);
        expect(config.get('occupation')).toEqual(null);
    });
    it('should set/get single setting', function () {
        var config = new src_1.Config();
        config.set('name', 'Doc Brown');
        config.set('occupation', 'Weather Man');
        expect(config.get('name')).toEqual('Doc Brown');
        expect(config.get('name')).toEqual('Doc Brown');
        expect(config.get('occupation')).toEqual('Weather Man');
        expect(config.get('occupation')).toEqual('Weather Man');
    });
    it('should init w/ given config settings', function () {
        var config = new src_1.Config({
            name: 'Doc Brown',
            occupation: 'Weather Man'
        });
        expect(config.get('name')).toEqual('Doc Brown');
        expect(config.get('occupation')).toEqual('Weather Man');
    });
    it('should get a fallback value', function () {
        var config = new src_1.Config({
            name: 'Doc Brown'
        });
        expect(config.get('name', 'Marty')).toEqual('Doc Brown');
        expect(config.get('occupation', 'Weather Man')).toEqual('Weather Man');
    });
    it('should get a boolean value with a boolean config value', function () {
        var config = new src_1.Config({
            key1: true,
            key2: false
        });
        expect(config.getBoolean('key1')).toEqual(true);
        expect(config.getBoolean('key2')).toEqual(false);
    });
    it('should get a boolean value with a string config value', function () {
        var config = new src_1.Config({
            key1: 'true',
            key2: 'false',
            key3: 'whatever'
        });
        expect(config.getBoolean('key1')).toEqual(true);
        expect(config.getBoolean('key2')).toEqual(false);
        expect(config.getBoolean('key3')).toEqual(false);
        expect(config.getBoolean('key4')).toEqual(false);
        expect(config.getBoolean('key5', true)).toEqual(true);
    });
    it('should get a boolean value with a number config value', function () {
        var config = new src_1.Config({
            key1: 0,
            key2: 1,
            key3: 'whatever'
        });
        expect(config.getBoolean('key1')).toEqual(false);
        expect(config.getBoolean('key2')).toEqual(true);
    });
    it('should get a number value with a number config value', function () {
        var config = new src_1.Config({
            key: 6
        });
        expect(config.getNumber('key')).toEqual(6);
    });
    it('should get a number value with a string config value', function () {
        var config = new src_1.Config({
            key: '6',
            numThenString: '6baymax',
            stringThenNum: 'baymax6'
        });
        expect(config.getNumber('key', 5)).toEqual(6);
        expect(config.getNumber('numThenString', 4)).toEqual(6);
        expect(isNaN(config.getNumber('stringThenNum'))).toEqual(true);
    });
    it('should get a number NaN value with a NaN config value', function () {
        var config = new src_1.Config({
            allString: 'allstring',
            imNull: null,
            imUndefined: undefined
        });
        expect(isNaN(config.getNumber('notfound'))).toEqual(true);
        expect(isNaN(config.getNumber('allString'))).toEqual(true);
        expect(isNaN(config.getNumber('imNull'))).toEqual(true);
        expect(isNaN(config.getNumber('imUndefined'))).toEqual(true);
    });
    it('should get a number fallback value with a NaN config value', function () {
        var config = new src_1.Config({
            allString: 'allstring',
            imNull: null,
            imUndefined: undefined
        });
        expect(config.getNumber('notfound', 6)).toEqual(6);
        expect(config.getNumber('allString', 6)).toEqual(6);
        expect(config.getNumber('imNull', 6)).toEqual(6);
        expect(config.getNumber('imUndefined', 6)).toEqual(6);
    });
    it('should get settings object', function () {
        var config = new src_1.Config({
            name: 'Doc Brown',
            occupation: 'Weather Man'
        });
        expect(config.settings()).toEqual({
            name: 'Doc Brown',
            occupation: 'Weather Man'
        });
    });
    it('should create default config w/ bad settings value', function () {
        var config = new src_1.Config(null);
        expect(config.settings()).toEqual({});
        config = new src_1.Config(undefined);
        expect(config.settings()).toEqual({});
        config = new src_1.Config();
        expect(config.settings()).toEqual({});
        config = new src_1.Config([1, 2, 3]);
        expect(config.settings()).toEqual({});
        config = new src_1.Config('im bad, you know it');
        expect(config.settings()).toEqual({});
        config = new src_1.Config(8675309);
        expect(config.settings()).toEqual({});
        config = new src_1.Config(true);
        expect(config.settings()).toEqual({});
        config = new src_1.Config(false);
        expect(config.settings()).toEqual({});
        config = new src_1.Config(1);
        expect(config.settings()).toEqual({});
        config = new src_1.Config(function () { });
        expect(config.settings()).toEqual({});
    });
}
exports.run = run;