mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 02:44:01 +00:00
Add unit tests for Darkwire and App classes; add HTML fixtures
This commit is contained in:
parent
712c581083
commit
7e2a930fcf
@ -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');
|
||||
|
@ -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",
|
||||
|
@ -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');
|
||||
|
47
test/unit/app.js
Normal file
47
test/unit/app.js
Normal file
@ -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, '<a href="http://cnn.com" target="_blank">cnn.com</a>');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
56
test/unit/darkwire.js
Normal file
56
test/unit/darkwire.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
3
test/unit/fixtures/app.html
Normal file
3
test/unit/fixtures/app.html
Normal file
@ -0,0 +1,3 @@
|
||||
<div class='messages'></div>
|
||||
<input id='fileInput'></input>
|
||||
<input class='sound-enabled'></input>
|
@ -1 +1,3 @@
|
||||
require('./audio.js');
|
||||
require('./darkwire.js');
|
||||
require('./app.js');
|
||||
|
Loading…
x
Reference in New Issue
Block a user