'use strict';
/* globals jasmine */
var path = require('path');
var failFast = require('protractor-fail-fast');

var specList = require('./specList');
// var FsCleaner = require('./lib/fs-cleaner');
// var start = (((specList.length - 3) / 2) + 3) - 3;
// var end = specList.length;
// console.log('Total specs are', specList.length, ', start is:', start, ', end is:', end);
// specList = specList.slice(0, 3).concat(specList.slice(start, end));
specList = specList.get(2);
console.log('Specs are', specList);

function disableAnimations() {
    var disableNgAnimate = function() {
        angular.module('disableNgAnimate', []).run(function($animate) {
            $animate.enabled(false);
        });
    };

    browser.addMockModule('disableNgAnimate', disableNgAnimate);

    var disableCssAnimate = function() {
        angular.module('disableCssAnimate', []).run(function() {
            var style = document.createElement('style');
            style.type = 'text/css';
            style.innerHTML = '* {' +
                '-webkit-transition: none !important;' +
                '-moz-transition: none !important;' +
                '-o-transition: none !important;' +
                '-ms-transition: none !important;' +
                'transition: none !important;' +
                '}';
            document.getElementsByTagName('head')[0].appendChild(style);
        });
    };

    browser.addMockModule('disableCssAnimate', disableCssAnimate);
}


exports.config = {
    plugins: [{
        package: 'protractor-fail-fast'
    }],
    seleniumAddress: process.env.SELENIUM_ADDRESS,
    // specs: require('./specList.js'),
    specs: specList,
    framework: 'jasmine2',
    // params: {
    // 	screenshotsBasePath: path.resolve(__dirname, './screenshots')
    // },
    capabilities: {
        browserName: 'chrome',
        'chromeOptions': {
            // Get rid of --ignore-certificate yellow warning
            args: ['--no-sandbox', '--test-type=browser'],
            // Set download path and avoid prompting for download even though
            // this is already the default on Chrome but for completeness
            prefs: {
                'download': {
                    'prompt_for_download': false,
                    'default_directory': path.resolve(__dirname, './downloads/'),
                },
            },
        }
    },
    // in case it throws  Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds. 
    allScriptsTimeout: 300 * 1000,
    getPageTimeout: 300 * 1000,
    jasmineNodeOpts: {
        defaultTimeoutInterval: 300 * 1000
    },
    onPrepare: function() {
        jasmine.getEnv().addReporter(failFast.init());
        var SpecReporter = require('jasmine-spec-reporter');
        // add jasmine spec reporter
        jasmine.getEnv().addReporter(new SpecReporter({
            displayStacktrace: true
        }));
        //disableAnimations();
        // FsCleaner.cleanScreenshotsFolder();
        // FsCleaner.cleanDownloadFolder();
    },
    afterLaunch: function() {
        failFast.clean(); // Cleans up the "fail file" (see below) 
    }
};