bootstrap unit tests

This commit is contained in:
vdice 2015-06-08 14:17:36 -06:00
parent 93e9fa5e58
commit 5d9feb0fb3
7 changed files with 751 additions and 434 deletions

View File

@ -1,10 +1,15 @@
NPM = npm
BROWSERIFY = node_modules/.bin/browserify
NODE_BIN_PATH = node_modules/.bin
BROWSERIFY = $(NODE_BIN_PATH)/browserify
COFFEELINT = $(NODE_BIN_PATH)/coffeelint
KARMA = $(NODE_BIN_PATH)/karma
GLOBAL_FLAGS = -x jquery -e
OUTPUT_DIR = .
DEPLOY_DIR = libs
all: compile deploy clean
.PHONY: all compile debug compile-debug app clean deploy test
all: compile deploy test clean
compile:FLAGS = $(GLOBAL_FLAGS)
compile: app
@ -22,3 +27,9 @@ clean:
deploy:
@mkdir -p $(DEPLOY_DIR) && cp $(OUTPUT_DIR)/*.bundle.js $(DEPLOY_DIR) && ./bump-js-versions.sh
coffeelint:
$(COFFEELINT) *.coffee test/spec/*.coffee
test: coffeelint
$(KARMA) start karma.conf.coffee

129
coffeelint.json Normal file
View File

@ -0,0 +1,129 @@
{
"arrow_spacing": {
"level": "ignore"
},
"braces_spacing": {
"level": "ignore",
"spaces": 0,
"empty_object_spaces": 0
},
"camel_case_classes": {
"level": "error"
},
"coffeescript_error": {
"level": "error"
},
"colon_assignment_spacing": {
"level": "ignore",
"spacing": {
"left": 0,
"right": 0
}
},
"cyclomatic_complexity": {
"value": 10,
"level": "ignore"
},
"duplicate_key": {
"level": "error"
},
"empty_constructor_needs_parens": {
"level": "ignore"
},
"ensure_comprehensions": {
"level": "warn"
},
"eol_last": {
"level": "ignore"
},
"indentation": {
"value": 2,
"level": "error"
},
"line_endings": {
"level": "ignore",
"value": "unix"
},
"max_line_length": {
"value": 160,
"level": "error",
"limitComments": true
},
"missing_fat_arrows": {
"level": "ignore",
"is_strict": false
},
"newlines_after_classes": {
"value": 3,
"level": "ignore"
},
"no_backticks": {
"level": "error"
},
"no_debugger": {
"level": "warn",
"console": false
},
"no_empty_functions": {
"level": "ignore"
},
"no_empty_param_list": {
"level": "ignore"
},
"no_implicit_braces": {
"level": "ignore",
"strict": true
},
"no_implicit_parens": {
"strict": true,
"level": "ignore"
},
"no_interpolation_in_single_quotes": {
"level": "ignore"
},
"no_plusplus": {
"level": "ignore"
},
"no_stand_alone_at": {
"level": "ignore"
},
"no_tabs": {
"level": "error"
},
"no_this": {
"level": "ignore"
},
"no_throwing_strings": {
"level": "error"
},
"no_trailing_semicolons": {
"level": "error"
},
"no_trailing_whitespace": {
"level": "error",
"allowed_in_comments": false,
"allowed_in_empty_lines": true
},
"no_unnecessary_double_quotes": {
"level": "ignore"
},
"no_unnecessary_fat_arrows": {
"level": "warn"
},
"non_empty_constructor_needs_parens": {
"level": "ignore"
},
"prefer_english_operator": {
"level": "ignore",
"doubleNotLevel": "ignore"
},
"space_operators": {
"level": "ignore"
},
"spacing_after_comma": {
"level": "ignore"
},
"transform_messes_up_line_numbers": {
"level": "warn"
}
}

49
karma.conf.coffee Normal file
View File

@ -0,0 +1,49 @@
module.exports = (config) ->
config.set
basePath: ''
frameworks: [
'mocha'
'commonjs'
'chai-jquery'
'chai'
'jquery-2.1.0'
]
files: [
# Modules under test - list specific
'./modules/**/Settings.js'
'./modules/**/UIUtil.js'
# Spec files
'./test/spec/**/*Spec.coffee'
]
exclude: []
preprocessors:
# Modules under test
'./modules/**/*.js': [ 'commonjs' ]
# Spec files
'./test/spec/**/*Spec.coffee': [ 'coffee', 'commonjs' ]
commonjsPreprocessor:
shouldExecFile: (file) ->
file.path.indexOf('/spec/') > -1
processContent: (content, file, cb) ->
cb("'use strict';\n" + content)
coffeePreprocessor:
options:
bare: true
sourceMap: false
reporters: [ 'progress' ]
port: 9876
colors: true
logLevel: config.LOG_INFO
autoWatch: true
browsers: [ 'PhantomJS' ]
singleRun: true

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
"browser"
],
"scripts": {
"test": "make compile"
"test": "make"
},
"author": "",
"readmeFilename": "README.md",
@ -27,7 +27,22 @@
"retry": "0.6.1"
},
"devDependencies": {
"browserify": "^10.2.3"
"browserify": "^10.2.3",
"chai": "^3.0.0",
"chai-jquery": "^2.0.0",
"coffee-script": "^1.9.3",
"coffeelint": "^1.10.1",
"jquery": "^2.1.4",
"karma": "^0.12.36",
"karma-chai": "^0.1.0",
"karma-chai-jquery": "^1.0.0",
"karma-coffee-preprocessor": "^0.2.1",
"karma-commonjs-plus": "^1.0.0",
"karma-jquery": "^0.1.0",
"karma-mocha": "^0.1.10",
"karma-phantomjs-launcher": "^0.2.0",
"mocha": "^2.2.5",
"phantomjs": "^1.9.17"
},
"license": "MIT"
}

View File

@ -0,0 +1,64 @@
'use strict'
describe 'Settings', ->
Settings = require('../../modules/settings/Settings')
generated_uid = window.localStorage.jitsiMeetId
afterEach ->
window.localStorage.clear()
it 'should initialize correctly', ->
settings = Settings.getSettings()
assert.propertyVal settings, 'displayName', ''
assert.propertyVal settings, 'email', ''
assert.propertyVal settings, 'language', undefined
assert.propertyVal settings, 'uid', generated_uid
describe '#setDisplayName(displayName)', ->
it 'should be able to set global display name', ->
Settings.setDisplayName('My Name')
assert.propertyVal Settings.getSettings(), 'displayName', 'My Name'
it 'should set localStorage displayname', ->
Settings.setDisplayName('My Name')
assert.equal window.localStorage.displayname, 'My Name'
describe '#setEmail(email)', ->
it 'should be able to set a global email address', ->
Settings.setEmail 'my@email.com'
assert.propertyVal Settings.getSettings(), 'email', 'my@email.com'
it 'should set localStorage email', ->
Settings.setEmail 'my@email.com'
assert.equal window.localStorage.email, 'my@email.com'
describe '#setLanguage(language)', ->
it 'should be able to get set global language', ->
Settings.setLanguage 'Russian'
assert.propertyVal Settings.getSettings(), 'language', 'Russian'
it 'should set localStorage language', ->
Settings.setLanguage 'Russian'
assert.equal window.localStorage.language, 'Russian'
describe '#getSettings()', ->
before ->
Settings.setDisplayName 'foo'
Settings.setEmail 'foo@bar'
Settings.setLanguage 'Luxembourgish'
it 'should be able to get displayName', ->
assert.propertyVal Settings.getSettings(), 'displayName', 'foo'
it 'should be able to get email', ->
assert.propertyVal Settings.getSettings(), 'email', 'foo@bar'
it 'should be able to get language', ->
assert.propertyVal Settings.getSettings(), 'language', 'Luxembourgish'
it 'should be able to get uid', ->
assert.propertyVal Settings.getSettings(), 'uid', generated_uid

View File

@ -0,0 +1,16 @@
'use strict'
describe 'UIUtilSpec', ->
UIUtil = require('../../modules/UI/util/UIUtil')
describe '#buttonClick(id, classname)', ->
it 'should add the class to the clicked element', ->
document.body.innerHTML = '<div id="test">test</div>'
UIUtil.buttonClick('#test', "hidden")
$('#test').should.have.class('hidden')
it 'should remove the class to the clicked element', ->
document.body.innerHTML = '<div id="test" class="hidden">test</div>'
UIUtil.buttonClick('#test', "hidden")
$('#test').should.not.have.class('hidden')