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

New Test Suit #47

Merged
merged 8 commits into from
Jul 12, 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
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "0.10"

install:
- npm install

before_script:
- ./node_modules/.bin/gulp libs && ./node_modules/.bin/gulp coffee-test

27 changes: 24 additions & 3 deletions gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exec = Promise.promisify (require 'child_process').exec
STYLES_PATH = require './src/themes/styl.includes.coffee'
COFFEE_PATH = ['./src/components/**/*.coffee','./src/core/**/*.coffee','./src/init.coffee']
LIBS_PATH = ['./libs/*.js']
TEST_PATH = ['./src/**/*.test.coffee']
TEST_PATH = ['./test/**/*.test.coffee']
LIBS = require './src/lib.includes.coffee'

# Helpers
Expand Down Expand Up @@ -217,16 +217,37 @@ gulp.task 'coffee-test', ->
.pipe gulp.dest 'test'


testFiles = [
'./test/kd.libs.js'
'./test/kd.test.js'
]

gulp.task 'karma', ['coffee-test'], ->

gulp.src ['./test/kd.*']
gulp.src testFiles
.pipe karma
configFile : 'karma.conf.js'
action : karmaAction

gulp.task 'karma-headless', ['coffee-test'], ->

return gulp.src testFiles
.pipe karma
configFile : 'karma.conf.js'
action : 'watch'
browsers : ['PhantomJS']

gulp.task 'karma-travis', ['coffee-test'], ->

return gulp.src testFiles
.pipe karma
configFile : 'karma.conf.js'
action : 'run'
browsers : ['PhantomJS']
reporters : ['dots']

gulp.task 'sauce', ->
gulp.src ['./test/kd.*']
gulp.src testFiles
.pipe karma
browsers : [
'sl_firefox_windows'
Expand Down
9 changes: 5 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'test/kd.libs.js'
'test/kd.libs.js',
'test/kd.test.js'
],

sauceLabs: {
Expand Down Expand Up @@ -57,21 +58,21 @@ module.exports = function(config) {

// list of files to exclude
exclude: [

],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {

},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
reporters: ['spec'],


// web server port
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "a non-document focused UI Framework for web applications.",
"main": "gulpfile.js",
"scripts": {
"test": ""
"test": "./node_modules/karma/bin/karma start --browsers PhantomJS --single-run"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,6 +40,8 @@
"karma-mocha": "^0.1.3",
"karma-chrome-launcher": "^0.1.2",
"karma-firefox-launcher": "^0.1.3",
"karma-spec-reporter": "0.0.12",
"karma-phantomjs-launcher": "~0.1",
"gulp-karma": "0.0.4",
"gulp-buffer": "0.0.2",
"browserify": "^3.33.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{assert} = require 'chai'
sinon = require 'sinon'
KDButtonBar = require '../buttonbar'
KDButtonBar = require '../../../src/components/buttons/buttonbar.coffee'

describe 'KDButtonBar', ->
beforeEach ->
Expand Down
2 changes: 2 additions & 0 deletions test/components/list/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
describe 'List', ->
require './listviewcontroller.test.coffee'
96 changes: 96 additions & 0 deletions test/components/list/listviewcontroller.test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{assert, expect} = require 'chai'
sinon = require 'sinon'
KDListViewController = require '../../../src/components/list/listviewcontroller.coffee'
KDListView = require '../../../src/components/list/listview.coffee'

describe 'KDListViewController', ->
beforeEach -> @sinon = sinon.sandbox.create()
afterEach -> @sinon.restore()

describe 'constructor', ->
it 'should instantiate without error', ->
viewController = new KDListViewController
expect(viewController).to.be.ok

it 'should set listview if listview has been passed as an option', ->
listViewStub = sinon.createStubInstance KDListView
viewController = new KDListViewController { view: listViewStub }

expect(viewController.listView).to.be.equal(listViewStub)

it 'should set listview even if there is no view option passed', ->
viewController = new KDListViewController
expect(viewController.listView).to.be.instanceof(KDListView)

it "shouldn't have scrollView if there is a scrollview option as false", ->
viewController = new KDListViewController { scrollView: no }
expect(viewController.scrollView).to.be.not.ok

describe 'instantiateListItems', ->
it "should call listview's addItem method", ->
listViewStub = sinon.createStubInstance KDListView
viewController = new KDListViewController { view: listViewStub }

items = [1, 2]
listViewStub.addItem = (item) -> item * 2
result = viewController.instantiateListItems items

expect(result).to.eql [2, 4]

it "emits 'AllItemsAddedToList' event when it instantiates new items", ->
listViewStub = sinon.createStubInstance KDListView
listViewStub.addItem = (item) -> item * 2
viewController = new KDListViewController { view: listViewStub }
sinon.spy(viewController, 'emit')

viewController.instantiateListItems [1, 2]

assert viewController.emit.called

describe 'putNoItemView', ->
it 'should add no item found widget view to subviews', ->
listViewStub = sinon.createStubInstance KDListView
widget = sinon.stub()
viewController = new KDListViewController
view : listViewStub
noItemFoundWidget : widget

viewController.putNoItemView()

assert listViewStub.addSubView.withArgs(widget).calledOnce

describe 'addItem', ->
beforeEach ->
@listViewStub = sinon.createStubInstance KDListView
@viewController = new KDListViewController
view : @listViewStub

it "adds item to its list view", ->
@viewController.addItem 1, 2

assert @listViewStub.addItem.withArgs(1, 2).calledOnce

it "doesn't add item to its list view when args don't exist", ->
@viewController.addItem

assert.notOk @listViewStub.addItem.called

describe 'removeItem', ->
beforeEach ->
@listViewStub = sinon.createStubInstance KDListView
@viewController = new KDListViewController
view : @listViewStub

it "adds item to its list view", ->
itemInstanceStub = sinon.stub()
@viewController.removeItem itemInstanceStub, 1, 2

assert @listViewStub.removeItem.withArgs(itemInstanceStub, 1, 2).calledOnce

it "doesn't add item to its list view when args don't exist", ->
@viewController.removeItem
assert.notOk @listViewStub.removeItem.called

describe 'registerItem', ->
it

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require 'chai'
KDController = require '../controller'
KDController = require '../../src/core/controller'

describe 'KDController', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require 'chai'
KDCustomhtmlview = require '../customhtmlview'
KDCustomhtmlview = require '../../src/core/customhtmlview'

describe 'KDCustomhtmlview', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require('chai')
KDEventEmitter = require('../eventemitter')
KDEventEmitter = require('../../src/core/eventemitter')

describe 'KDEventEmitter', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require('chai')
KDEventEmitterWildcard = require('../eventemitterwildcard')
KDEventEmitterWildcard = require('../../src/core/eventemitterwildcard')

describe 'KDEventEmitterWildcard', ->

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/test/kd.test.coffee → test/core/kd.test.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{assert} = require('chai')
sinon = require('sinon')
kd = require('../kd')
kd = require('../../src/core/kd')

describe 'KD core', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require('chai')
KDObject = require('../object')
KDObject = require('../../src/core/object')

describe 'KDObject', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require 'chai'
KDRouter = require '../router'
KDRouter = require '../../src/core/router'

describe 'KDRouter', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require 'chai'
KDUtils = require '../utils'
KDUtils = require '../../src/core/utils'

describe 'KDUtils', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require('chai')
KDView = require('../view')
KDView = require('../../src/core/view')

describe 'KDView', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require 'chai'
KDViewController = require '../viewcontroller'
KDViewController = require '../../src/core/viewcontroller'

describe 'KDViewController', ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{assert} = require 'chai'
KDWindowController = require '../windowcontroller'
KDWindowController = require '../../src/core/windowcontroller'

describe 'KDWindowController', ->

Expand Down
22 changes: 22 additions & 0 deletions test/phantomjs_polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 139 bytes gzipped
/*! (C) WebReflection, Mit Style License */
(function (P) {
'use strict';
if (!P.bind) {
P.bind = function (s) {
var
c = this,
l = [].slice,
a = l.call(arguments, 1);
return function bind() {
return c.apply(s, a.concat(l.call(arguments)));
};
};
}
}(Function.prototype));

console = {}
console.log = function() {}
console.warn = function() {}
console.error = function() {}

6 changes: 4 additions & 2 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require('../src/core/test')
require('../src/components/buttons/test')
require('./phantomjs_polyfill')
require('./core')
require('./components/buttons')
require('./components/list')