describe 'mixco.script', ->
{isinstance} = require '../../mixco/multi'
{Script, register} = require '../../mixco/script'
control = require '../../mixco/control'
class TestScript extends Script
describe 'Script', ->
script = null
beforeEach ->
script = new TestScript
it 'configures controller id to be de script name', ->
expect(script.config())
.toMatch "<controller id=\"testscript\">[^$]*</controller>"
it 'can generate configuration with partial metadata', ->
delete script.info.wiki
expect(script.config())
.not.toContain "undefined"
describe 'register', ->
it 'registers a class in the given NodeJs module', ->
testModule = exports: {}
register testModule, TestScript
expect(isinstance testModule.exports.testscript, TestScript)
.toBe true
it 'can generate a script type from a definition', ->
spy = createSpyObj 'scriptSpy', [
'constructor', 'preinit', 'init', 'shutdown', 'postshutdown' ]
testModule = exports: {}
register testModule,
name: 'awesome_script'
constructor: -> spy.constructor()
preinit: ->
spy.preinit()
expect(@_isInit).not.toBeDefined()
init: -> spy.init()
postshutdown: ->
spy.postshutdown()
expect(@_isInit).not.toBeDefined()
shutdown: -> spy.shutdown()
info: author: 'Jimmy Jazz'
script = testModule.exports.awesome_script
expect(script.name).toBe 'awesome_script'
expect(script.info.author).toBe 'Jimmy Jazz'
expect(spy.constructor).toHaveBeenCalled()
script.init()
expect(spy.preinit).toHaveBeenCalled()
expect(spy.init).toHaveBeenCalled()
script.shutdown()
expect(spy.shutdown).toHaveBeenCalled()
expect(spy.postshutdown).toHaveBeenCalled()
it 'controls created during construction are registered autoamtically', ->
testModule = exports: {}
expectedControls = []
register testModule,
name: 'some_script'
constructor: ->
expectedControls.push control.knob()
expectedControls.push control.ledButton()
expect(expectedControls.length)
.toBe 2
expect(testModule.exports.some_script.controls)
.toEqual expectedControls