Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Test stubs for Core modules #4

Merged
merged 4 commits into from
Mar 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/core/eventemitter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

module.exports = class KDEventEmitter

@registerWildcardEmitter = ->
source = @Wildcard.prototype
@::[prop] = val for own prop, val of source when prop isnt 'constructor'

@registerStaticEmitter = ->
# static listeners will be put here
@_e = {}
Expand Down
42 changes: 5 additions & 37 deletions src/core/kd.coffee
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
utils = window.utils = require './utils.coffee'

Function::bind or= (context) ->
if 1 < arguments.length
args = [].slice.call arguments, 1
return => @apply context, if arguments.length then args.concat [].slice.call arguments else args
=> if arguments.length then @apply context, arguments else @call context

Function::swiss = (parent, names...)->
for name in names
@::[name] = parent::[name]
@

# Cross-Browser DOM dependencies
window.URL ?= window.webkitURL ? null
window.BlobBuilder ?= window.WebKitBlobBuilder ? window.MozBlobBuilder ? null
window.requestFileSystem ?= window.webkitRequestFileSystem ? null
window.requestAnimationFrame ?= window.webkitRequestAnimationFrame ? window.mozRequestAnimationFrame ? null

# FIXME: add to utils.coffee
String.prototype.capitalize = ()-> this.charAt(0).toUpperCase() + this.slice(1)
String.prototype.decapitalize = ()-> this.charAt(0).toLowerCase() + this.slice(1)
String.prototype.trim = ()-> this.replace(/^\s+|\s+$/g,"")

# Dict = Object.create.bind null, null, Object.create null

do (arrayProto = Array.prototype, {defineProperty} = Object)->
# set up .first and .last getters for Array prototype

"last" of arrayProto or
defineProperty arrayProto, "last", { get: -> @[@length-1] }

"first" of arrayProto or
defineProperty arrayProto, "first", { get: -> @[0] }
require './support'

# KD Global
window.KD or= {}
Expand All @@ -42,7 +10,6 @@ KD.log = window.log = noop
KD.warn = window.warn = noop
KD.error = window.error = noop


unless window.event?
try
# warn when the global "event" property is accessed.
Expand Down Expand Up @@ -75,6 +42,9 @@ window.KD = $.extend (window.KD), do ->

unregisterInstance: (anInstanceId)->
# warn "Instance being unregistered doesn't exist in registry!!", anInstance unless @instances[anInstance.id]

# FIXME (sb) - delete puts JITs into SLOW mode for that object, forever. We
# should consider using _.omit for cases like this
delete @instances[anInstanceId]

deleteInstance:(anInstanceId)->
Expand Down Expand Up @@ -123,6 +93,4 @@ window.KD = $.extend (window.KD), do ->

getInstanceForTesting:(key)-> @instancesToBeTested[key]

prettyPrint = noop

module.exports = KD
module.exports = KD
33 changes: 33 additions & 0 deletions src/core/support.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Pollyfils for older browsers, most of this is probably depreacted

# FIXME (sb) - these cases should be converted to use _.bind
Function::bind or= (context) ->
if 1 < arguments.length
args = [].slice.call arguments, 1
return => @apply context, if arguments.length then args.concat [].slice.call arguments else args
=> if arguments.length then @apply context, arguments else @call context


# Cross-Browser DOM dependencies
window.URL ?= window.webkitURL ? null
window.BlobBuilder ?= window.WebKitBlobBuilder ? window.MozBlobBuilder ? null
window.requestFileSystem ?= window.webkitRequestFileSystem ? null
window.requestAnimationFrame ?= window.webkitRequestAnimationFrame ? window.mozRequestAnimationFrame ? null

# FIXME: add to utils.coffee
String.prototype.capitalize = ()-> this.charAt(0).toUpperCase() + this.slice(1)
# FIXME:
String.prototype.trim = ()-> this.replace(/^\s+|\s+$/g,"")


do (arrayProto = Array.prototype, {defineProperty} = Object)->
# set up .first and .last getters for Array prototype

"last" of arrayProto or
defineProperty arrayProto, "last", { get: -> @[@length-1] }

"first" of arrayProto or
defineProperty arrayProto, "first", { get: -> @[0] }



13 changes: 13 additions & 0 deletions src/core/test/controller.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{assert} = require 'chai'
KDController = require '../controller'

describe 'KDController', ->

it 'exists', ->
assert.ok(KDController)

describe 'constructor', ->

it 'should instantiate without error', ->
router = new KDController
assert.ok(router)
13 changes: 13 additions & 0 deletions src/core/test/customhtmlview.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{assert} = require 'chai'
KDCustomhtmlview = require '../customhtmlview'

describe 'KDCustomhtmlview', ->

it 'exists', ->
assert.ok(KDCustomhtmlview)

describe 'constructor', ->

it 'should instantiate without error', ->
router = new KDCustomhtmlview
assert.ok(router)
7 changes: 7 additions & 0 deletions src/core/test/eventemitter.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{assert} = require('chai')
KDEventEmitter = require('../eventemitter')

describe 'KDEventEmitter', ->

it 'exists', ->
assert.ok(KDEventEmitter)
7 changes: 7 additions & 0 deletions src/core/test/eventemitterwildcard.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{assert} = require('chai')
KDEventEmitterWildcard = require('../eventemitterwildcard')

describe 'KDEventEmitterWildcard', ->

it 'exists', ->
assert.ok(KDEventEmitterWildcard)
16 changes: 16 additions & 0 deletions src/core/test/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe 'Core', ->
require './kd.test'
require './object.test'
require './utils.test'
require './router.test'
require './eventemitter.test'
require './eventemitterwildcard.test'

require './controller.test'
require './viewcontroller.test'
require './windowcontroller.test'

require './view.test'
require './customhtmlview.test'
require './scrollview.test'

38 changes: 38 additions & 0 deletions src/core/test/kd.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{assert} = require('chai')
sinon = require('sinon')
kd = require('../kd')

describe 'KD core', ->

it 'attaches to the window', ->
assert.ok(window.KD)

describe 'KD.create', ->

beforeEach ->
@classes = kd.classes

afterEach ->
kd.classes = @classes

it 'should create a new object from a registered KD class', ->
stub = sinon.stub()

kd.classes.foo = class Foo
constructor: stub

kd.create 'foo'

assert.ok(stub.called)

xdescribe 'registerInstance', ->

xdescribe 'unregisterInstance', ->

xdescribe 'deleteInstance', ->

xdescribe 'extend', ->

xdescribe 'registerSingleton', ->

xdescribe 'getSingleton', ->
12 changes: 12 additions & 0 deletions src/core/test/object.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{assert} = require('chai')
KDObject = require('../object')

describe 'KDObject', ->

it 'exists', ->
assert.ok(KDObject)

describe 'constructor', ->
it 'should instantiate without error', ->
o = new KDObject()
assert.ok(o)
13 changes: 13 additions & 0 deletions src/core/test/router.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{assert} = require 'chai'
KDRouter = require '../router'

describe 'KDRouter', ->

it 'exists', ->
assert.ok(KDRouter)

describe 'constructor', ->

it 'should instantiate without error', ->
router = new KDRouter
assert.ok(router)
14 changes: 14 additions & 0 deletions src/core/test/scrollview.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{assert} = require 'chai'
KDScrollview = require '../scrollview'

describe 'KDScrollview', ->

it 'exists', ->
assert.ok(KDScrollview)

describe 'constructor', ->

it 'should instantiate without error', ->
router = new KDScrollview
assert.ok(router)

9 changes: 9 additions & 0 deletions src/core/test/utils.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{assert} = require 'chai'
KDUtils = require '../utils'

describe 'KDUtils', ->

it 'exists', ->
assert.ok(KDUtils)

it 'should test each method in utils, auditing usage and deprecating unused methods'
12 changes: 12 additions & 0 deletions src/core/test/view.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{assert} = require('chai')
KDView = require('../view')

describe 'KDView', ->

it 'exists', ->
assert.ok(KDView)

describe 'constructor', ->
it 'should instantiate without error', ->
o = new KDView()
assert.ok(o)
13 changes: 13 additions & 0 deletions src/core/test/viewcontroller.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{assert} = require 'chai'
KDViewController = require '../viewcontroller'

describe 'KDViewController', ->

it 'exists', ->
assert.ok(KDViewController)

describe 'constructor', ->

it 'should instantiate without error', ->
router = new KDViewController
assert.ok(router)
13 changes: 13 additions & 0 deletions src/core/test/windowcontroller.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{assert} = require 'chai'
KDWindowController = require '../windowcontroller'

describe 'KDWindowController', ->

it 'exists', ->
assert.ok(KDWindowController)

describe 'constructor', ->

it 'should instantiate without error', ->
router = new KDWindowController
assert.ok(router)
7 changes: 1 addition & 6 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
assert = require('chai').assert
KDView = require '../src/core/view'

describe 'KDView', ->
it 'exists', ->
assert.ok(KDView)
require('../src/core/test')