mirror of
https://github.com/ONLYOFFICE/web-apps.git
synced 2026-04-07 14:06:16 +08:00
webapps added
This commit is contained in:
15
test/common.js
Normal file
15
test/common.js
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* common.js
|
||||
*
|
||||
* Created by Alexander Yuzhin on 5/7/14
|
||||
* Copyright (c) 2014 Ascensio System SIA. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
// Include and setup all the stuff for testing
|
||||
define([
|
||||
'chai'
|
||||
],function(chai) {
|
||||
window.expect = chai.expect;
|
||||
window.assert = chai.assert;
|
||||
});
|
||||
89
test/common/index.html
Normal file
89
test/common/index.html
Normal file
@ -0,0 +1,89 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Unit Tests</title>
|
||||
<link rel="stylesheet" href="../../build/node_modules/mocha/mocha.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="../../build/node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../../vendor/requirejs/require.js" type="text/javascript" charset="utf-8"></script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Partial config file
|
||||
require.config({
|
||||
// Base URL relative to the test runner
|
||||
// Paths are relative to this
|
||||
baseUrl: '../../apps/',
|
||||
paths: {
|
||||
// Testing libs
|
||||
'common' : 'common',
|
||||
'chai' : '../build/node_modules/chai/chai',
|
||||
'jquery' : '../vendor/jquery/jquery.min',
|
||||
'underscore' : '../vendor/underscore/underscore',
|
||||
'backbone' : '../vendor/backbone/backbone',
|
||||
'bootstrap' : '../vendor/bootstrap/dist/js/bootstrap',
|
||||
'perfectscrollbar' : '../vendor/perfect-scrollbar/src/perfect-scrollbar',
|
||||
'jmousewheel' : '../vendor/perfect-scrollbar/src/jquery.mousewheel'
|
||||
},
|
||||
shim: {
|
||||
backbone: {
|
||||
deps: [
|
||||
'underscore',
|
||||
'jquery'
|
||||
],
|
||||
exports: 'Backbone'
|
||||
},
|
||||
underscore: {
|
||||
exports: '_'
|
||||
},
|
||||
bootstrap: {
|
||||
deps: [
|
||||
'jquery'
|
||||
]
|
||||
},
|
||||
common: {
|
||||
deps: [
|
||||
'backbone'
|
||||
]
|
||||
},
|
||||
jmousewheel: {
|
||||
deps: [
|
||||
'jquery'
|
||||
]
|
||||
},
|
||||
perfectscrollbar: {
|
||||
deps: [
|
||||
'jmousewheel'
|
||||
]
|
||||
}
|
||||
}
|
||||
// urlArgs: /debug\=1/.test(window.location.search) ? '' : 'bust=' + (new Date()).getTime(), // debug
|
||||
});
|
||||
|
||||
// You can do this in the grunt config for each mocha task, see the `options` config
|
||||
mocha.setup({
|
||||
ui: 'bdd',
|
||||
ignoreLeaks: true
|
||||
});
|
||||
|
||||
// Protect from barfs
|
||||
console = window.console || function() {};
|
||||
|
||||
// Don't track
|
||||
window.notrack = true;
|
||||
|
||||
// Mocha run helper, used for browser
|
||||
var runMocha = function() {
|
||||
mocha.run();
|
||||
};
|
||||
|
||||
require([
|
||||
'../test/common',
|
||||
'../../test/common/main/lib/util/utils.js',
|
||||
'../../test/common/main/lib/component/Button.js'
|
||||
], runMocha);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
115
test/common/main/lib/component/Button.js
Normal file
115
test/common/main/lib/component/Button.js
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Button.js
|
||||
*
|
||||
* Unit test
|
||||
*
|
||||
* Created by Alexander Yuzhin on 6/20/14
|
||||
* Copyright (c) 2014 Ascensio System SIA. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
define([
|
||||
'backbone',
|
||||
'../../../../../apps/common/main/lib/component/Button.js',
|
||||
'../../../../../apps/common/main/lib/component/Menu.js'
|
||||
],function() {
|
||||
var chai = require('chai'),
|
||||
should = chai.should();
|
||||
|
||||
describe('Common.UI.Button', function(){
|
||||
var button,
|
||||
domPlaceholder = document.createElement('div');
|
||||
|
||||
it('Create simple button', function(){
|
||||
$('body').append(domPlaceholder);
|
||||
|
||||
button = new Common.UI.Button({
|
||||
id: 'id-btn-simple',
|
||||
caption: 'test'
|
||||
});
|
||||
|
||||
button.render($(domPlaceholder));
|
||||
|
||||
should.exist(button);
|
||||
$('#id-btn-simple').should.have.length(1);
|
||||
});
|
||||
|
||||
it('Button caption', function(){
|
||||
button.caption.should.equal('test');
|
||||
});
|
||||
|
||||
it('Button update caption', function(){
|
||||
button.setCaption('update caption');
|
||||
|
||||
// object
|
||||
button.caption.should.equal('update caption');
|
||||
|
||||
// dom
|
||||
assert.equal(button.cmpEl.find('button:first').andSelf().filter('button').text(), 'update caption', 'dom caption');
|
||||
});
|
||||
|
||||
it('Button toggle', function(){
|
||||
button.toggle();
|
||||
assert.equal(button.isActive(), true, 'should by active');
|
||||
button.toggle();
|
||||
assert.equal(button.isActive(), false, 'should NOT by active');
|
||||
|
||||
button.toggle(false);
|
||||
assert.equal(button.isActive(), false, 'should NOT by active');
|
||||
button.toggle(true);
|
||||
assert.equal(button.isActive(), true, 'should by active');
|
||||
|
||||
button.toggle(false);
|
||||
});
|
||||
|
||||
it('Button disable', function(){
|
||||
assert.equal(button.isDisabled(), false, 'should NOT by disable');
|
||||
|
||||
button.setDisabled(true);
|
||||
assert.equal(button.isDisabled(), true, 'should by disable');
|
||||
|
||||
button.setDisabled(false);
|
||||
assert.equal(button.isDisabled(), false, 'should NOT by disable');
|
||||
});
|
||||
|
||||
it('Remove simple button', function(){
|
||||
button.remove();
|
||||
$('#id-btn-simple').should.have.length(0);
|
||||
|
||||
button = null;
|
||||
// domPlaceholder.remove();
|
||||
});
|
||||
|
||||
it('Create split button', function(){
|
||||
$('body').append(domPlaceholder);
|
||||
|
||||
button = new Common.UI.Button({
|
||||
id : 'id-btn-split',
|
||||
caption : 'split',
|
||||
split : true,
|
||||
menu : new Common.UI.Menu({
|
||||
items: [
|
||||
{
|
||||
caption: 'print',
|
||||
value: 'print'
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
|
||||
button.render($(domPlaceholder));
|
||||
|
||||
should.exist(button);
|
||||
$('#id-btn-split').should.have.length(1);
|
||||
$('#id-btn-split button').should.have.length(2);
|
||||
});
|
||||
|
||||
it('Remove split button', function(){
|
||||
button.remove();
|
||||
$('#id-btn-split').should.have.length(0);
|
||||
|
||||
button = null;
|
||||
// domPlaceholder.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
33
test/common/main/lib/util/utils.js
Normal file
33
test/common/main/lib/util/utils.js
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* utils.js
|
||||
*
|
||||
* Unit test
|
||||
*
|
||||
* Created by Alexander Yuzhin on 5/7/14
|
||||
* Copyright (c) 2014 Ascensio System SIA. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
define([
|
||||
'../../../../../apps/common/main/lib/util/utils.js'
|
||||
],function() {
|
||||
describe('Common.Utils.String', function(){
|
||||
it('Test format', function(){
|
||||
assert.equal('successively: first, second', Common.Utils.String.format('successively: {0}, {1}', 'first', 'second'));
|
||||
assert.equal('revers: second, first', Common.Utils.String.format('revers: {1}, {0}', 'first', 'second'));
|
||||
});
|
||||
|
||||
it('Test htmlEncode', function(){
|
||||
assert.equal('Curly, Larry & Moe', Common.Utils.String.htmlEncode('Curly, Larry & Moe'));
|
||||
});
|
||||
|
||||
it('Test htmlDecode', function(){
|
||||
assert.equal('Curly, Larry & Moe', Common.Utils.String.htmlDecode('Curly, Larry & Moe'));
|
||||
});
|
||||
|
||||
it('Test ellipsis', function(){
|
||||
assert.equal('Truncate a s...', Common.Utils.String.ellipsis('Truncate a string and add an ellipsis', 15));
|
||||
assert.equal('Truncate a string and add...', Common.Utils.String.ellipsis('Truncate a string and add an ellipsis', 30, true));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user