diff --git a/karma.conf.js b/karma.conf.js index 6b79df8..ed0864b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -5,7 +5,7 @@ module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', + basePath: 'test/unit', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter @@ -13,7 +13,8 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - 'test/unit/index.js' + 'index.js', + 'fixtures/**/*.html' ], // list of files to exclude @@ -23,7 +24,8 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - 'test/unit/**/*.js': ['browserify'] + '**/*.js': ['browserify'], + 'fixtures/**/*.html': ['html2js'] }, // test results reporter to use @@ -58,6 +60,7 @@ module.exports = function(config) { browserify: { debug: true, + plugin: ['proxyquireify/plugin'], configure: function(bundle) { bundle.once('prebundle', function() { bundle.transform('babelify'); diff --git a/package.json b/package.json index 6445250..150d839 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "karma": "^0.13.21", "karma-browserify": "^5.0.2", "karma-chrome-launcher": "^0.2.2", + "karma-html2js-preprocessor": "^0.1.0", "karma-mocha": "^0.2.2", "mocha": "^2.4.5", "mocha-jscs": "^4.2.0", diff --git a/src/js/app.js b/src/js/app.js index ddecb8d..c793883 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -115,8 +115,6 @@ export default class App { $('#about-modal').modal('show'); }); - $('[data-toggle="tooltip"]').tooltip(); - $('.navbar .participants').click(() => { this.renderParticipantsList(); $('#participants-modal').modal('show'); diff --git a/test/unit/app.js b/test/unit/app.js new file mode 100644 index 0000000..2711ddc --- /dev/null +++ b/test/unit/app.js @@ -0,0 +1,47 @@ +import assert from 'assert'; +import sinon from 'sinon'; +import io from 'socket.io-client/socket.io.js'; +import $ from '../../src/public/vendor/jquery-1.10.2.min.js'; +import Favico from '../../src/public/favicon'; +import Autolinker from '../../src/public/vendor/autolinker.min.js'; + +window.io = io; +window.$ = window.jQuery = $; +window.Favico = Favico; +window.Autolinker = Autolinker; +window.$.fn.bootstrapSwitch = () => { + return { + on: () => { + return; + } + }; +}; +window.FastClick = { + attach: () => { + return true; + } +}; + +var proxyquire = require('proxyquireify')(require); + +var stubs = {}; + +var App = proxyquire('../../src/js/app.js', stubs).default; + +describe('App', () => { + + describe('cleanInput', () => { + + let app; + + before(() => { + app = new App(); + }); + + it('should create HTML links from URLs', () => { + let input = app.cleanInput('cnn.com'); + assert.equal(input, 'cnn.com'); + }); + }); + +}); diff --git a/test/unit/darkwire.js b/test/unit/darkwire.js new file mode 100644 index 0000000..4764d10 --- /dev/null +++ b/test/unit/darkwire.js @@ -0,0 +1,56 @@ +import assert from 'assert'; +import sinon from 'sinon'; + +var proxyquire = require('proxyquireify')(require); + +let importPrimaryKeyStub = sinon.stub(); + +var stubs = { + './crypto': { + default: function() { + return { + importPrimaryKey: importPrimaryKeyStub + }; + } + } +}; + +var Darkwire = proxyquire('../../src/js/darkwire.js', stubs).default; + +describe('Darkwire', () => { + + describe('adding users', () => { + + before(() => { + document.body.innerHTML = window.__html__['fixtures/app.html']; + window.username = 'alan'; + let darkwire = new Darkwire(); + darkwire._myUserId = 3; + darkwire.addUser( + { + users: [ + { + id: 1, + username: 'user 1', + publicKey: {} + }, + { + id: 2, + username: 'user 2', + publicKey: {} + } + ] + } + ); + }); + + after(() => { + importPrimaryKeyStub.reset(); + }); + + it('should import each users key', () => { + assert.equal(importPrimaryKeyStub.callCount, 2); + }); + }); + +}); diff --git a/test/unit/fixtures/app.html b/test/unit/fixtures/app.html new file mode 100644 index 0000000..4c476a8 --- /dev/null +++ b/test/unit/fixtures/app.html @@ -0,0 +1,3 @@ +
+ + \ No newline at end of file diff --git a/test/unit/index.js b/test/unit/index.js index 1c2e979..8ee7b67 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -1 +1,3 @@ require('./audio.js'); +require('./darkwire.js'); +require('./app.js');