<commit_before>'use strict';

var Behaviors = require('./behaviors');
var Logger = require('./../logger/logger');
var VirtualDOM = require('../virtual-dom/virtual-dom');

var COMPONENT_DELIM = ':';
var IF_KEY = '$if';
var INVERTED_BEHAVIOR_KEYS = ['$index', '$repeatPayload'];
var REPEAT_KEY = '$repeat';
var SELF_KEY = '$self';
var YIELD_KEY = '$yield';

var CONTROL_FLOW_KEYS = [IF_KEY, REPEAT_KEY, YIELD_KEY];

function isSelfSelector(selector) {
    return selector === SELF_KEY;
}

function isControlFlowBehavior(name) {
    return CONTROL_FLOW_KEYS.indexOf(name) >= 0;
}

function hasInvertedBehaviorParams(params) {
    var result = false;
    for (var i = 0; i < params.length; i++) {
        if (INVERTED_BEHAVIOR_KEYS.indexOf(params[i]) >= 0) {
            result = true;
            break;
        }
    }

    return result;
}

function getTargets(component, selector) {
    var expandedBlueprint = component.tree.getExpandedBlueprint();
    if (expandedBlueprint) {
        return VirtualDOM.query(expandedBlueprint, selector);
    }
    else {
        return [];
    }
}

function route(behavior, component) {
    var name = behavior.name;

    if (isControlFlowBehavior(name)) {
        if (!component.blockControlFlow) {
            if (behavior.name === REPEAT_KEY) {
                component.processDynamicRepeat(behavior);
            }
            else if (behavior.name === IF_KEY) {
                component.processDynamicIf(behavior);
            }
            else {
                Logger.log('Dynamic $yield behaviors are not yet implemented.', 1);
            }
        }
    }
    else {
        if (hasInvertedBehaviorParams(behavior.params)) {
            if (isSelfSelector(behavior.selector) || behavior.name.indexOf(COMPONENT_DELIM) >= 0) {
                throw new Error('Inverted behaviors (i.e., ones with params of `$index`/`$payload`) can not use `$self` and must use components\' public interface');
            }

            Behaviors.invertedBehavior(behavior, component, getTargets(component, behavior.selector));
        }
        else {
            if (isSelfSelector(behavior.selector)) {
                if (name.indexOf(COMPONENT_DELIM) === -1) {
                    Behaviors.selfMessagingBehavior(behavior, component);
                }
                else {
                    Behaviors.selfDirectBehavior(behavior, component);
                }

            }
            else {
                if (name.indexOf(COMPONENT_DELIM) === -1) {
                    Behaviors.targetMessagingBehavior(behavior, component, getTargets(component, behavior.selector));
                }
                else {
                    throw new Error('Direct targeted behavior is not supported (' + behavior.selector + '|' + name + '.)');
                }
            }
        }
    }
}

module.exports = {
    route: route
};
<commit_msg>Feat: Adds `$camera` to behavior-router.js<commit_after>'use strict';

var Behaviors = require('./behaviors');
var Logger = require('./../logger/logger');
var VirtualDOM = require('../virtual-dom/virtual-dom');

var CAMERA_KEY = '$camera';
var COMPONENT_DELIM = ':';
var IF_KEY = '$if';
var INVERTED_BEHAVIOR_KEYS = ['$index', '$repeatPayload'];
var REPEAT_KEY = '$repeat';
var SELF_KEY = '$self';
var YIELD_KEY = '$yield';

var CONTROL_FLOW_KEYS = [IF_KEY, REPEAT_KEY, YIELD_KEY];

function isCameraSelector(selector) {
    return selector === CAMERA_KEY;
}

function isSelfSelector(selector) {
    return selector === SELF_KEY;
}

function isControlFlowBehavior(name) {
    return CONTROL_FLOW_KEYS.indexOf(name) >= 0;
}

function hasInvertedBehaviorParams(params) {
    var result = false;
    for (var i = 0; i < params.length; i++) {
        if (INVERTED_BEHAVIOR_KEYS.indexOf(params[i]) >= 0) {
            result = true;
            break;
        }
    }

    return result;
}

function getTargets(component, selector) {
    var expandedBlueprint = component.tree.getExpandedBlueprint();
    if (expandedBlueprint) {
        return VirtualDOM.query(expandedBlueprint, selector);
    }
    else {
        return [];
    }
}

function route(behavior, component) {
    var name = behavior.name;

    if (isControlFlowBehavior(name)) {
        if (!component.blockControlFlow) {
            if (behavior.name === REPEAT_KEY) {
                component.processDynamicRepeat(behavior);
            }
            else if (behavior.name === IF_KEY) {
                component.processDynamicIf(behavior);
            }
            else {
                Logger.log('Dynamic $yield behaviors are not yet implemented.', 1);
            }
        }
    }
    else {
        if (hasInvertedBehaviorParams(behavior.params)) {
            if (isSelfSelector(behavior.selector) || behavior.name.indexOf(COMPONENT_DELIM) >= 0) {
                throw new Error('Inverted behaviors (i.e., ones with params of `$index`/`$payload`) can not use `$self` and must use components\' public interface');
            }

            Behaviors.invertedBehavior(behavior, component, getTargets(component, behavior.selector));
        }
        else if (isCameraSelector(behavior.selector)) {
            Behaviors.cameraBehavior(behavior, component);
        }
        else {
            if (isSelfSelector(behavior.selector)) {
                if (name.indexOf(COMPONENT_DELIM) === -1) {
                    Behaviors.selfMessagingBehavior(behavior, component);
                }
                else {
                    Behaviors.selfDirectBehavior(behavior, component);
                }

            }
            else {
                if (name.indexOf(COMPONENT_DELIM) === -1) {
                    Behaviors.targetMessagingBehavior(behavior, component, getTargets(component, behavior.selector));
                }
                else {
                    throw new Error('Direct targeted behavior is not supported (' + behavior.selector + '|' + name + '.)');
                }
            }
        }
    }
}

module.exports = {
    route: route
};
<|endoftext|>


<commit_before>import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import RegistrationSearchBox from './RegistrationSearchBox'
import RegistrationSearchResults from './RegistrationSearchResults'

import { AccountActions } from '../../../account/store/account'
import { AvailabilityActions } from '../../store/availability'
import { IdentityActions } from '../../store/identity'
import { RegistrationActions } from '../../store/registration'
import { isABlockstackName } from '../../../utils/name-utils'

import log4js from 'log4js'

const logger = log4js.getLogger('profiles/components/registration/RegistrationSearchView.js')

const STORAGE_URL = '/account/storage'

function mapStateToProps(state) {
  return {
    api: state.settings.api,
    availability: state.profiles.availability,
    walletBalance: state.account.coreWallet.balance,
    balanceUrl: state.settings.api.zeroConfBalanceUrl
  }
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators(Object.assign({},
    IdentityActions, AccountActions, RegistrationActions, AvailabilityActions), dispatch)
}

class RegistrationSearchView extends Component {
  static propTypes = {
    api: PropTypes.object.isRequired,
    availability: PropTypes.object.isRequired,
    checkNameAvailabilityAndPrice: PropTypes.func.isRequired,
    refreshCoreWalletBalance: PropTypes.func.isRequired,
    walletBalance: PropTypes.number.isRequired,
    routeParams: PropTypes.object.isRequired,
    balanceUrl: PropTypes.string.isRequired
  }

  constructor(props) {
    super(props)
    const availableDomains = Object.assign({},
      {
        id: {
          registerUrl: this.props.api.registerUrl
        }
      }) // ,
      // this.props.api.subdomains)

    const nameSuffixes = Object.keys(availableDomains)

    this.state = {
      alerts: [],
      username: '',
      searchingUsername: '',
      storageConnected: this.props.api.storageConnected,
      availableDomains,
      nameSuffixes,
      showSearchResults: false
    }
    this.onChange = this.onChange.bind(this)
    this.search = this.search.bind(this)
    this.updateAlert = this.updateAlert.bind(this)
    this.displayConnectStorageAlert = this.displayConnectStorageAlert.bind(this)
    this.showSearchBox = this.showSearchBox.bind(this)
  }

  componentDidMount() {
    logger.trace('componentDidMount')
    this.props.refreshCoreWalletBalance(this.props.balanceUrl,
      this.props.api.coreAPIPassword)
  }

  componentWillReceiveProps() {
    logger.trace('componentWillReceiveProps')
    // Clear alerts
    this.setState({
      alerts: []
    })

    const storageConnected = this.props.api.storageConnected

    if (!storageConnected) {
      this.displayConnectStorageAlert()
    }
  }

  onChange(event) {
    const username = event.target.value.toLowerCase().replace(/\W+/g, '')
    this.setState({
      username
    })
  }

  search(event) {
    logger.trace('search')
    const username = this.state.username
    logger.debug(`search: user is searching for ${username}`)
    event.preventDefault()
    const nameSuffixes = this.state.nameSuffixes
    const testDomainName = `${username}.${nameSuffixes[0]}`
    if (!isABlockstackName(testDomainName)) {
      this.updateAlert('danger', `${testDomainName} is not a valid Blockstack name`)
      return
    }
    this.setState({
      searchingUsername: username,
      showSearchResults: true
    })

    nameSuffixes.forEach((nameSuffix) =>
    this.props.checkNameAvailabilityAndPrice(this.props.api,
      `${username}.${nameSuffix}`))
  }

  showSearchBox(event) {
    logger.trace('showSearchBox')
    event.preventDefault()
    this.setState({
      username: '',
      searchingUsername: '',
      showSearchResults: false
    })
  }

  updateAlert(alertStatus, alertMessage, url = null) {
    logger.trace(`updateAlert: alertStatus: ${alertStatus}, alertMessage ${alertMessage}`)
    this.setState({
      alerts: [{
        status: alertStatus,
        message: alertMessage,
        url
      }]
    })
  }

  displayConnectStorageAlert() {
    this.updateAlert('danger', 'Please go to the Storage app and connect a storage provider.',
    STORAGE_URL)
  }

  render() {
    const searchingUsername = this.state.searchingUsername
    const availableNames = this.props.availability.names
    const index = this.props.routeParams.index
    const showSearchResults = this.state.showSearchResults
    return (

        {!showSearchResults ?
          <RegistrationSearchBox
            alerts={this.state.alerts}
            search={this.search}
            username={this.state.username}
            onChange={this.onChange}
            disabled={!this.state.storageConnected}
          />
          :
          <RegistrationSearchResults
            showSearchBox={this.showSearchBox}
            searchingUsername={searchingUsername}
            nameSuffixes={this.state.nameSuffixes}
            availableNames={availableNames}
            index={index}
          />
        }

    )
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(RegistrationSearchView)
<commit_msg>props expect number<commit_after>import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import RegistrationSearchBox from './RegistrationSearchBox'
import RegistrationSearchResults from './RegistrationSearchResults'

import { AccountActions } from '../../../account/store/account'
import { AvailabilityActions } from '../../store/availability'
import { IdentityActions } from '../../store/identity'
import { RegistrationActions } from '../../store/registration'
import { isABlockstackName } from '../../../utils/name-utils'

import log4js from 'log4js'

const logger = log4js.getLogger('profiles/components/registration/RegistrationSearchView.js')

const STORAGE_URL = '/account/storage'

function mapStateToProps(state) {
  return {
    api: state.settings.api,
    availability: state.profiles.availability,
    walletBalance: state.account.coreWallet.balance,
    balanceUrl: state.settings.api.zeroConfBalanceUrl
  }
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators(Object.assign({},
    IdentityActions, AccountActions, RegistrationActions, AvailabilityActions), dispatch)
}

class RegistrationSearchView extends Component {
  static propTypes = {
    api: PropTypes.object.isRequired,
    availability: PropTypes.object.isRequired,
    checkNameAvailabilityAndPrice: PropTypes.func.isRequired,
    refreshCoreWalletBalance: PropTypes.func.isRequired,
    walletBalance: PropTypes.number.isRequired,
    routeParams: PropTypes.object.isRequired,
    balanceUrl: PropTypes.string.isRequired
  }

  constructor(props) {
    super(props)
    const availableDomains = Object.assign({},
      {
        id: {
          registerUrl: this.props.api.registerUrl
        }
      }) // ,
      // this.props.api.subdomains)

    const nameSuffixes = Object.keys(availableDomains)

    this.state = {
      alerts: [],
      username: '',
      searchingUsername: '',
      storageConnected: this.props.api.storageConnected,
      availableDomains,
      nameSuffixes,
      showSearchResults: false
    }
    this.onChange = this.onChange.bind(this)
    this.search = this.search.bind(this)
    this.updateAlert = this.updateAlert.bind(this)
    this.displayConnectStorageAlert = this.displayConnectStorageAlert.bind(this)
    this.showSearchBox = this.showSearchBox.bind(this)
  }

  componentDidMount() {
    logger.trace('componentDidMount')
    this.props.refreshCoreWalletBalance(this.props.balanceUrl,
      this.props.api.coreAPIPassword)
  }

  componentWillReceiveProps() {
    logger.trace('componentWillReceiveProps')
    // Clear alerts
    this.setState({
      alerts: []
    })

    const storageConnected = this.props.api.storageConnected

    if (!storageConnected) {
      this.displayConnectStorageAlert()
    }
  }

  onChange(event) {
    const username = event.target.value.toLowerCase().replace(/\W+/g, '')
    this.setState({
      username
    })
  }

  search(event) {
    logger.trace('search')
    const username = this.state.username
    logger.debug(`search: user is searching for ${username}`)
    event.preventDefault()
    const nameSuffixes = this.state.nameSuffixes
    const testDomainName = `${username}.${nameSuffixes[0]}`
    if (!isABlockstackName(testDomainName)) {
      this.updateAlert('danger', `${testDomainName} is not a valid Blockstack name`)
      return
    }
    this.setState({
      searchingUsername: username,
      showSearchResults: true
    })

    nameSuffixes.forEach((nameSuffix) =>
    this.props.checkNameAvailabilityAndPrice(this.props.api,
      `${username}.${nameSuffix}`))
  }

  showSearchBox(event) {
    logger.trace('showSearchBox')
    event.preventDefault()
    this.setState({
      username: '',
      searchingUsername: '',
      showSearchResults: false
    })
  }

  updateAlert(alertStatus, alertMessage, url = null) {
    logger.trace(`updateAlert: alertStatus: ${alertStatus}, alertMessage ${alertMessage}`)
    this.setState({
      alerts: [{
        status: alertStatus,
        message: alertMessage,
        url
      }]
    })
  }

  displayConnectStorageAlert() {
    this.updateAlert('danger', 'Please go to the Storage app and connect a storage provider.',
    STORAGE_URL)
  }

  render() {
    const searchingUsername = this.state.searchingUsername
    const availableNames = this.props.availability.names
    const index = parseInt(this.props.routeParams.index, 10)
    const showSearchResults = this.state.showSearchResults
    return (

        {!showSearchResults ?
          <RegistrationSearchBox
            alerts={this.state.alerts}
            search={this.search}
            username={this.state.username}
            onChange={this.onChange}
            disabled={!this.state.storageConnected}
          />
          :
          <RegistrationSearchResults
            showSearchBox={this.showSearchBox}
            searchingUsername={searchingUsername}
            nameSuffixes={this.state.nameSuffixes}
            availableNames={availableNames}
            index={index}
          />
        }

    )
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(RegistrationSearchView)
<|endoftext|>


<commit_before>{
	// IMPORTANT
	//
	// Internet Explorer can't parse dictionaries as:
	//  {
	//        'foo' : 'bar',
	//  }
	//
	// Due to the last ',' after 'bar'. Same for lists
	//   [
	//      1,
	//      2,
	//      //3
	//   ]
	// Would produce an error since there is a ',' and then a ']'.
	//
	// "weblab.service.fileupload.post.url" : "/weblab/fileUpload.php",
	"admin.email"                    : "weblab@deusto.es",
	"demo.available"                 : true,
	"google.analytics.tracking.code" : "UA-12576838-6",
	"experiments.default_picture"	 : "/img/experiments/default.jpg",
	"experiments" : {
					// Experiments not developed in GWT (such as those developed in Flash or Java) don't require
					// recompiling the client to be loaded. Adding them to this configuration file is enough.
					// Also those experiments that are inherently reusable for different classes, such as
					// those based in Virtual Machines (that will need to handle different experiment names
					// and categories) can be added here.
					"flash" : [
					           {
					        	   "experiment.name"     : "flashdummy",
					        	   "experiment.category" : "Dummy experiments",
					        	   "experiment.picture"	 : "/img/experiments/flash.jpg",
					        	   "page.footer"	 : "",
					        	   "flash.timeout"       : 20,
					        	   "width"               : 500,
					        	   "height"              : 350,
					        	   "swf.file"            : "WeblabFlashSample.swf",
					        	   "message"             : "Note: This is not a real experiment, it's just a demo so as to show that WebLab-Deusto can integrate different web technologies (such as Adobe Flash in this experiment). This demostrates that developing experiments in WebLab-Deusto is really flexible."
	                       		}
	                       		// Other flash experiments could be added here
	                       ],
	                "java" : [
	                          {
	                        	  "experiment.name"      : "javadummy",
	                        	  "experiment.category"  : "Dummy experiments",
	                        	  "experiment.picture"   : "/img/experiments/java.jpg",
	                        	  "width"                : 500,
	                        	  "height"               : 350,
	                        	  "jar.file"             : "WeblabJavaSample.jar",
	                        	  "code"                 : "es.deusto.weblab.client.experiment.plugins.es.deusto.weblab.javadummy.JavaDummyApplet",
	                        	  "message"             : "Note: This is not a real experiment, it's just a demo so as to show that WebLab-Deusto can integrate different web technologies (such as Java Applets in this experiment). This demostrates that developing experiments in WebLab-Deusto is really flexible."
	                          }
	                          // Other java experiments could be added here
	                       ],
	                "vm"    : [
	                           {
	                        	   "experiment.name"     : "vm",
	                        	   "experiment.category" : "Dummy experiments"
	                           },
	                           {
	                        	   "experiment.name"     : "ud-linux-vm",
	                        	   "experiment.category" : "VM experiments"
	                           },
	                           {
	                        	   "experiment.name"     : "ud-win-vm",
	                        	   "experiment.category" : "VM experiments"
	                           },
	                           {   "experiment.name"	 : "vm-win",
	                               "experiment.category" : "Dummy experiments"
	                           }
	                       ],
	                "xilinx" : [
							  {
								   "experiment.name"     : "ud-test-pld1",
								   "experiment.category" : "PLD experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
							  },
							  {
								   "experiment.name"     : "ud-test-pld2",
								   "experiment.category" : "PLD experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
							  },
							  {
								   "experiment.name"     : "ud-demo-pld",
								   "experiment.category" : "PLD experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
							  },
							  {
								   "experiment.name"     : "ud-demo-fpga",
								   "experiment.category" : "FPGA experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
						      },
						      {
							       "experiment.name"     : "ud-demo-xilinx",
							       "experiment.category" : "Xilinx experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
							       "is.demo"             : true,
							       "is.multiresource.demo" : true
						      },
							  {
								   "experiment.name"     : "ud-fpga",
								   "experiment.category" : "FPGA experiments"
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg"
							  },
	                          {
	                        	  "experiment.name"      : "ud-pld",
	                        	  "experiment.category"  : "PLD experiments"
	                        	  "experiment.picture"   : "/img/experiments/xilinx.jpg"
	                          }
	                       ],
	                "dummy" : [
	                           {
	                        	   "experiment.name"     : "ud-dummy",
	                        	   "experiment.category" : "Dummy experiments"
	                           }
	                       ],
	                "visir" : [
	                           {
	                        	   "experiment.name"     : "visirtest",
	                        	   "experiment.category" : "Dummy experiments",
	                        	   "experiment.picture"  : "/img/experiments/visir.jpg",
	                        	   "page.timer"          : true,
	                        	   "page.footer"         : "Powered by the wonderful VISIR Open Source project developed at the BTH"
	                           },
	                           {
	                        	   "experiment.name"     : "lxi_visir",
	                        	   "experiment.category" : "Visir experiments",
	                        	   "experiment.picture"  : "/img/experiments/visir.jpg",
	                        	   "page.timer"          : true,
	                        	   "page.footer"         : "Powered by the wonderful VISIR Open Source project developed at the BTH"
	                           },
                                   {
	                        	   "experiment.name"     : "visir",
	                        	   "experiment.category" : "Visir experiments",
	                        	   "experiment.picture"  : "/img/experiments/visir.jpg",
	                        	   "page.timer"          : true,
	                        	   "page.footer"         : "Powered by the wonderful VISIR Open Source project developed at the BTH"
	                           }
	                       ],
	                "logic" : [
	                           {
	                        	   "experiment.name"     : "ud-logic",
	                        	   "experiment.category" : "PIC experiments"
	                        	  "experiment.picture"   : "/img/experiments/logic.jpg"
	                           }
	                       ],
	                "binary" : [
	                            {
	                               "experiment.name"     : "ud-binary",
	                               "experiment.category" : "PLD experiments"
	                            }
	                       ],
	                "gpib"   : [
	                            {
	                               "experiment.name"     : "ud-gpib",
	                               "experiment.category" : "GPIB experiments"
	                            }
	                       ],
	                "gpib1" : [
	                            {
	                               "experiment.name"     : "ud-gpib1",
	                               "experiment.category" : "GPIB experiments"
	                            }
	                        ],
	                "gpib2" : [
	                           {
	                        	   "experiment.name"     : "ud-gpib2",
	                        	   "experiment.category" : "GPIB experiments"
	                           }
	                        ],
	                "pic"   : [
	                           {
	                        	   "experiment.name"     : "ud-pic",
	                        	   "experiment.category" : "PIC experiments"
	                        	   "experiment.picture"  : "/img/experiments/microchip.jpg"
	                           }
	                        ],
	                "pic2"  : [
	                           {
	                        	   "experiment.name"     : "ud-pic2",
	                        	   "experiment.category" : "PIC experiments"
	                        	   "experiment.picture"  : "/img/experiments/microchip.jpg"
	                           }
	                        ]
		}
}
<commit_msg>[configuration]  * The configuration file was wrong, fixing it.<commit_after>{
	// IMPORTANT
	//
	// Internet Explorer can't parse dictionaries as:
	//  {
	//        'foo' : 'bar',
	//  }
	//
	// Due to the last ',' after 'bar'. Same for lists
	//   [
	//      1,
	//      2,
	//      //3
	//   ]
	// Would produce an error since there is a ',' and then a ']'.
	//
	// "weblab.service.fileupload.post.url" : "/weblab/fileUpload.php",
	"admin.email"                    : "weblab@deusto.es",
	"demo.available"                 : true,
	"google.analytics.tracking.code" : "UA-12576838-6",
	"experiments.default_picture"	 : "/img/experiments/default.jpg",
	"experiments" : {
					// Experiments not developed in GWT (such as those developed in Flash or Java) don't require
					// recompiling the client to be loaded. Adding them to this configuration file is enough.
					// Also those experiments that are inherently reusable for different classes, such as
					// those based in Virtual Machines (that will need to handle different experiment names
					// and categories) can be added here.
					"flash" : [
					           {
					        	   "experiment.name"     : "flashdummy",
					        	   "experiment.category" : "Dummy experiments",
					        	   "experiment.picture"	 : "/img/experiments/flash.jpg",
					        	   "page.footer"	 : "",
					        	   "flash.timeout"       : 20,
					        	   "width"               : 500,
					        	   "height"              : 350,
					        	   "swf.file"            : "WeblabFlashSample.swf",
					        	   "message"             : "Note: This is not a real experiment, it's just a demo so as to show that WebLab-Deusto can integrate different web technologies (such as Adobe Flash in this experiment). This demostrates that developing experiments in WebLab-Deusto is really flexible."
	                       		}
	                       		// Other flash experiments could be added here
	                       ],
	                "java" : [
	                          {
	                        	  "experiment.name"      : "javadummy",
	                        	  "experiment.category"  : "Dummy experiments",
	                        	  "experiment.picture"   : "/img/experiments/java.jpg",
	                        	  "width"                : 500,
	                        	  "height"               : 350,
	                        	  "jar.file"             : "WeblabJavaSample.jar",
	                        	  "code"                 : "es.deusto.weblab.client.experiment.plugins.es.deusto.weblab.javadummy.JavaDummyApplet",
	                        	  "message"             : "Note: This is not a real experiment, it's just a demo so as to show that WebLab-Deusto can integrate different web technologies (such as Java Applets in this experiment). This demostrates that developing experiments in WebLab-Deusto is really flexible."
	                          }
	                          // Other java experiments could be added here
	                       ],
	                "vm"    : [
	                           {
	                        	   "experiment.name"     : "vm",
	                        	   "experiment.category" : "Dummy experiments"
	                           },
	                           {
	                        	   "experiment.name"     : "ud-linux-vm",
	                        	   "experiment.category" : "VM experiments"
	                           },
	                           {
	                        	   "experiment.name"     : "ud-win-vm",
	                        	   "experiment.category" : "VM experiments"
	                           },
	                           {   "experiment.name"	 : "vm-win",
	                               "experiment.category" : "Dummy experiments"
	                           }
	                       ],
	                "xilinx" : [
							  {
								   "experiment.name"     : "ud-test-pld1",
								   "experiment.category" : "PLD experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
							  },
							  {
								   "experiment.name"     : "ud-test-pld2",
								   "experiment.category" : "PLD experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
							  },
							  {
								   "experiment.name"     : "ud-demo-pld",
								   "experiment.category" : "PLD experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
							  },
							  {
								   "experiment.name"     : "ud-demo-fpga",
								   "experiment.category" : "FPGA experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
								   "is.demo"             : true
						      },
						      {
							       "experiment.name"     : "ud-demo-xilinx",
							       "experiment.category" : "Xilinx experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg",
							       "is.demo"             : true,
							       "is.multiresource.demo" : true
						      },
							  {
								   "experiment.name"     : "ud-fpga",
								   "experiment.category" : "FPGA experiments",
	                        	   "experiment.picture"   : "/img/experiments/xilinx.jpg"
							  },
	                          {
	                        	  "experiment.name"      : "ud-pld",
	                        	  "experiment.category"  : "PLD experiments",
	                        	  "experiment.picture"   : "/img/experiments/xilinx.jpg"
	                          }
	                       ],
	                "dummy" : [
	                           {
	                        	   "experiment.name"     : "ud-dummy",
	                        	   "experiment.category" : "Dummy experiments"
	                           }
	                       ],
	                "visir" : [
	                           {
	                        	   "experiment.name"     : "visirtest",
	                        	   "experiment.category" : "Dummy experiments",
	                        	   "experiment.picture"  : "/img/experiments/visir.jpg",
	                        	   "page.timer"          : true,
	                        	   "page.footer"         : "Powered by the wonderful VISIR Open Source project developed at the BTH"
	                           },
	                           {
	                        	   "experiment.name"     : "lxi_visir",
	                        	   "experiment.category" : "Visir experiments",
	                        	   "experiment.picture"  : "/img/experiments/visir.jpg",
	                        	   "page.timer"          : true,
	                        	   "page.footer"         : "Powered by the wonderful VISIR Open Source project developed at the BTH"
	                           },
                                   {
	                        	   "experiment.name"     : "visir",
	                        	   "experiment.category" : "Visir experiments",
	                        	   "experiment.picture"  : "/img/experiments/visir.jpg",
	                        	   "page.timer"          : true,
	                        	   "page.footer"         : "Powered by the wonderful VISIR Open Source project developed at the BTH"
	                           }
	                       ],
	                "logic" : [
	                           {
	                        	   "experiment.name"     : "ud-logic",
	                        	   "experiment.category" : "PIC experiments",
	                        	  "experiment.picture"   : "/img/experiments/logic.jpg"
	                           }
	                       ],
	                "binary" : [
	                            {
	                               "experiment.name"     : "ud-binary",
	                               "experiment.category" : "PLD experiments"
	                            }
	                       ],
	                "gpib"   : [
	                            {
	                               "experiment.name"     : "ud-gpib",
	                               "experiment.category" : "GPIB experiments"
	                            }
	                       ],
	                "gpib1" : [
	                            {
	                               "experiment.name"     : "ud-gpib1",
	                               "experiment.category" : "GPIB experiments"
	                            }
	                        ],
	                "gpib2" : [
	                           {
	                        	   "experiment.name"     : "ud-gpib2",
	                        	   "experiment.category" : "GPIB experiments"
	                           }
	                        ],
	                "pic"   : [
	                           {
	                        	   "experiment.name"     : "ud-pic",
	                        	   "experiment.category" : "PIC experiments",
	                        	   "experiment.picture"  : "/img/experiments/microchip.jpg"
	                           }
	                        ],
	                "pic2"  : [
	                           {
	                        	   "experiment.name"     : "ud-pic2",
	                        	   "experiment.category" : "PIC experiments",
	                        	   "experiment.picture"  : "/img/experiments/microchip.jpg"
	                           }
	                        ]
		}
}
<|endoftext|>


<commit_before>import reducer, {
    initialState as reducerInitialState,
    checkHasOfficialRemote,
    checkRemoveOfficialRemote,
    removeMember
} from "./reducer";
import {
    WS_INSERT_REFERENCE,
    WS_UPDATE_REFERENCE,
    WS_REMOVE_REFERENCE,
    LIST_REFERENCES,
    FILTER_REFERENCES,
    GET_REFERENCE,
    EDIT_REFERENCE,
    UPLOAD,
    CHECK_REMOTE_UPDATES,
    UPDATE_REMOTE_REFERENCE,
    ADD_REFERENCE_USER,
    EDIT_REFERENCE_USER,
    REMOVE_REFERENCE_USER,
    ADD_REFERENCE_GROUP,
    EDIT_REFERENCE_GROUP,
    REMOVE_REFERENCE_GROUP,
    WS_INSERT_OTU,
    WS_REMOVE_OTU
} from "../actionTypes";

describe("References Reducer", () => {

    const initialState = reducerInitialState;
    let state;
    let action;
    let result;
    let expected;

    it("should return the initial state on first pass", () => {
        result = reducer(undefined, {});
        expected = initialState;
        expect(result).toEqual(expected);
    });

    it("should return the given state on other action types", () => {
        action = {
            type: "UNHANDLED_ACTION"
        };
        result = reducer(initialState, action);
        expected = initialState;
        expect(result).toEqual(expected);
    });

    describe("should handle WS_INSERT_REFERENCE", () => {
        it("returns state if documents not yet fetched", () => {
            state = { fetched: false };
            action = { type: WS_INSERT_REFERENCE };
            result = reducer(state, action);
            expected = state;
            expect(result).toEqual(expected);
        });

        it("inserts entry into list otherwise", () => {
            state = {
                ...initialState,
                documents: [],
                page: 1,
                fetched: true,
                total_count: 0
            };
            action = {
                type: WS_INSERT_REFERENCE,
                data: { id: "123abc", name: "testReference" }
            };
            result = reducer(state, action);
            expected = {
                ...state,
                installOfficial: false,
                documents: [{ ...action.data }],
                total_count: 1
            };
            expect(result).toEqual(expected);
        });
    });

    it("should handle WS_UPDATE_REFERENCE", () => {
        state = { documents: [{ id: "123abc", name: "testReference" }] };
        action = {
            type: WS_UPDATE_REFERENCE,
            data: { id: "123abc", name: "testReference-edited" }
        };
        result = reducer(state, action);
        expected = {
            ...state,
            documents: [{ id: "123abc", name: "testReference-edited" }]
        };
        expect(result).toEqual(expected);
    });

    it("should handle WS_REMOVE_REFERENCE", () => {
        state = {
            documents: [{ id: "123abc", name: "testReference" }],
            page: 1,
            fetched: true,
            total_count: 1
        };
        action = {
            type: WS_REMOVE_REFERENCE,
            data: ["123abc"]
        };
        result = reducer(state, action);
        expected = {
            ...state,
            installOfficial: false,
            documents: [],
            total_count: 0,
            refetchPage: false
        };
        expect(result).toEqual(expected);
    });

    it("should handle WS_INSERT_OTU", () => {
        state = { detail: { otu_count: 3 } };
        action = { type: WS_INSERT_OTU };
        result = reducer(state, action);
        expected = { detail: { otu_count: 4 } };
        expect(result).toEqual(expected);
    });

    it("should handle WS_REMOVE_OTU", () => {
        state = { detail: { otu_count: 3 } };
        action = { type: WS_REMOVE_OTU };
        result = reducer(state, action);
        expected = { detail: { otu_count: 2 } };
        expect(result).toEqual(expected);
    });

    it("should handle LIST_REFERENCES_REQUESTED", () => {
        state = {};
        action = { type: LIST_REFERENCES.REQUESTED };
        result = reducer(state, action);
        expected = { isLoading: true, errorLoad: false };
        expect(result).toEqual(expected);
    });

    it("should handle LIST_REFERENCES_SUCCEEDED", () => {
        state = initialState;
        action = {
            type: LIST_REFERENCES.SUCCEEDED,
            data: { documents: [] }
        };
        result = reducer(state, action);
        expected = {
            ...state,
            installOfficial: false,
            documents: [],
            isLoading: false,
            errorLoad: false,
            fetched: true,
            refetchPage: false
        };
        expect(result).toEqual(expected);
    });

    it("should handle LIST_REFERENCES_FAILED", () => {
        state = {};
        action = { type: LIST_REFERENCES.FAILED };
        result = reducer(state, action);
        expected = { isLoading: false, errorLoad: true };
        expect(result).toEqual(expected);
    });

    it("should handle GET_REFERENCE_REQUESTED", () => {
        state = { detail: { foo: "bar" } };
        action = { type: GET_REFERENCE.REQUESTED };
        result = reducer(state, action);
        expected = { detail: null };
        expect(result).toEqual(expected);
    });

    it("should handle GET_REFERENCE_SUCCEEDED", () => {
        state = { detail: null };
        action = { type: GET_REFERENCE.SUCCEEDED, data: { foo: "bar" } };
        result = reducer(state, action);
        expected = { detail: { foo: "bar" }};
        expect(result).toEqual(expected);
    });

    it("should handle EDIT_REFERENCE_SUCCEEDED", () => {
        state = { detail: { foo: "bar" } };
        action = {
            type: EDIT_REFERENCE.SUCCEEDED,
            data: { foo: "baz" }
        };
        result = reducer(state, action);
        expected = { detail: { foo: "baz" } };
        expect(result).toEqual(expected);
    });

    it("should handle UPLOAD_SUCCEEDED", () => {
        state = {};
        action = { type: UPLOAD.SUCCEEDED, data: { foo: "bar" } };
        result = reducer(state, action);
        expected = { importData: { foo: "bar" } };
        expect(result).toEqual(expected);
    });

    it("should handle CHECK_REMOTE_UPDATES_REQUESTED", () => {
        state = {};
        action = { type: CHECK_REMOTE_UPDATES.REQUESTED };
        result = reducer(state, action);
        expected = { detail: { checkPending: true } };
        expect(result).toEqual(expected);
    });

    it("should handle CHECK_REMOTE_UPDATES_FAILED", () => {
        state = { detail: { checkPending: true } };
        action = { type: CHECK_REMOTE_UPDATES.FAILED };
        result = reducer(state, action);
        expected = { detail: { checkPending: false } };
        expect(result).toEqual(expected);
    });

    it("should handle CHECK_REMOTE_UPDATES_SUCCEEDED", () => {
        state = { detail: { checkPending: true } };
        action = {
            type: CHECK_REMOTE_UPDATES.SUCCEEDED,
            data: { foo: "bar" }
        };
        result = reducer(state, action);
        expected = {
            detail: {
                checkPending: false,
                release: { foo: "bar" }
            }
        };
        expect(result).toEqual(expected);
    });

    it("should handle UPDATE_REMOTE_REFERENCE_SUCCEEDED", () => {
        state = { detail: {} };
        action = {
            type: UPDATE_REMOTE_REFERENCE.SUCCEEDED,
            data: { foo: "bar" }
        };
        result = reducer(state, action);
        expected = { detail: { release: { foo: "bar" } } };
        expect(result).toEqual(expected);
    });

    it("should handle FILTER_REFERENCES_REQUESTED", () => {
        state = { filter: "" };
        action = {
            type: FILTER_REFERENCES.REQUESTED,
            term: "search"
        };
        result = reducer(state, action);
        expected = { filter: "search" };
        expect(result).toEqual(expected);
    });

    it("should handle FILTER_REFERENCES_SUCCEEDED", () => {
        state = { documents: null };
        action = {
            type: FILTER_REFERENCES.SUCCEEDED,
            data: { documents: [] }
        };
        result = reducer(state, action);
        expected = { documents: [] };
        expect(result).toEqual(expected);
    });

    it("should handle ADD_REFERENCE_USER_SUCCEEDED", () => {
        state = { detail: { users: [] } };
        action = {
            type: ADD_REFERENCE_USER.SUCCEEDED,
            data: { id: "test-user" }
        };
        result = reducer(state, action);
        expected = { detail: { users: [{ id: "test-user" }] }};
        expect(result).toEqual(expected);
    });

    it("should handle EDIT_REFERENCE_USER_SUCCEEDED", () => {
        state = { detail: { users: [{ id: "test-user", foo: "bar" }] } };
        action = {
            type: EDIT_REFERENCE_USER.SUCCEEDED,
            data: { id: "test-user", foo: "baz" }
        };
        result = reducer(state, action);
        expected = { detail: { users: [{ id: "test-user", foo: "baz" }] } };
        expect(result).toEqual(expected);
    });

    describe("should handle REMOVE_REFERENCE_USER_REQUESTED", () => {

        it("if store and response data refIds match, append to pending remove list", () => {
            state = { detail: { id: "test-1", pendingUserRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_USER.REQUESTED,
                refId: "test-1",
                userId: "test-user"
            };
            result = reducer(state, action);
            expected = {
                detail: { id: "test-1", pendingUserRemove: ["test-user"] }
            };
            expect(result).toEqual(expected);
        });

        it("else return state", () => {
            state = { detail: { id: "test-1", pendingUserRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_USER.REQUESTED,
                refId: "test-2",
                userId: "test-user"
            };
            result = reducer(state, action);
            expected = state;
            expect(result).toEqual(expected);
        });

    });

    it("should handle REMOVE_REFERENCE_USER_SUCCEEDED", () => {
        state = {
            detail: {
                users: [{ id: "test-user" }],
                pendingUserRemove: ["test-user"]
            }
        };
        action = { type: REMOVE_REFERENCE_USER.SUCCEEDED };
        result = reducer(state, action);
        expected = {detail: {...state.detail, users: [] } };
        expect(result).toEqual(expected);
    });

    it("should handle ADD_REFERENCE_GROUP_SUCCEEDED", () => {
        state = { detail: { groups: [] } };
        action = {
            type: ADD_REFERENCE_GROUP.SUCCEEDED,
            data: { id: "test-group" }
        };
        result = reducer(state, action);
        expected = {
            detail: { groups: [{ id: "test-group" }] }
        };
        expect(result).toEqual(expected);
    });

    it("should handle EDIT_REFERENCE_GROUP_SUCCEEDED", () => {
        state = {
            detail: {
                groups: [{ id: "test-group", foo: "bar" }]
            }
        };
        action = {
            type: EDIT_REFERENCE_GROUP.SUCCEEDED,
            data: { id: "test-group", foo: "baz" }
        };
        result = reducer(state, action);
        expected = {
            detail: {
                groups: [{ id: "test-group", foo: "baz" }]
            }
        };
        expect(result).toEqual(expected);
    });

    describe("should handle REMOVE_REFERENCE_GROUP_REQUESTED", () => {

        it("if store and response data refIds match, append to pending remove list", () => {
            state = { detail: { id: "test-1", pendingGroupRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_GROUP.REQUESTED,
                refId: "test-1",
                groupId: "test-group"
            };
            result = reducer(state, action);
            expected = {
                detail: { id: "test-1", pendingGroupRemove: ["test-group"] }
            };
            expect(result).toEqual(expected);
        });

        it("else return state", () => {
            state = { detail: { id: "test-1", pendingGroupRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_GROUP.REQUESTED,
                refId: "test-2",
                groupId: "test-group"
            };
            result = reducer(state, action);
            expected = state;
            expect(result).toEqual(expected);
        });

    });

    it("should handle REMOVE_REFERENCE_GROUP_SUCCEEDED", () => {
        state = {
            detail: {
                groups: [{ id: "test-group" }],
                pendingRemove: ["test-group"]
            }
        };
        action = { type: REMOVE_REFERENCE_GROUP.SUCCEEDED };
        result = reducer(state, action);
        expected = { detail: { groups: [], pendingRemove: [] } };
        expect(result).toEqual(expected);
    });

    describe("Helper Functions", () => {
        let list;

        it("checkHasOfficialRemote: checks list for official remote reference presence", () => {
            list = [];
            result = checkHasOfficialRemote(list);
            expect(result).toBe(false);

            list = [{ id: "official" }];
            result = checkHasOfficialRemote(list);
            expect(result).toBe(false);

            list = [
                {
                    id: "official",
                    remotes_from: { errors: [], slug: "virtool/ref-plant-viruses" }
                }
            ];
            result = checkHasOfficialRemote(list);
            expect(result).toBe(true);
        });

        describe("checkRemoveOfficialRemote: ", () => {
            let removedIds;
            let hasOfficial;

            it("if list does not currently contain official remote, return false", () => {
                list = [];
                removedIds = [];
                hasOfficial = false;
                result = checkRemoveOfficialRemote(list, removedIds, hasOfficial);
                expect(result).toBe(false);
            });

            it("list contains official remote and the official remote pending removal, return false", () => {
                list = [{ id: "official", remotes_from: { slug: "virtool/ref-plant-viruses" } }];
                removedIds = ["official"];
                hasOfficial = true;
                result = checkRemoveOfficialRemote(list, removedIds, hasOfficial);
                expect(result).toBe(false);
            });

            it("list contains official remote and the official remote not pending removal, return true", () => {
                list = [{ id: "official" }];
                removedIds = ["test"];
                hasOfficial = true;
                result = checkRemoveOfficialRemote(list, removedIds, hasOfficial);
                expect(result).toBe(true);
            });
        });

        it("removeMember: removes oldest member in pending list", () => {
            list = [];
            let pendingRemoves = [];
            result = removeMember(list, pendingRemoves);
            expect(result).toEqual(list);

            list = [{ id: "foo" }];
            pendingRemoves = ["bar"];
            result = removeMember(list, pendingRemoves);
            expect(result).toEqual(list);

            list = [{ id: "foo" }];
            pendingRemoves = ["foo"];
            result = removeMember(list, pendingRemoves);
            expected = [];
            expect(result).toEqual(expected);
        });

    });
});
<commit_msg>Update references reducer tests<commit_after>import reducer, {
    initialState as reducerInitialState,
    checkHasOfficialRemote,
    checkRemoveOfficialRemote,
    removeMember
} from "./reducer";
import {
    WS_INSERT_REFERENCE,
    WS_UPDATE_REFERENCE,
    WS_REMOVE_REFERENCE,
    LIST_REFERENCES,
    FILTER_REFERENCES,
    GET_REFERENCE,
    EDIT_REFERENCE,
    UPLOAD,
    CHECK_REMOTE_UPDATES,
    UPDATE_REMOTE_REFERENCE,
    ADD_REFERENCE_USER,
    EDIT_REFERENCE_USER,
    REMOVE_REFERENCE_USER,
    ADD_REFERENCE_GROUP,
    EDIT_REFERENCE_GROUP,
    REMOVE_REFERENCE_GROUP,
    WS_INSERT_OTU,
    WS_REMOVE_OTU
} from "../actionTypes";

describe("References Reducer", () => {

    const initialState = reducerInitialState;
    let state;
    let action;
    let result;
    let expected;

    it("should return the initial state on first pass", () => {
        result = reducer(undefined, {});
        expected = initialState;
        expect(result).toEqual(expected);
    });

    it("should return the given state on other action types", () => {
        action = {
            type: "UNHANDLED_ACTION"
        };
        result = reducer(initialState, action);
        expected = initialState;
        expect(result).toEqual(expected);
    });

    describe("should handle WS_INSERT_REFERENCE", () => {
        it("returns state if documents not yet fetched", () => {
            state = { fetched: false };
            action = { type: WS_INSERT_REFERENCE };
            result = reducer(state, action);
            expected = state;
            expect(result).toEqual(expected);
        });

        it("inserts entry into list otherwise", () => {
            state = {
                ...initialState,
                documents: [],
                page: 1,
                fetched: true,
                total_count: 0
            };
            action = {
                type: WS_INSERT_REFERENCE,
                data: { id: "123abc", name: "testReference" }
            };
            result = reducer(state, action);
            expected = {
                ...state,
                installOfficial: false,
                documents: [{ ...action.data }],
                total_count: 1
            };
            expect(result).toEqual(expected);
        });
    });

    it("should handle WS_UPDATE_REFERENCE", () => {
        state = { documents: [{ id: "123abc", name: "testReference" }] };
        action = {
            type: WS_UPDATE_REFERENCE,
            data: { id: "123abc", name: "testReference-edited" }
        };
        result = reducer(state, action);
        expected = {
            ...state,
            documents: [{ id: "123abc", name: "testReference-edited" }]
        };
        expect(result).toEqual(expected);
    });

    it("should handle WS_REMOVE_REFERENCE", () => {
        state = {
            documents: [{ id: "123abc", name: "testReference" }],
            page: 1,
            fetched: true,
            total_count: 1
        };
        action = {
            type: WS_REMOVE_REFERENCE,
            data: ["123abc"]
        };
        result = reducer(state, action);
        expected = {
            ...state,
            installOfficial: false,
            documents: [],
            total_count: 0,
            refetchPage: false
        };
        expect(result).toEqual(expected);
    });

    it("should handle WS_INSERT_OTU", () => {
        state = { detail: { otu_count: 3 } };
        action = { type: WS_INSERT_OTU };
        result = reducer(state, action);
        expected = { detail: { otu_count: 4 } };
        expect(result).toEqual(expected);

        state = { detail: null };
        action = { type: WS_INSERT_OTU };
        result = reducer(state, action);
        expect(result).toEqual(state);
    });

    it("should handle WS_REMOVE_OTU", () => {
        state = { detail: { otu_count: 3 } };
        action = { type: WS_REMOVE_OTU };
        result = reducer(state, action);
        expected = { detail: { otu_count: 2 } };
        expect(result).toEqual(expected);

        state = { detail: null };
        action = { type: WS_REMOVE_OTU };
        result = reducer(state, action);
        expect(result).toEqual(state);
    });

    it("should handle LIST_REFERENCES_REQUESTED", () => {
        state = {};
        action = { type: LIST_REFERENCES.REQUESTED };
        result = reducer(state, action);
        expected = { isLoading: true, errorLoad: false };
        expect(result).toEqual(expected);
    });

    it("should handle LIST_REFERENCES_SUCCEEDED", () => {
        state = initialState;
        action = {
            type: LIST_REFERENCES.SUCCEEDED,
            data: { documents: [] }
        };
        result = reducer(state, action);
        expected = {
            ...state,
            installOfficial: false,
            documents: [],
            isLoading: false,
            errorLoad: false,
            fetched: true,
            refetchPage: false
        };
        expect(result).toEqual(expected);
    });

    it("should handle LIST_REFERENCES_FAILED", () => {
        state = {};
        action = { type: LIST_REFERENCES.FAILED };
        result = reducer(state, action);
        expected = { isLoading: false, errorLoad: true };
        expect(result).toEqual(expected);
    });

    it("should handle GET_REFERENCE_REQUESTED", () => {
        state = { detail: { foo: "bar" } };
        action = { type: GET_REFERENCE.REQUESTED };
        result = reducer(state, action);
        expected = { detail: null };
        expect(result).toEqual(expected);
    });

    it("should handle GET_REFERENCE_SUCCEEDED", () => {
        state = { detail: null };
        action = { type: GET_REFERENCE.SUCCEEDED, data: { foo: "bar" } };
        result = reducer(state, action);
        expected = { detail: { foo: "bar" }};
        expect(result).toEqual(expected);
    });

    it("should handle EDIT_REFERENCE_SUCCEEDED", () => {
        state = { detail: { foo: "bar" } };
        action = {
            type: EDIT_REFERENCE.SUCCEEDED,
            data: { foo: "baz" }
        };
        result = reducer(state, action);
        expected = { detail: { foo: "baz" } };
        expect(result).toEqual(expected);
    });

    it("should handle UPLOAD_SUCCEEDED", () => {
        state = {};
        action = { type: UPLOAD.SUCCEEDED, data: { foo: "bar" } };
        result = reducer(state, action);
        expected = { importData: { foo: "bar" } };
        expect(result).toEqual(expected);
    });

    it("should handle CHECK_REMOTE_UPDATES_REQUESTED", () => {
        state = {};
        action = { type: CHECK_REMOTE_UPDATES.REQUESTED };
        result = reducer(state, action);
        expected = { detail: { checkPending: true } };
        expect(result).toEqual(expected);
    });

    it("should handle CHECK_REMOTE_UPDATES_FAILED", () => {
        state = { detail: { checkPending: true } };
        action = { type: CHECK_REMOTE_UPDATES.FAILED };
        result = reducer(state, action);
        expected = { detail: { checkPending: false } };
        expect(result).toEqual(expected);
    });

    it("should handle CHECK_REMOTE_UPDATES_SUCCEEDED", () => {
        state = { detail: { checkPending: true } };
        action = {
            type: CHECK_REMOTE_UPDATES.SUCCEEDED,
            data: { foo: "bar" }
        };
        result = reducer(state, action);
        expected = {
            detail: {
                checkPending: false,
                release: { foo: "bar" }
            }
        };
        expect(result).toEqual(expected);
    });

    it("should handle UPDATE_REMOTE_REFERENCE_SUCCEEDED", () => {
        state = { detail: {} };
        action = {
            type: UPDATE_REMOTE_REFERENCE.SUCCEEDED,
            data: { foo: "bar" }
        };
        result = reducer(state, action);
        expected = { detail: { release: { foo: "bar" } } };
        expect(result).toEqual(expected);
    });

    it("should handle FILTER_REFERENCES_REQUESTED", () => {
        state = { filter: "" };
        action = {
            type: FILTER_REFERENCES.REQUESTED,
            term: "search"
        };
        result = reducer(state, action);
        expected = { filter: "search" };
        expect(result).toEqual(expected);
    });

    it("should handle FILTER_REFERENCES_SUCCEEDED", () => {
        state = { documents: null };
        action = {
            type: FILTER_REFERENCES.SUCCEEDED,
            data: { documents: [] }
        };
        result = reducer(state, action);
        expected = { documents: [] };
        expect(result).toEqual(expected);
    });

    it("should handle ADD_REFERENCE_USER_SUCCEEDED", () => {
        state = { detail: { users: [] } };
        action = {
            type: ADD_REFERENCE_USER.SUCCEEDED,
            data: { id: "test-user" }
        };
        result = reducer(state, action);
        expected = { detail: { users: [{ id: "test-user" }] }};
        expect(result).toEqual(expected);
    });

    it("should handle EDIT_REFERENCE_USER_SUCCEEDED", () => {
        state = { detail: { users: [{ id: "test-user", foo: "bar" }] } };
        action = {
            type: EDIT_REFERENCE_USER.SUCCEEDED,
            data: { id: "test-user", foo: "baz" }
        };
        result = reducer(state, action);
        expected = { detail: { users: [{ id: "test-user", foo: "baz" }] } };
        expect(result).toEqual(expected);
    });

    describe("should handle REMOVE_REFERENCE_USER_REQUESTED", () => {

        it("if store and response data refIds match, append to pending remove list", () => {
            state = { detail: { id: "test-1", pendingUserRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_USER.REQUESTED,
                refId: "test-1",
                userId: "test-user"
            };
            result = reducer(state, action);
            expected = {
                detail: { id: "test-1", pendingUserRemove: ["test-user"] }
            };
            expect(result).toEqual(expected);
        });

        it("else return state", () => {
            state = { detail: { id: "test-1", pendingUserRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_USER.REQUESTED,
                refId: "test-2",
                userId: "test-user"
            };
            result = reducer(state, action);
            expected = state;
            expect(result).toEqual(expected);
        });

    });

    it("should handle REMOVE_REFERENCE_USER_SUCCEEDED", () => {
        state = {
            detail: {
                users: [{ id: "test-user" }],
                pendingUserRemove: ["test-user"]
            }
        };
        action = { type: REMOVE_REFERENCE_USER.SUCCEEDED };
        result = reducer(state, action);
        expected = {detail: {...state.detail, users: [] } };
        expect(result).toEqual(expected);
    });

    it("should handle ADD_REFERENCE_GROUP_SUCCEEDED", () => {
        state = { detail: { groups: [] } };
        action = {
            type: ADD_REFERENCE_GROUP.SUCCEEDED,
            data: { id: "test-group" }
        };
        result = reducer(state, action);
        expected = {
            detail: { groups: [{ id: "test-group" }] }
        };
        expect(result).toEqual(expected);
    });

    it("should handle EDIT_REFERENCE_GROUP_SUCCEEDED", () => {
        state = {
            detail: {
                groups: [{ id: "test-group", foo: "bar" }]
            }
        };
        action = {
            type: EDIT_REFERENCE_GROUP.SUCCEEDED,
            data: { id: "test-group", foo: "baz" }
        };
        result = reducer(state, action);
        expected = {
            detail: {
                groups: [{ id: "test-group", foo: "baz" }]
            }
        };
        expect(result).toEqual(expected);
    });

    describe("should handle REMOVE_REFERENCE_GROUP_REQUESTED", () => {

        it("if store and response data refIds match, append to pending remove list", () => {
            state = { detail: { id: "test-1", pendingGroupRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_GROUP.REQUESTED,
                refId: "test-1",
                groupId: "test-group"
            };
            result = reducer(state, action);
            expected = {
                detail: { id: "test-1", pendingGroupRemove: ["test-group"] }
            };
            expect(result).toEqual(expected);
        });

        it("else return state", () => {
            state = { detail: { id: "test-1", pendingGroupRemove: [] } };
            action = {
                type: REMOVE_REFERENCE_GROUP.REQUESTED,
                refId: "test-2",
                groupId: "test-group"
            };
            result = reducer(state, action);
            expected = state;
            expect(result).toEqual(expected);
        });

    });

    it("should handle REMOVE_REFERENCE_GROUP_SUCCEEDED", () => {
        state = {
            detail: {
                groups: [{ id: "test-group" }],
                pendingRemove: ["test-group"]
            }
        };
        action = { type: REMOVE_REFERENCE_GROUP.SUCCEEDED };
        result = reducer(state, action);
        expected = { detail: { groups: [], pendingRemove: [] } };
        expect(result).toEqual(expected);
    });

    describe("Helper Functions", () => {
        let list;

        it("checkHasOfficialRemote: checks list for official remote reference presence", () => {
            list = [];
            result = checkHasOfficialRemote(list);
            expect(result).toBe(false);

            list = [{ id: "official" }];
            result = checkHasOfficialRemote(list);
            expect(result).toBe(false);

            list = [
                {
                    id: "official",
                    remotes_from: { errors: [], slug: "virtool/ref-plant-viruses" }
                }
            ];
            result = checkHasOfficialRemote(list);
            expect(result).toBe(true);
        });

        describe("checkRemoveOfficialRemote: ", () => {
            let removedIds;
            let hasOfficial;

            it("if list does not currently contain official remote, return false", () => {
                list = [];
                removedIds = [];
                hasOfficial = false;
                result = checkRemoveOfficialRemote(list, removedIds, hasOfficial);
                expect(result).toBe(false);
            });

            it("list contains official remote and the official remote pending removal, return false", () => {
                list = [{ id: "official", remotes_from: { slug: "virtool/ref-plant-viruses" } }];
                removedIds = ["official"];
                hasOfficial = true;
                result = checkRemoveOfficialRemote(list, removedIds, hasOfficial);
                expect(result).toBe(false);
            });

            it("list contains official remote and the official remote not pending removal, return true", () => {
                list = [{ id: "official" }];
                removedIds = ["test"];
                hasOfficial = true;
                result = checkRemoveOfficialRemote(list, removedIds, hasOfficial);
                expect(result).toBe(true);
            });
        });

        it("removeMember: removes oldest member in pending list", () => {
            list = [];
            let pendingRemoves = [];
            result = removeMember(list, pendingRemoves);
            expect(result).toEqual(list);

            list = [{ id: "foo" }];
            pendingRemoves = ["bar"];
            result = removeMember(list, pendingRemoves);
            expect(result).toEqual(list);

            list = [{ id: "foo" }];
            pendingRemoves = ["foo"];
            result = removeMember(list, pendingRemoves);
            expected = [];
            expect(result).toEqual(expected);
        });

    });
});
<|endoftext|>


<commit_before>import React from "react";
import { connect } from "react-redux";
import { Col, Panel, Row } from "react-bootstrap";
import { toNumber, upperFirst } from "lodash-es";

import { updateSetting } from "../../actions";
import { getResources } from "../../../jobs/actions";
import { Alert, InputError, LoadingPlaceholder } from "../../../base";

const getErrorMessage = (isError, min, max) => (
    isError ? `Value must be between ${min} and ${max}` : null
);

const getUpperLimits = (resources) => {
    const procLimit = resources.proc.length;
    const memLimit = parseFloat((resources.mem.total / Math.pow(1024, 3)).toFixed(1));

    return { procLimit, memLimit };
};

class Resources extends React.Component {

    constructor (props) {
        super(props);

        this.state = {
            errorProc: false,
            errorMem: false,
            showAlert: false
        };
    }

    componentDidMount () {
        this.props.onGet();
    }

    componentWillReceiveProps (nextProps) {

        if (nextProps.mem !== this.props.mem) {
            this.setState({errorMem: false});
        }

        if (nextProps.proc !== this.props.proc) {
            this.setState({errorProc: false});
        }
    }

    handleChange = (e) => {
        e.preventDefault();

        const error = `error${upperFirst(e.target.name)}`;
        this.setState({ [error]: false });
    };

    handleInvalid = (e) => {
        e.preventDefault();

        const error = `error${upperFirst(e.target.name)}`;
        this.setState({ [error]: true });
    };

    handleSave = (e) => {
        const name = e.name;
        const value = toNumber(e.value);
        const error = `error${upperFirst(name)}`;

        if (value <= e.max && value >= e.min) {
            this.props.onUpdate(e);
        } else {
            this.setState({ [error]: true });
        }
    };

    render () {

        if (this.props.resources === null) {
            return <LoadingPlaceholder />;
        }

        const { procLimit, memLimit } = getUpperLimits(this.props.resources);

        const errorMessageProc = getErrorMessage(this.state.errorProc, this.props.procLowerLimit, procLimit);
        const errorMessageMem = getErrorMessage(this.state.errorMem, this.props.memLowerLimit, memLimit);

        let alert;

        if (this.props.error) {
            alert = (
                <Alert bsStyle="danger" icon="warning">
                    Resource Limit values cannot be lower than corresponding Task-specific Limits.
                </Alert>
            );
        }

        return (

                {alert}
                <Row>
                    <Col md={12}>

Resource Limits

                    </Col>
                    <Col xs={12} md={6} mdPush={6}>
                        <Panel>
                            <Panel.Body>
                                Set limits on the computing resources Virtool can use on the host server.
                            </Panel.Body>
                        </Panel>
                    </Col>
                    <Col xs={12} md={6} mdPull={6}>
                        <Panel>
                            <Panel.Body>
                                <InputError
                                    label="CPU Limit"
                                    type="number"
                                    name="proc"
                                    min={this.props.procLowerLimit}
                                    max={procLimit}
                                    onSave={this.handleSave}
                                    onInvalid={this.handleInvalid}
                                    onChange={this.handleChange}
                                    initialValue={
                                        procLimit < this.props.proc
                                            ? procLimit
                                            : this.props.proc
                                    }
                                    error={errorMessageProc}
                                    noMargin
                                    withButton
                                />
                                <InputError
                                    label="Memory Limit (GB)"
                                    type="number"
                                    name="mem"
                                    min={this.props.memLowerLimit}
                                    max={memLimit}
                                    step={0.1}
                                    onSave={this.handleSave}
                                    onInvalid={this.handleInvalid}
                                    onChange={this.handleChange}
                                    initialValue={
                                        memLimit < this.props.mem
                                            ? memLimit
                                            : this.props.mem
                                    }
                                    error={errorMessageMem}
                                    noMargin
                                    withButton
                                />
                            </Panel.Body>
                        </Panel>
                    </Col>
                </Row>

        );
    }
}

const mapStateToProps = (state) => ({
    proc: state.settings.data.proc,
    mem: state.settings.data.mem,
    resources: state.jobs.resources,
    procLowerLimit: state.settings.data.rebuild_index_proc,
    memLowerLimit: state.settings.data.rebuild_index_mem,
    error: state.settings.data.updateError
});

const mapDispatchToProps = (dispatch) => ({

    onUpdate: (e) => {
        dispatch(updateSetting(e.name, toNumber(e.value)));
    },

    onGet: () => {
        dispatch(getResources());
    }

});

export default connect(mapStateToProps, mapDispatchToProps)(Resources);
<commit_msg>Fix resource limits component<commit_after>import React from "react";
import { connect } from "react-redux";
import { Col, Panel, Row } from "react-bootstrap";
import { toNumber, upperFirst } from "lodash-es";

import { Alert, Flex, FlexItem, InputError, LoadingPlaceholder } from "../../../base";
import { getResources } from "../../../jobs/actions";
import { maxResourcesSelector, minResourcesSelector } from "../../selectors";
import { updateSetting } from "../../actions";

const getErrorMessage = (isError, min, max) => (
    isError ? `Value must be between ${min} and ${max}` : null
);

const LimitLabel = ({ label, available, unit }) => (

        <Flex alignItems="center">
            <FlexItem grow={1} shrink={0}>
                {label}
            </FlexItem>
            <FlexItem grow={0} shrink={0}>

                    {available} {unit} available

            </FlexItem>
        </Flex>

);

class Resources extends React.Component {

    constructor (props) {
        super(props);

        this.state = {
            errorProc: false,
            errorMem: false,
            showAlert: false
        };
    }

    componentDidMount () {
        this.props.onGet();
    }

    componentWillReceiveProps (nextProps) {
        if (nextProps.mem !== this.props.mem) {
            this.setState({errorMem: false});
        }

        if (nextProps.proc !== this.props.proc) {
            this.setState({errorProc: false});
        }
    }

    handleChange = (e) => {
        this.setError(e, false);
    };

    handleInvalid = (e) => {
        this.setError(e, true);
    };

    handleSave = (e) => {
        const name = e.name;
        const value = toNumber(e.value);
        const error = `error${upperFirst(name)}`;

        if (value <= e.max && value >= e.min) {
            this.props.onUpdate(e);
        } else {
            this.setState({ [error]: true });
        }
    };

    setError = (e, value) => {
        e.preventDefault();

        this.setState({
            [`error${upperFirst(e.target.name)}`]: value
        });
    };

    render () {

        if (this.props.resources === null) {
            return <LoadingPlaceholder />;
        }

        const errorMessageProc = getErrorMessage(
            this.state.errorProc,
            this.props.minProc,
            this.props.maxProc
        );

        const errorMessageMem = getErrorMessage(
            this.state.errorMem,
            this.props.minMem,
            this.props.maxMem
        );

        let alert;

        if (this.props.error) {
            alert = (
                <Alert bsStyle="danger" icon="warning">
                    Resource Limit values cannot be lower than corresponding Task-specific Limits.
                </Alert>
            );
        }

        return (

                {alert}
                <Row>
                    <Col md={12}>

Resource Limits

                    </Col>
                    <Col xs={12} md={6} mdPush={6}>
                        <Panel>
                            <Panel.Body>
                                Set limits on the computing resources Virtool can use on the host server.
                            </Panel.Body>
                        </Panel>
                    </Col>
                    <Col xs={12} md={6} mdPull={6}>
                        <Panel>
                            <Panel.Body>
                                <LimitLabel label="CPU Limit" available={this.props.maxProc} unit="cores" />
                                <InputError
                                    type="number"
                                    name="proc"
                                    min={this.props.minProc}
                                    max={this.props.maxProc}
                                    onSave={this.handleSave}
                                    onInvalid={this.handleInvalid}
                                    onChange={this.handleChange}
                                    initialValue={this.props.proc}
                                    error={errorMessageProc}
                                    noMargin
                                    withButton
                                />

                                <LimitLabel label="Memory Limit (GB)" available={this.props.maxMem} unit="GB" />
                                <InputError
                                    type="number"
                                    name="mem"
                                    min={this.props.minMem}
                                    max={this.props.maxMem}
                                    step={0.1}
                                    onSave={this.handleSave}
                                    onInvalid={this.handleInvalid}
                                    onChange={this.handleChange}
                                    initialValue={this.props.mem}
                                    error={errorMessageMem}
                                    noMargin
                                    withButton
                                />
                            </Panel.Body>
                        </Panel>
                    </Col>
                </Row>

        );
    }
}

const mapStateToProps = (state) => {
    const { maxProc, maxMem } = maxResourcesSelector(state);
    const { minProc, minMem } = minResourcesSelector(state);

    return {
        proc: state.settings.data.proc,
        mem: state.settings.data.mem,
        minProc,
        minMem,
        maxProc,
        maxMem,
        resources: state.jobs.resources,
        error: state.settings.data.updateError
    };
};

const mapDispatchToProps = (dispatch) => ({

    onUpdate: (e) => {
        dispatch(updateSetting(e.name, toNumber(e.value)));
    },

    onGet: () => {
        dispatch(getResources());
    }

});

export default connect(mapStateToProps, mapDispatchToProps)(Resources);
<|endoftext|>


<commit_before>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Wraps an iterable storage mechanism and creates artificial
 * namespaces using a prefix in the global namespace.
 *
 */

goog.provide('goog.storage.mechanism.PrefixedMechanism');

goog.require('goog.iter.Iterator');
goog.require('goog.storage.mechanism.IterableMechanism');

/**
 * Wraps an iterable storage mechanism and creates artificial namespaces.
 *
 * @param {!goog.storage.mechanism.IterableMechanism} mechanism Underlying
 *     iterable storage mechanism.
 * @param {string} prefix Prefix for creating an artificial namespace.
 * @constructor
 * @extends {goog.storage.mechanism.IterableMechanism}
 */
goog.storage.mechanism.PrefixedMechanism = function(mechanism, prefix) {
  goog.base(this);
  this.mechanism_ = mechanism;
  this.prefix_ = prefix + '::';
};
goog.inherits(goog.storage.mechanism.PrefixedMechanism,
              goog.storage.mechanism.IterableMechanism);

/**
 * The mechanism to be prefixed.
 *
 * @type {goog.storage.mechanism.IterableMechanism}
 * @private
 */
goog.storage.mechanism.PrefixedMechanism.prototype.mechanism_ = null;

/**
 * The prefix for creating artificial namespaces.
 *
 * @type {string}
 * @private
 */
goog.storage.mechanism.PrefixedMechanism.prototype.prefix_ = '';

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.set = function(key, value) {
  this.mechanism_.set(this.prefix_ + key, value);
};

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.get = function(key) {
  return this.mechanism_.get(this.prefix_ + key);
};

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.remove = function(key) {
  this.mechanism_.remove(this.prefix_ + key);
};

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.__iterator__ = function(
    opt_keys) {
  var subIter = this.mechanism_.__iterator__(true);
  var newIter = new goog.iter.Iterator;
  var selfObj = this;
  newIter.next = function() {
    var key = subIter.next();
    while (key.substr(0, selfObj.prefix_.length) != selfObj.prefix_) {
      key = subIter.next();
    }
    return opt_keys ? key.substr(selfObj.prefix_.length) :
                      selfObj.mechanism_.get(key);
  };
  return newIter;
};
<commit_msg><commit_after>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Wraps an iterable storage mechanism and creates artificial
 * namespaces using a prefix in the global namespace.
 *
 */

goog.provide('goog.storage.mechanism.PrefixedMechanism');

goog.require('goog.iter.Iterator');
goog.require('goog.storage.mechanism.IterableMechanism');

/**
 * Wraps an iterable storage mechanism and creates artificial namespaces.
 *
 * @param {!goog.storage.mechanism.IterableMechanism} mechanism Underlying
 *     iterable storage mechanism.
 * @param {string} prefix Prefix for creating an artificial namespace.
 * @constructor
 * @extends {goog.storage.mechanism.IterableMechanism}
 */
goog.storage.mechanism.PrefixedMechanism = function(mechanism, prefix) {
  goog.base(this);
  this.mechanism_ = mechanism;
  this.prefix_ = prefix + '::';
};
goog.inherits(goog.storage.mechanism.PrefixedMechanism,
              goog.storage.mechanism.IterableMechanism);

/**
 * The mechanism to be prefixed.
 *
 * @type {goog.storage.mechanism.IterableMechanism}
 * @private
 */
goog.storage.mechanism.PrefixedMechanism.prototype.mechanism_ = null;

/**
 * The prefix for creating artificial namespaces.
 *
 * @type {string}
 * @private
 */
goog.storage.mechanism.PrefixedMechanism.prototype.prefix_ = '';

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.set = function(key, value) {
  this.mechanism_.set(this.prefix_ + key, value);
};

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.get = function(key) {
  return this.mechanism_.get(this.prefix_ + key);
};

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.remove = function(key) {
  this.mechanism_.remove(this.prefix_ + key);
};

/** @override */
goog.storage.mechanism.PrefixedMechanism.prototype.__iterator__ = function(
    opt_keys) {
  var subIter = this.mechanism_.__iterator__(true);
  var newIter = new goog.iter.Iterator;
  var selfObj = this;
  newIter.next = function() {
    var key = /** @type {string} */ (subIter.next());
    while (key.substr(0, selfObj.prefix_.length) != selfObj.prefix_) {
      key = /** @type {string} */ (subIter.next());
    }
    return opt_keys ? key.substr(selfObj.prefix_.length) :
                      selfObj.mechanism_.get(key);
  };
  return newIter;
};
<|endoftext|>


<commit_before>'use strict';

module.exports = function (config) {
  var configuration = {
    basePath: '.',

    frameworks: ['jasmine'],

    files: [
      // paths loaded by Karma
      {pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true},
      {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
      {pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true},
      {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
      {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
      {pattern: 'node_modules/@angular/**/*.map', included: false, watched: false},

      {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
      {pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false},

      {pattern: 'karma-test-shim.js', included: true, watched: true},

      // paths loaded via module imports
      {pattern: 'dist/**/*.js', included: false, watched: true},
      {pattern: 'dist/**/*.html', included: true, served: true, watched: true},
      {pattern: 'dist/**/*.css', included: true, served: true, watched: true},

      // paths to support debugging with source maps in dev tools
      {pattern: 'src/**/*.ts', included: false, watched: false},
      {pattern: 'dist/**/*.js.map', included: false, watched: false}
    ],

    // proxied base paths
    proxies: {
      // required for component assets fetched by Angular's compiler
      '/src/': '/base/src/'
    },

    port: 9876,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    colors: true,

    autoWatch: true,

    browsers: ['Chrome'],

    customLaunchers: {
      Chrome_travis_ci: {
        base: 'Chrome',
        flags: ['--no-sandbox']
      }
    },

    // Karma plugins loaded
    plugins: [
      'karma-jasmine',
      'karma-coverage',
      'karma-chrome-launcher',
      'karma-mocha-reporter',
      'karma-jasmine-html-reporter'
    ],

    // Coverage reporter generates the coverage
    reporters: ['mocha', 'coverage', 'kjhtml'],

    // Source files that you wanna generate coverage for.
    // Do not include tests or libraries (these files will be instrumented by Istanbul)
    preprocessors: {
      'dist/**/!(*spec).js': ['coverage']
    },

    coverageReporter: {
      dir: 'coverage/',
      subdir: 'report',
      reporters: [
        {type: 'text'},
        {type: 'text-summary'},
        {type: 'json', file: 'coverage-final.json'},
        {type: 'html'}
      ]
    }
  };

  if (process.env.TRAVIS) {
    configuration.browsers = ['Chrome_travis_ci'];
  }

  config.set(configuration)
};
<commit_msg>Fix 'Search' unit tests runner<commit_after>'use strict';

module.exports = function (config) {
  var configuration = {
    basePath: '.',

    frameworks: ['jasmine'],

    files: [
      // paths loaded by Karma
      {pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true},
      {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
      {pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true},
      {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
      {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
      {pattern: 'node_modules/@angular/**/*.map', included: false, watched: false},

      {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
      {pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false},

      {pattern: 'karma-test-shim.js', included: true, watched: true},

      // paths loaded via module imports
      {pattern: 'dist/**/*.js', included: false, watched: true},
      {pattern: 'dist/**/*.html', included: true, served: true, watched: true},
      {pattern: 'dist/**/*.css', included: true, served: true, watched: true},

      // paths to support debugging with source maps in dev tools
      {pattern: 'src/**/*.ts', included: false, watched: false},
      {pattern: 'dist/**/*.js.map', included: false, watched: false}
    ],

    exclude: [
      'node_modules/**/*spec.js'
    ],

    // proxied base paths
    proxies: {
      // required for component assets fetched by Angular's compiler
      '/src/': '/base/src/'
    },

    port: 9876,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    colors: true,

    autoWatch: true,

    browsers: ['Chrome'],

    customLaunchers: {
      Chrome_travis_ci: {
        base: 'Chrome',
        flags: ['--no-sandbox']
      }
    },

    // Karma plugins loaded
    plugins: [
      'karma-jasmine',
      'karma-coverage',
      'karma-chrome-launcher',
      'karma-mocha-reporter',
      'karma-jasmine-html-reporter'
    ],

    // Coverage reporter generates the coverage
    reporters: ['mocha', 'coverage', 'kjhtml'],

    // Source files that you wanna generate coverage for.
    // Do not include tests or libraries (these files will be instrumented by Istanbul)
    preprocessors: {
      'dist/**/!(*spec).js': ['coverage']
    },

    coverageReporter: {
      dir: 'coverage/',
      subdir: 'report',
      reporters: [
        {type: 'text'},
        {type: 'text-summary'},
        {type: 'json', file: 'coverage-final.json'},
        {type: 'html'}
      ]
    }
  };

  if (process.env.TRAVIS) {
    configuration.browsers = ['Chrome_travis_ci'];
  }

  config.set(configuration)
};
<|endoftext|>