forked from lxm_front/Mergely
added test
This commit is contained in:
62
karma.conf.js
Normal file
62
karma.conf.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const webpackCfg = require('./webpack.config');
|
||||||
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = function(config) {
|
||||||
|
config.set({
|
||||||
|
basePath: './',
|
||||||
|
|
||||||
|
browsers: [
|
||||||
|
'ChromeHeadless'
|
||||||
|
],
|
||||||
|
|
||||||
|
frameworks: [
|
||||||
|
'mocha', 'chai'
|
||||||
|
],
|
||||||
|
|
||||||
|
files: [
|
||||||
|
'node_modules/codemirror/lib/codemirror.css',
|
||||||
|
'src/mergely.css',
|
||||||
|
'tests/**/*.spec.js'
|
||||||
|
],
|
||||||
|
|
||||||
|
preprocessors: {
|
||||||
|
'node_modules/jquery/dist/jquery.js': ['webpack'],
|
||||||
|
'node_modules/codemirror/lib/codemirror.js': ['webpack'],
|
||||||
|
'tests/**/*.spec.js': ['webpack'],
|
||||||
|
'src/**/*.js': ['webpack']
|
||||||
|
},
|
||||||
|
|
||||||
|
reporters: ['mocha'],
|
||||||
|
mochaReporter: {
|
||||||
|
showDiff: true
|
||||||
|
},
|
||||||
|
|
||||||
|
singleRun: true,
|
||||||
|
client: {
|
||||||
|
captureConsole: true,
|
||||||
|
mocha: {}
|
||||||
|
},
|
||||||
|
webpack: {
|
||||||
|
entry: './src/mergely.js',
|
||||||
|
module: {
|
||||||
|
loaders: [
|
||||||
|
{ test: /\.css$/, loader: ExtractTextPlugin.extract('css-loader') }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.js'],
|
||||||
|
alias: {
|
||||||
|
CodeMirror: path.join(__dirname, 'node_modules', 'codemirror'),
|
||||||
|
jQuery: path.join(__dirname, 'node_modules', 'jquery')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new ExtractTextPlugin('mergely.css')
|
||||||
|
]
|
||||||
|
},
|
||||||
|
webpackServer: {
|
||||||
|
noInfo: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
12
package.json
12
package.json
@@ -9,7 +9,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf lib && webpack",
|
"build": "rm -rf lib && webpack",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "karma start",
|
||||||
|
"test:chrome": "karma start --browsers Chrome --singleRun=false"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -37,12 +38,21 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/wickedest/Mergely#readme",
|
"homepage": "https://github.com/wickedest/Mergely#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"chai": "^4.1.2",
|
||||||
"codemirror": "^5.32.0",
|
"codemirror": "^5.32.0",
|
||||||
"css-loader": "^0.28.7",
|
"css-loader": "^0.28.7",
|
||||||
"extract-text-webpack-plugin": "^3.0.2",
|
"extract-text-webpack-plugin": "^3.0.2",
|
||||||
"file-loader": "^1.1.5",
|
"file-loader": "^1.1.5",
|
||||||
"image-webpack-loader": "^3.4.2",
|
"image-webpack-loader": "^3.4.2",
|
||||||
"jquery": "^3.2.1",
|
"jquery": "^3.2.1",
|
||||||
|
"karma": "^2.0.0",
|
||||||
|
"karma-chai": "^0.1.0",
|
||||||
|
"karma-chrome-launcher": "^2.2.0",
|
||||||
|
"karma-coverage-istanbul-reporter": "^1.3.0",
|
||||||
|
"karma-mocha": "^1.3.0",
|
||||||
|
"karma-mocha-reporter": "^2.2.5",
|
||||||
|
"karma-webpack": "^2.0.9",
|
||||||
|
"mocha": "^4.0.1",
|
||||||
"webpack": "^3.8.1"
|
"webpack": "^3.8.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
74
tests/mergely.spec.js
Normal file
74
tests/mergely.spec.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
const jQuery = require('jquery');
|
||||||
|
const CodeMirror = require('CodeMirror');
|
||||||
|
const mergely = require('../src/mergely');
|
||||||
|
const $ = jQuery;
|
||||||
|
|
||||||
|
(function($) {
|
||||||
|
$.fn.hasScrollBar = function() {
|
||||||
|
return this.get(0).scrollHeight - 2 > this.height();
|
||||||
|
}
|
||||||
|
})(jQuery);
|
||||||
|
|
||||||
|
|
||||||
|
describe('mergely', function () {
|
||||||
|
function init(options) {
|
||||||
|
$('body').css({'margin': '0px'}).append('<div id="mergely"></div>');
|
||||||
|
const editor = $('#mergely');
|
||||||
|
editor.mergely(options);
|
||||||
|
return editor;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('initialization', () => {
|
||||||
|
it('initializes without arguments', function (done) {
|
||||||
|
$(document).ready(() => {
|
||||||
|
const editor = init({
|
||||||
|
height: 100,
|
||||||
|
license: 'lgpl-separate-notice'
|
||||||
|
});
|
||||||
|
expect(editor).to.exist;
|
||||||
|
expect(editor.mergely).to.exist;
|
||||||
|
const children = editor.children();
|
||||||
|
expect(children.length).to.equal(6);
|
||||||
|
expect($(children[0]).attr('id')).to.equal('mergely-splash');
|
||||||
|
expect($(children[1]).attr('class')).to.equal('mergely-margin');
|
||||||
|
expect($(children[2]).attr('class')).to.equal('mergely-column');
|
||||||
|
expect($(children[3]).attr('class')).to.equal('mergely-canvas');
|
||||||
|
expect($(children[4]).attr('class')).to.equal('mergely-column');
|
||||||
|
expect($(children[5]).attr('class')).to.equal('mergely-margin');
|
||||||
|
expect($('body').hasScrollBar()).to.equal(false);
|
||||||
|
expect($('.mergely-editor-lhs .CodeMirror-code').text()).to.equal('');
|
||||||
|
expect($('.mergely-editor-rhs .CodeMirror-code').text()).to.equal('');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only('initializes with static arguments for lhs/rhs text', function (done) {
|
||||||
|
$(document).ready(() => {
|
||||||
|
const editor = init({
|
||||||
|
height: 100,
|
||||||
|
license: 'lgpl-separate-notice',
|
||||||
|
lhs: (setValue) => {
|
||||||
|
console.log('here');
|
||||||
|
setValue('left-hand side text')
|
||||||
|
},
|
||||||
|
rhs: (setValue) => setValue('right-hand side text'),
|
||||||
|
});
|
||||||
|
expect(editor).to.exist;
|
||||||
|
expect(editor.mergely).to.exist;
|
||||||
|
const children = editor.children();
|
||||||
|
expect(children.length).to.equal(6);
|
||||||
|
expect($(children[0]).attr('id')).to.equal('mergely-splash');
|
||||||
|
expect($(children[1]).attr('class')).to.equal('mergely-margin');
|
||||||
|
expect($(children[2]).attr('class')).to.equal('mergely-column');
|
||||||
|
expect($(children[3]).attr('class')).to.equal('mergely-canvas');
|
||||||
|
expect($(children[4]).attr('class')).to.equal('mergely-column');
|
||||||
|
expect($(children[5]).attr('class')).to.equal('mergely-margin');
|
||||||
|
expect($('body').hasScrollBar()).to.equal(false);
|
||||||
|
expect($('#mergely-editor-lhs .CodeMirror-code .CodeMirror-line').text()).to.equal('left-hand side text');
|
||||||
|
expect($('#mergely-editor-rhs .CodeMirror-code .CodeMirror-line').text()).to.equal('right-hand side text');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user