2014-11-24 13:03:02 +00:00
|
|
|
_ = require('lodash')
|
2014-11-19 12:45:56 +00:00
|
|
|
expect = require('chai').expect
|
|
|
|
device = require('./device')
|
2014-11-24 12:54:35 +00:00
|
|
|
DEVICES = require('./device-data.json')
|
2014-11-19 12:45:56 +00:00
|
|
|
|
|
|
|
describe 'Device:', ->
|
|
|
|
|
|
|
|
describe '#getDisplayName()', ->
|
|
|
|
|
|
|
|
it 'should return Raspberry Pi for that device', ->
|
|
|
|
possibleNames = [
|
|
|
|
'raspberry-pi'
|
|
|
|
'raspberrypi'
|
|
|
|
'rpi'
|
|
|
|
]
|
|
|
|
|
|
|
|
for name in possibleNames
|
2014-11-19 12:50:11 +00:00
|
|
|
expect(device.getDisplayName(name)).to.equal('Raspberry Pi')
|
|
|
|
|
|
|
|
it 'should return unknown if no matches', ->
|
|
|
|
unknownNames = [
|
|
|
|
'hello'
|
|
|
|
'foobar'
|
|
|
|
{}
|
|
|
|
123
|
|
|
|
]
|
|
|
|
|
|
|
|
for name in unknownNames
|
|
|
|
expect(device.getDisplayName(name)).to.equal('Unknown')
|
2014-11-24 12:25:45 +00:00
|
|
|
|
2014-11-24 13:09:39 +00:00
|
|
|
it 'should return the name itself if passing the display name', ->
|
|
|
|
for supportedDevice in device.getSupportedDevices()
|
|
|
|
displayName = device.getDisplayName(supportedDevice)
|
|
|
|
expect(displayName).to.equal(supportedDevice)
|
|
|
|
|
2014-11-24 13:03:02 +00:00
|
|
|
describe '#getDeviceSlug()', ->
|
|
|
|
|
|
|
|
it 'should return valid slugs', ->
|
|
|
|
for key, value in DEVICES
|
|
|
|
expect(device.getDeviceSlug(key)).to.equal(value.slug)
|
2014-11-24 12:25:45 +00:00
|
|
|
|
2014-11-24 13:03:02 +00:00
|
|
|
it 'should return unknown if not valid device', ->
|
|
|
|
result = device.getDeviceSlug('Foo Bar')
|
|
|
|
expect(result).to.equal('unknown')
|
2014-11-24 12:54:35 +00:00
|
|
|
|
2014-11-24 13:03:02 +00:00
|
|
|
it 'should return a valid slug if using an alternative name', ->
|
|
|
|
for key, value in DEVICES
|
|
|
|
name = _.first(value.names)
|
|
|
|
expect(device.getDeviceSlug(name)).to.equal(value.slug)
|
|
|
|
|
|
|
|
describe '#getSupportedDevices()', ->
|
2014-11-24 12:54:35 +00:00
|
|
|
|
|
|
|
it 'should return an array', ->
|
2014-11-24 13:03:02 +00:00
|
|
|
expect(device.getSupportedDevices()).to.be.an.instanceof(Array)
|
2014-11-24 12:54:35 +00:00
|
|
|
|
2014-11-24 13:03:02 +00:00
|
|
|
it 'should have every supported device', ->
|
|
|
|
supportedDevices = device.getSupportedDevices()
|
|
|
|
for key, value in DEVICES
|
|
|
|
expect(supportedDevices.indexOf(key)).to.not.equal(-1)
|