Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion test/unit-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,29 @@

// Include and setup all the stuff for testing
define([
'chai'
'chai',
'backbone'
],function(chai) {
window.expect = chai.expect;
window.assert = chai.assert;

// Components read a little ambient state at render time -- Button asks
// Common.UI.Scaling for the current ratio, and the menus ask Common.Locale
// for the text direction. Pulling in the real modules would drag 'core' and
// the whole application bootstrap into a unit test, so stub the two calls.
window.Common = window.Common || {};
Common.UI = Common.UI || {};
Common.UI.Scaling = Common.UI.Scaling || {};
if (!Common.UI.Scaling.currentRatio) {
Common.UI.Scaling.currentRatio = function() { return 1; };
}
Common.Locale = Common.Locale || {};
if (!Common.Locale.isCurrentLanguageRtl) {
Common.Locale.isCurrentLanguageRtl = function() { return false; };
}
// Components subscribe to app-wide events (uitheme:changed, modal:close)
// on render. Backbone.Events is the same thing the application installs.
if (!Common.NotificationCenter) {
Common.NotificationCenter = _.extend({}, Backbone.Events);
}
});
49 changes: 35 additions & 14 deletions test/unit-tests/common/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
<head>
<meta charset="utf-8">
<title>Unit Tests</title>
<link rel="stylesheet" href="../../../../web-apps%20—%20копия/build/node_modules/mocha/mocha.css" type="text/css" media="screen" title="no title" charset="utf-8">
<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="../../../../web-apps%20—%20копия/build/node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../web-apps%20—%20копия/vendor/requirejs/require.js" type="text/javascript" charset="utf-8"></script>
<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="module">
// chai 5.x ships ESM only, so it cannot be pulled in by requirejs.
// Import it here and register it under the id the test files already use,
// so define(['chai']) and require('chai') keep working unchanged.
import * as chai from '../../../build/node_modules/chai/chai.js';
window.chai = chai;
define('chai', [], function () { return chai; });

<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/',
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',
Expand Down Expand Up @@ -64,8 +70,7 @@

// You can do this in the grunt config for each mocha task, see the `options` config
mocha.setup({
ui: 'bdd',
ignoreLeaks: true
ui: 'bdd'
});

// Protect from barfs
Expand All @@ -79,11 +84,27 @@
mocha.run();
};

require([
'../test/common',
'./main/lib/util/utils.js',
'../../test/common/main/lib/component/Button.js'
], runMocha);
// The app modules under test read $, _ and Backbone as globals rather than
// declaring them as dependencies, so requirejs is free to evaluate them
// before the vendor libs land. Load the globals first, then the tests.
require(['jquery', 'underscore', 'backbone'], function ($, _, Backbone) {
// underscore's UMD build registers itself as an AMD module and leaves
// no global behind, so publish the three the app modules expect.
window.$ = window.jQuery = $;
window._ = _;
window.Backbone = Backbone;

// The test setup module publishes assert/expect and stubs the ambient
// Common.* state the components read at render time. A flat require
// array would let requirejs evaluate whichever module lands first, so
// wait for the setup to finish before the tests are pulled in.
require(['../test/unit-tests/common'], function () {
require([
'./main/lib/util/utils.js',
'./main/lib/component/Button.js'
], runMocha);
});
});
</script>
</body>
</html>
</html>
6 changes: 3 additions & 3 deletions test/unit-tests/common/main/lib/component/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

define([
'backbone',
'../../../../../../../web-apps — копия/apps/common/main/lib/component/Button.js',
'../../../../../apps/common/main/lib/component/Menu.js'
'common/main/lib/component/Button',
'common/main/lib/component/Menu'
],function() {
var chai = require('chai'),
should = chai.should();
Expand Down Expand Up @@ -70,7 +70,7 @@ define([
button.caption.should.equal('update caption');

// dom
assert.equal(button.cmpEl.find('button:first').andSelf().filter('button').text(), 'update caption', 'dom caption');
assert.equal(button.cmpEl.find('button:first').addBack().filter('button').text(), 'update caption', 'dom caption');
});

it('Button toggle', function(){
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/common/main/lib/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/

define([
'../../../../../../../web-apps — копия/apps/common/main/lib/util/utils.js'
'common/main/lib/util/utils'
],function() {
describe('Common.Utils.String', function(){
it('Test format', function(){
Expand Down
Loading