noflo = require 'noflo'
unless noflo.isBrowser()
  chai = require 'chai' unless chai
  module = require '../components/TouchSensor2.coffee'
else
  module = require 'noflo-legoev3/components/TouchSensor2.js'

describe 'TouchSensor2 component', ->
  c = null
  port = null
  kick = null

  beforeEach ->
    c = module.getComponent()
    port = noflo.internalSocket.createSocket()
    c.inPorts.port.attach port
    kick = noflo.internalSocket.createSocket()
    c.inPorts.kick.attach kick

  describe 'when instantiated', ->
    it 'should have an input port', ->
      chai.expect(c.inPorts.kick).to.be.an 'object'
    it 'should have an input port', ->
      chai.expect(c.inPorts.port).to.be.an 'object'
    it 'should have an output port', ->
      chai.expect(c.outPorts.value).to.be.an 'object'

  describe 'when kicked', ->
    it 'starts up the watcher', ->
      kick.send true
      kick.disconnect()
      chai.expect(c.running).to.be.true

