From 38d31f535f8e0957b70adb9149ae8bb9a8acc545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerardo=20P=C3=A9rez?= Date: Fri, 11 Nov 2016 16:55:07 -0600 Subject: [PATCH] test(test): added test for EmberAppItem --- src/support/EmberAppItem.js | 22 +++++++++++++----- test/unit/support/EmberAppItem.js | 37 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 test/unit/support/EmberAppItem.js diff --git a/src/support/EmberAppItem.js b/src/support/EmberAppItem.js index 668bd5d..d8507c7 100644 --- a/src/support/EmberAppItem.js +++ b/src/support/EmberAppItem.js @@ -1,12 +1,22 @@ -const EAIEnum = ['name', 'mount', 'directory', 'access', 'adapter', 'subdomain', 'layout']; -const DefEAIEnum = ['emberapp', '/', '/emberapp', 'public', 'localhost', 'www', 'main']; +const Defaults = { + 'name': 'emberapp', + 'mount': '/', + 'directory': '/emberapp', + 'access':'public', + 'adapter':'localhost', + 'subdomain':'www', + 'layout':'main' +} + export default class EmberAppItem { - constructor(application, data) { - data.name = application; - for (let property of EAIEnum) { + constructor(...args) { + let [application, data] = args; + data = Object.assign({},Defaults,data||{}); + data.name = application || Defaults.name; + for (let property in Defaults) { Object.defineProperty(this, property, { enumerable: property !== 'name', - value: data[property] || DefEAIEnum[property] + value: data[property] }); } Object.freeze(this); diff --git a/test/unit/support/EmberAppItem.js b/test/unit/support/EmberAppItem.js new file mode 100644 index 0000000..dee8dc3 --- /dev/null +++ b/test/unit/support/EmberAppItem.js @@ -0,0 +1,37 @@ +/*global describe, it*/ +import * as assert from 'assert'; +import EmberAppItem from '../../../src/support/EmberAppItem'; + +describe('EmberAppItem', function() { + let App = new EmberAppItem(); + it('creates EmberApp Default config', function() { + assert.equal(App.name,'emberapp'); + assert.equal(App.mount,'/'); + assert.equal(App.directory,'/emberapp'); + assert.equal(App.access,'public'); + assert.equal(App.adapter,'localhost'); + assert.equal(App.subdomain,'www'); + assert.equal(App.layout,'main'); + }); + + it('creates EmberApp with config', function() { + App = new EmberAppItem('test',{mount:'/panel'}); + assert.equal(App.name,'test'); + assert.equal(App.mount,'/panel'); + assert.equal(App.directory,'/emberapp'); + assert.equal(App.access,'public'); + assert.equal(App.adapter,'localhost'); + assert.equal(App.subdomain,'www'); + assert.equal(App.layout,'main'); + }); + + it('is equal if name are the same',function(){ + let App2 = new EmberAppItem('test'); + + assert.equal(App.equals(App2),true); + }); + + it('returns app\' name',function(){ + assert.equal(App.valueOf(),'test'); + }); +});