mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 12:07:10 -04:00
Clean up tests.
This commit is contained in:
parent
c4fa90a747
commit
3a2e61b163
53 changed files with 70 additions and 22837 deletions
62
ghu.js
62
ghu.js
|
@ -7,7 +7,6 @@ const {
|
||||||
const ROOT = resolve(__dirname);
|
const ROOT = resolve(__dirname);
|
||||||
const SRC = join(ROOT, 'src');
|
const SRC = join(ROOT, 'src');
|
||||||
const TEST = join(ROOT, 'test');
|
const TEST = join(ROOT, 'test');
|
||||||
const TEST_SCAR = join(ROOT, 'test-scar');
|
|
||||||
const BUILD = join(ROOT, 'build');
|
const BUILD = join(ROOT, 'build');
|
||||||
|
|
||||||
const mapper = mapfn.p(SRC, BUILD).s('.less', '.css').s('.jade', '');
|
const mapper = mapfn.p(SRC, BUILD).s('.less', '.css').s('.jade', '');
|
||||||
|
@ -120,43 +119,12 @@ ghu.task('build:copy', runtime => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
ghu.task('build:tests', ['build:scripts', 'build:styles'], 'build the test suite', runtime => {
|
ghu.task('build:tests', ['build:styles'], 'build the test suite', () => {
|
||||||
return Promise.all([
|
|
||||||
read(`${TEST}/scripts.js`)
|
|
||||||
.then(newerThan(`${BUILD}/test/scripts.js`))
|
|
||||||
.then(includeit())
|
|
||||||
.then(write(`${BUILD}/test/scripts.js`, {overwrite: true})),
|
|
||||||
|
|
||||||
read(`${TEST}/styles.less`)
|
|
||||||
.then(newerThan(`${BUILD}/test/styles.css`))
|
|
||||||
.then(includeit())
|
|
||||||
.then(less())
|
|
||||||
.then(autoprefixer())
|
|
||||||
.then(write(`${BUILD}/test/styles.css`, {overwrite: true})),
|
|
||||||
|
|
||||||
read(`${TEST}/index.html.jade`)
|
|
||||||
.then(newerThan(`${BUILD}/test/index.html`))
|
|
||||||
.then(pug({pkg: runtime.pkg}))
|
|
||||||
.then(write(`${BUILD}/test/index.html`, {overwrite: true})),
|
|
||||||
|
|
||||||
read(`${BUILD}/_h5ai/public/js/scripts.js`)
|
|
||||||
.then(newerThan(`${BUILD}/test/h5ai-scripts.js`))
|
|
||||||
.then(write(`${BUILD}/test/h5ai-scripts.js`, {overwrite: true})),
|
|
||||||
|
|
||||||
read(`${BUILD}/_h5ai/public/css/styles.css`)
|
|
||||||
.then(newerThan(`${BUILD}/test/h5ai-styles.css`))
|
|
||||||
.then(write(`${BUILD}/test/h5ai-styles.css`, {overwrite: true}))
|
|
||||||
]).then(() => {
|
|
||||||
console.log(`browse to file://${BUILD}/test/index.html to run the test suite`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
ghu.task('build:tests-scar', ['build:scripts', 'build:styles'], 'build the test suite', () => {
|
|
||||||
const webpackConfig = {
|
const webpackConfig = {
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
{
|
{
|
||||||
include: [TEST_SCAR],
|
include: [TEST],
|
||||||
loader: 'babel',
|
loader: 'babel',
|
||||||
query: {cacheDirectory: true}
|
query: {cacheDirectory: true}
|
||||||
}
|
}
|
||||||
|
@ -165,27 +133,25 @@ ghu.task('build:tests-scar', ['build:scripts', 'build:styles'], 'build the test
|
||||||
};
|
};
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
read(`${BUILD}/_h5ai/public/js/scripts.js`)
|
|
||||||
.then(newerThan(`${BUILD}/test-scar/h5ai-scripts.js`))
|
|
||||||
.then(write(`${BUILD}/test-scar/h5ai-scripts.js`, {overwrite: true})),
|
|
||||||
|
|
||||||
read(`${BUILD}/_h5ai/public/css/styles.css`)
|
read(`${BUILD}/_h5ai/public/css/styles.css`)
|
||||||
.then(newerThan(`${BUILD}/test-scar/h5ai-styles.css`))
|
.then(newerThan(`${BUILD}/test/h5ai-styles.css`))
|
||||||
.then(write(`${BUILD}/test-scar/h5ai-styles.css`, {overwrite: true})),
|
.then(write(`${BUILD}/test/h5ai-styles.css`, {overwrite: true})),
|
||||||
|
|
||||||
read(`${TEST_SCAR}/tests.html`)
|
read(`${TEST}/tests.html`)
|
||||||
.then(newerThan(`${BUILD}/test-scar/tests.html`))
|
.then(newerThan(`${BUILD}/test/tests.html`))
|
||||||
.then(write(`${BUILD}/test-scar/tests.html`, {overwrite: true})),
|
.then(write(`${BUILD}/test/tests.html`, {overwrite: true})),
|
||||||
|
|
||||||
read(`${TEST_SCAR}: tests.js`)
|
read(`${TEST}: tests.js`)
|
||||||
.then(webpack(webpackConfig, {showStats: false}))
|
.then(webpack(webpackConfig, {showStats: false}))
|
||||||
.then(write(mapfn.p(TEST_SCAR, `${BUILD}/test-scar`), {overwrite: true}))
|
.then(wrap(`\n\n// @include "${SRC}/**/js/global.js"\n\n`))
|
||||||
|
.then(includeit())
|
||||||
|
.then(write(mapfn.p(TEST, `${BUILD}/test`), {overwrite: true}))
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
console.log(`browse to file://${BUILD}/test-scar/tests.html to run the test suite`);
|
console.log(`browse to file://${BUILD}/test/tests.html to run the test suite`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ghu.task('build', ['build:scripts', 'build:styles', 'build:pages', 'build:copy', 'build:tests', 'build:tests-scar'],
|
ghu.task('build', ['build:scripts', 'build:styles', 'build:pages', 'build:copy', 'build:tests'],
|
||||||
'build all updated files, optionally use :production');
|
'build all updated files, optionally use :production');
|
||||||
|
|
||||||
ghu.task('deploy', ['build'], 'deploy to a specified path with :dest=/some/path', runtime => {
|
ghu.task('deploy', ['build'], 'deploy to a specified path with :dest=/some/path', runtime => {
|
||||||
|
@ -202,7 +168,7 @@ ghu.task('deploy', ['build'], 'deploy to a specified path with :dest=/some/path'
|
||||||
});
|
});
|
||||||
|
|
||||||
ghu.task('watch', runtime => {
|
ghu.task('watch', runtime => {
|
||||||
return watch([SRC, TEST, TEST_SCAR], () => ghu.run(runtime.sequence.filter(x => x !== 'watch'), runtime.args, true));
|
return watch([SRC, TEST], () => ghu.run(runtime.sequence.filter(x => x !== 'watch'), runtime.args, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
ghu.task('release', ['force-production', 'clean', 'build'], 'create a zipball', runtime => {
|
ghu.task('release', ['force-production', 'clean', 'build'], 'create a zipball', runtime => {
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
---
|
|
||||||
env:
|
|
||||||
browser: true
|
|
|
@ -1,16 +0,0 @@
|
||||||
const {test} = require('scar');
|
|
||||||
const {clearModulejs, mockConfigModule} = require('./util/modjs');
|
|
||||||
const {pinHtml} = require('./util/pin');
|
|
||||||
|
|
||||||
mockConfigModule();
|
|
||||||
clearModulejs();
|
|
||||||
|
|
||||||
require('./tests/premisses');
|
|
||||||
require('./tests/unit/boot');
|
|
||||||
require('./tests/unit/config');
|
|
||||||
require('./tests/unit/libs');
|
|
||||||
require('./tests/unit/modulejs');
|
|
||||||
|
|
||||||
pinHtml();
|
|
||||||
|
|
||||||
test.cli({sync: true});
|
|
|
@ -1,21 +0,0 @@
|
||||||
const {test, assert} = require('scar');
|
|
||||||
|
|
||||||
test('window is global object', () => {
|
|
||||||
assert.equal(typeof window, 'object');
|
|
||||||
assert.equal(window, window.window);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('document is global object', () => {
|
|
||||||
assert.equal(typeof window.document, 'object');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('jQuery and $ are global functions', () => {
|
|
||||||
assert.equal(typeof window.jQuery, 'function');
|
|
||||||
assert.equal(window.jQuery.fn.jquery, '2.2.4');
|
|
||||||
assert.equal(window.jQuery, window.$);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_ is global function', () => {
|
|
||||||
assert.equal(typeof window._, 'function');
|
|
||||||
assert.equal(window._.VERSION, '4.13.1');
|
|
||||||
});
|
|
|
@ -1,33 +0,0 @@
|
||||||
const {test, assert} = require('scar');
|
|
||||||
const sinon = require('sinon');
|
|
||||||
|
|
||||||
const ID = 'boot';
|
|
||||||
const DEPS = ['$', 'core/server'];
|
|
||||||
|
|
||||||
const getDef = () => window.modulejs._private.definitions[ID];
|
|
||||||
const createInst = () => getDef().fn.call(null, window.jQuery, {});
|
|
||||||
|
|
||||||
test(`module '${ID}' is defined`, () => {
|
|
||||||
assert.ok(getDef());
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' has correct id`, () => {
|
|
||||||
assert.equal(getDef().id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' has correct deps`, () => {
|
|
||||||
assert.deepEqual(getDef().deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' has args for each dependency`, () => {
|
|
||||||
const def = getDef();
|
|
||||||
assert.deepEqual(def.deps.length, def.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' inits without errors`, () => {
|
|
||||||
createInst();
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' instance is undefined`, () => {
|
|
||||||
assert.equal(createInst(), undefined);
|
|
||||||
});
|
|
|
@ -1,32 +0,0 @@
|
||||||
const {test, assert} = require('scar');
|
|
||||||
|
|
||||||
const ID = 'config';
|
|
||||||
const DEPS = [];
|
|
||||||
|
|
||||||
const getDef = () => window.modulejs._private.definitions[ID];
|
|
||||||
const createInst = () => getDef().fn();
|
|
||||||
|
|
||||||
test(`module '${ID}' is defined`, () => {
|
|
||||||
assert.ok(getDef());
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' has correct id`, () => {
|
|
||||||
assert.equal(getDef().id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' has correct deps`, () => {
|
|
||||||
assert.deepEqual(getDef().deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' has args for each dependency`, () => {
|
|
||||||
const def = getDef();
|
|
||||||
assert.deepEqual(def.deps.length, def.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' inits without errors`, () => {
|
|
||||||
createInst();
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${ID}' is only dummy definiton`, () => {
|
|
||||||
assert.deepEqual(createInst(), {_dummyConfig: true});
|
|
||||||
});
|
|
|
@ -1,25 +0,0 @@
|
||||||
const {test, assert} = require('scar');
|
|
||||||
|
|
||||||
const libs = {
|
|
||||||
_: window._,
|
|
||||||
$: window.jQuery,
|
|
||||||
marked: window.marked,
|
|
||||||
prism: window.Prism
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.keys(libs).forEach(id => {
|
|
||||||
test(`module '${id}' is defined`, () => {
|
|
||||||
assert.ok(window.modulejs._private.definitions[id]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${id}' has no instance`, () => {
|
|
||||||
assert.equal(window.modulejs._private.instances[id], undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`module '${id}' returns global lib`, () => {
|
|
||||||
const definition = window.modulejs._private.definitions[id];
|
|
||||||
const instance = definition.fn();
|
|
||||||
assert.ok(instance);
|
|
||||||
assert.equal(instance, libs[id]);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,33 +0,0 @@
|
||||||
const {test, assert} = require('scar');
|
|
||||||
|
|
||||||
test('modulejs is global object', () => {
|
|
||||||
assert.equal(typeof window.modulejs, 'object');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs.define() is function', () => {
|
|
||||||
assert.equal(typeof window.modulejs.define, 'function');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs.require() is function', () => {
|
|
||||||
assert.equal(typeof window.modulejs.require, 'function');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs.state() is function', () => {
|
|
||||||
assert.equal(typeof window.modulejs.state, 'function');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs.log() is function', () => {
|
|
||||||
assert.equal(typeof window.modulejs.log, 'function');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs._private is object', () => {
|
|
||||||
assert.equal(typeof window.modulejs._private, 'object');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs has definitions', () => {
|
|
||||||
assert.ok(Object.keys(window.modulejs._private.definitions).length >= 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('modulejs has no instances', () => {
|
|
||||||
assert.equal(Object.keys(window.modulejs._private.instances).length, 0);
|
|
||||||
});
|
|
|
@ -1,17 +0,0 @@
|
||||||
const lodash = window._;
|
|
||||||
const modjs = window.modulejs;
|
|
||||||
|
|
||||||
function clearModulejs() {
|
|
||||||
lodash.each(modjs._private.instances, (val, key) => {
|
|
||||||
delete modjs._private.instances[key]; // eslint-disable-line prefer-reflect
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockConfigModule() {
|
|
||||||
modjs.define('config', {_dummyConfig: true});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
clearModulejs,
|
|
||||||
mockConfigModule
|
|
||||||
};
|
|
|
@ -1,33 +0,0 @@
|
||||||
const jq = window.jQuery;
|
|
||||||
let title;
|
|
||||||
let htmlId;
|
|
||||||
let htmlClasses;
|
|
||||||
let bodyId;
|
|
||||||
let bodyClasses;
|
|
||||||
let $pinnedElements;
|
|
||||||
|
|
||||||
function pinHtml() {
|
|
||||||
title = document.title;
|
|
||||||
htmlId = jq('html').attr('id');
|
|
||||||
htmlClasses = jq('html').attr('class');
|
|
||||||
bodyId = jq('body').attr('id');
|
|
||||||
bodyClasses = jq('body').attr('class');
|
|
||||||
$pinnedElements = jq('head,body').children();
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreHtml() {
|
|
||||||
document.title = title;
|
|
||||||
jq('html').attr('id', htmlId);
|
|
||||||
jq('html').attr('class', htmlClasses);
|
|
||||||
jq('body').attr('id', bodyId);
|
|
||||||
jq('body').attr('class', bodyClasses);
|
|
||||||
jq('head,body').children().not($pinnedElements).remove();
|
|
||||||
if (window.localStorage && window.localStorage.clear) {
|
|
||||||
window.localStorage.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
pinHtml,
|
|
||||||
restoreHtml
|
|
||||||
};
|
|
|
@ -1,30 +0,0 @@
|
||||||
---
|
|
||||||
env:
|
|
||||||
es6: false
|
|
||||||
node: false
|
|
||||||
browser: true
|
|
||||||
mocha: true
|
|
||||||
|
|
||||||
globals:
|
|
||||||
modulejs: false
|
|
||||||
jQuery: false
|
|
||||||
$: false
|
|
||||||
_: false
|
|
||||||
util: false
|
|
||||||
assert: false
|
|
||||||
uniq: false
|
|
||||||
sinon: false
|
|
||||||
|
|
||||||
parserOptions:
|
|
||||||
ecmaVersion: 6
|
|
||||||
|
|
||||||
rules:
|
|
||||||
consistent-this: 0
|
|
||||||
func-names: 0
|
|
||||||
max-nested-callbacks: [1, 5]
|
|
||||||
max-params: [1, 10]
|
|
||||||
no-invalid-this: 0
|
|
||||||
no-var: 0
|
|
||||||
object-shorthand: 0
|
|
||||||
prefer-arrow-callback: 0
|
|
||||||
prefer-reflect: 0
|
|
|
@ -1,14 +0,0 @@
|
||||||
doctype html
|
|
||||||
html
|
|
||||||
head
|
|
||||||
meta(charset="utf-8")
|
|
||||||
meta(http-equiv="x-ua-compatible", content="ie=edge")
|
|
||||||
title h5ai test suite - v#{pkg.version}
|
|
||||||
meta(name="viewport", content="width=device-width, initial-scale=1")
|
|
||||||
link(rel="stylesheet", href="h5ai-styles.css")
|
|
||||||
link(rel="stylesheet", href="styles.css")
|
|
||||||
script(src="h5ai-scripts.js")
|
|
||||||
script(src="scripts.js")
|
|
||||||
|
|
||||||
body
|
|
||||||
div#mocha
|
|
|
@ -1,35 +0,0 @@
|
||||||
// @include "vendor/*.js"
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
'use strict'; // eslint-disable-line strict
|
|
||||||
// @include "util/*.js"
|
|
||||||
}());
|
|
||||||
|
|
||||||
jQuery(function () {
|
|
||||||
'use strict'; // eslint-disable-line strict
|
|
||||||
|
|
||||||
util.mockConfigModule();
|
|
||||||
util.clearModulejs();
|
|
||||||
util.setupMocha();
|
|
||||||
|
|
||||||
describe('all tests', function () {
|
|
||||||
// @include "tests/premisses.js"
|
|
||||||
|
|
||||||
describe('unit tests', function () {
|
|
||||||
// @include "tests/unit/modulejs.js"
|
|
||||||
// @include "tests/unit/libs.js"
|
|
||||||
// @include "tests/unit/boot.js"
|
|
||||||
// @include "tests/unit/config.js"
|
|
||||||
|
|
||||||
// @include "tests/unit/*/*.js"
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('integration tests', function () {
|
|
||||||
// @include "tests/integration/*.js"
|
|
||||||
// @-include "tests/integration/*/*.js"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
util.pinHtml();
|
|
||||||
util.runMocha();
|
|
||||||
});
|
|
230
test/styles.less
230
test/styles.less
|
@ -1,230 +0,0 @@
|
||||||
@charset 'utf-8';
|
|
||||||
|
|
||||||
@col-white: #ffffff;
|
|
||||||
@col-red-500: #f44336;
|
|
||||||
@col-red-800: #c62828;
|
|
||||||
@col-amber-800: #ff8f00;
|
|
||||||
@col-green-500: #4caf50;
|
|
||||||
@col-grey-200: #eeeeee;
|
|
||||||
@col-grey-800: #424242;
|
|
||||||
|
|
||||||
@col-text: @col-grey-800;
|
|
||||||
@col-text-fail: @col-red-800;
|
|
||||||
@col-back-hover: @col-grey-200;
|
|
||||||
@col-pending: @col-grey-800;
|
|
||||||
@col-pass: @col-green-500;
|
|
||||||
@col-fail: @col-red-500;
|
|
||||||
@col-medium: @col-amber-800;
|
|
||||||
@col-slow: @col-red-800;
|
|
||||||
@col-progress: rgba(255,255,255,0.2);
|
|
||||||
|
|
||||||
#mocha {
|
|
||||||
position: fixed;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
z-index: 10000;
|
|
||||||
font-family: "Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif";
|
|
||||||
background: @col-white;
|
|
||||||
|
|
||||||
#mocha-bar {
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
height: 32px;
|
|
||||||
color: @col-white;
|
|
||||||
background: @col-pending;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: bold;
|
|
||||||
line-height: 32px;
|
|
||||||
padding: 0 8px;
|
|
||||||
text-shadow: 0 0 4px @col-text;
|
|
||||||
|
|
||||||
&.pass {
|
|
||||||
background: @col-pass;
|
|
||||||
}
|
|
||||||
&.fail {
|
|
||||||
background: @col-fail;
|
|
||||||
}
|
|
||||||
.stats {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
right: 8px;
|
|
||||||
top: 0;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.progress {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
height: 100%;
|
|
||||||
background: @col-progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#mocha-stats {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#mocha-report {
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 32px;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
overflow-x: auto;
|
|
||||||
overflow-y: scroll;
|
|
||||||
|
|
||||||
> .suite {
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 32px;
|
|
||||||
max-width: 900px;
|
|
||||||
|
|
||||||
> .toggle {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
a, a:active, a:visited, a:hover {
|
|
||||||
display: block;
|
|
||||||
color: inherit;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul, li, h1, h2 {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul {
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color: @col-text;
|
|
||||||
height: 24px;
|
|
||||||
line-height: 24px;
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: bold;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: @col-back-hover;
|
|
||||||
}
|
|
||||||
a, a:active, a:visited, a:hover {
|
|
||||||
padding: 0 8px;
|
|
||||||
}
|
|
||||||
.count {
|
|
||||||
font-size: 0.85em;
|
|
||||||
}
|
|
||||||
.passed {
|
|
||||||
color: @col-pass;
|
|
||||||
margin-left: 1em;
|
|
||||||
}
|
|
||||||
.failed {
|
|
||||||
color: @col-fail;
|
|
||||||
margin-left: 0.5em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: normal;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
display: block;
|
|
||||||
font-family: "Ubuntu Mono", "Monaco", "Lucida Sans Typewriter", "monospace";
|
|
||||||
font-size: 12px;
|
|
||||||
margin: 4px 0 16px 18px;
|
|
||||||
padding: 0 8px;
|
|
||||||
word-wrap: break-word;
|
|
||||||
border-left: 2px solid @col-text;
|
|
||||||
|
|
||||||
&.error {
|
|
||||||
color: @col-text-fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.suite {
|
|
||||||
position: relative;
|
|
||||||
margin: 16px 0 8px 24px;
|
|
||||||
|
|
||||||
.toggle {
|
|
||||||
position: absolute;
|
|
||||||
left: -24px;
|
|
||||||
top: 0;
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
line-height: 24px;
|
|
||||||
color: @col-text;
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: bold;
|
|
||||||
text-align: center;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: @col-back-hover;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.test {
|
|
||||||
margin-left: 15px;
|
|
||||||
padding: 2px 4px;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: @col-back-hover;
|
|
||||||
}
|
|
||||||
&.fail {
|
|
||||||
color: @col-text-fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
content: ' ';
|
|
||||||
display: block;
|
|
||||||
width: 10px;
|
|
||||||
height: 10px;
|
|
||||||
float: left;
|
|
||||||
margin-right: 8px;
|
|
||||||
background: @col-pending;
|
|
||||||
border-radius: 20px;
|
|
||||||
position: relative;
|
|
||||||
top: 3px;
|
|
||||||
}
|
|
||||||
&.pass::before {
|
|
||||||
background: @col-pass;
|
|
||||||
}
|
|
||||||
&.fail::before {
|
|
||||||
background: @col-fail;
|
|
||||||
}
|
|
||||||
&.pending::before {
|
|
||||||
background: @col-pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
.duration {
|
|
||||||
display: inline-block;
|
|
||||||
color: @col-text;
|
|
||||||
border: none;
|
|
||||||
box-shadow: none;
|
|
||||||
font-size: 10px;
|
|
||||||
margin-left: 12px;
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
&.medium .duration {
|
|
||||||
color: @col-medium;
|
|
||||||
}
|
|
||||||
&.slow .duration {
|
|
||||||
color: @col-slow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.replay {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,9 +2,8 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>h5ai test suite - scar</title>
|
<title>h5ai test suite</title>
|
||||||
<link rel="stylesheet" href="h5ai-styles.css">
|
<link rel="stylesheet" href="h5ai-styles.css">
|
||||||
<script src="h5ai-scripts.js"></script>
|
|
||||||
<script src="tests.js"></script>
|
<script src="tests.js"></script>
|
||||||
</head>
|
</head>
|
||||||
</html>
|
</html>
|
8
test/tests.js
Normal file
8
test/tests.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const {test} = require('scar');
|
||||||
|
const {pinHtml} = require('./util/pin');
|
||||||
|
|
||||||
|
require('./tests/premisses');
|
||||||
|
|
||||||
|
pinHtml();
|
||||||
|
|
||||||
|
test.cli({sync: true});
|
|
@ -1,106 +0,0 @@
|
||||||
(function () {
|
|
||||||
describe('view', function () {
|
|
||||||
before(function () {
|
|
||||||
this.configBackup = modulejs._private.definitions.config;
|
|
||||||
this.storeKey = '_h5ai';
|
|
||||||
this.xConfig = {
|
|
||||||
setup: {
|
|
||||||
PUBLIC_HREF: uniq.path('-PUBLIC/'),
|
|
||||||
ROOT_HREF: uniq.path('-ROOT/')
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
modulejs._private.definitions.config = this.configBackup;
|
|
||||||
util.clearModulejs();
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
delete modulejs._private.definitions.config;
|
|
||||||
modulejs.define('config', this.xConfig);
|
|
||||||
util.clearModulejs();
|
|
||||||
util.restoreHtml();
|
|
||||||
$('<div id="fallback"/>').appendTo('body');
|
|
||||||
$('<div id="fallback-hints"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('requiring \'view/viewmode\' sets up basic HTML', function () {
|
|
||||||
it('runs without errors', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds id root to body', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.strictEqual($('body').attr('id'), 'root');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes HTML #fallback', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#fallback'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes HTML #fallback-hints', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#fallback-hints'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #mainrow to #root', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#root > #mainrow'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #content to #mainrow', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#mainrow > #content'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #view to #content', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#content > #view'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #items to #view', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#view > #items'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #topbar to #root', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#root > #topbar'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #toolbar to #topbar', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#topbar > #toolbar'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #flowbar to #topbar', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#topbar > #flowbar'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #backlink to #topbar', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#topbar > #backlink'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #sidebar-toggle to #toolbar', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#toolbar > #sidebar-toggle'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #viewmode-settings to #sidebar', function () {
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('#sidebar > #viewmode-settings'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds style to head', function () {
|
|
||||||
var styleTagCount = $('head > style').length;
|
|
||||||
modulejs.require('view/viewmode');
|
|
||||||
assert.lengthOf($('head > style'), styleTagCount + 1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,69 +1,21 @@
|
||||||
(function () {
|
const {test, assert} = require('scar');
|
||||||
describe('premisses', function () {
|
|
||||||
it('window is global object', function () {
|
|
||||||
assert.isObject(window);
|
|
||||||
assert.strictEqual(window, window.window);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('document is global object', function () {
|
test('window is global object', () => {
|
||||||
assert.isObject(document);
|
assert.equal(typeof global, 'object');
|
||||||
assert.strictEqual(document, window.document);
|
assert.equal(global, global.window);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('jQuery and $ are global functions', function () {
|
test('document is global object', () => {
|
||||||
assert.isFunction(jQuery);
|
assert.equal(typeof global.document, 'object');
|
||||||
assert.strictEqual(jQuery, window.jQuery);
|
});
|
||||||
assert.strictEqual(jQuery.fn.jquery, '2.2.4');
|
|
||||||
|
|
||||||
assert.strictEqual($, jQuery);
|
test('jQuery and $ are global functions', () => {
|
||||||
assert.strictEqual($, window.$);
|
assert.equal(typeof global.jQuery, 'function');
|
||||||
});
|
assert.equal(global.jQuery.fn.jquery, '2.2.4');
|
||||||
|
assert.equal(global.jQuery, global.$);
|
||||||
|
});
|
||||||
|
|
||||||
it('_ is global function', function () {
|
test('_ is global function', () => {
|
||||||
assert.isFunction(_);
|
assert.equal(typeof global._, 'function');
|
||||||
assert.strictEqual(_, window._);
|
assert.equal(global._.VERSION, '4.13.1');
|
||||||
assert.strictEqual(_.VERSION, '4.13.1');
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('util is global object', function () {
|
|
||||||
assert.isPlainObject(util);
|
|
||||||
assert.strictEqual(util, window.util);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uniq is global object', function () {
|
|
||||||
assert.isPlainObject(uniq);
|
|
||||||
assert.strictEqual(uniq, window.uniq);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('assert.isPlainObject() works', function () {
|
|
||||||
assert.isFunction(assert.isPlainObject);
|
|
||||||
|
|
||||||
assert.isPlainObject({});
|
|
||||||
assert.isPlainObject({a: 1});
|
|
||||||
assert.isPlainObject(Object());
|
|
||||||
assert.isPlainObject(new Object()); // eslint-disable-line no-new-object
|
|
||||||
|
|
||||||
assert.throws(function () { assert.isPlainObject(); });
|
|
||||||
assert.throws(function () { assert.isPlainObject(1); });
|
|
||||||
assert.throws(function () { assert.isPlainObject('a'); });
|
|
||||||
assert.throws(function () { assert.isPlainObject(new Date()); });
|
|
||||||
assert.throws(function () { assert.isPlainObject(/a/); });
|
|
||||||
assert.throws(function () { assert.isPlainObject(function () {}); });
|
|
||||||
assert.throws(function () { assert.isPlainObject(new function A() {}); });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('assert.lengthOfKeys() works', function () {
|
|
||||||
assert.isFunction(assert.lengthOfKeys);
|
|
||||||
|
|
||||||
assert.lengthOfKeys({}, 0);
|
|
||||||
assert.lengthOfKeys({a: true}, 1);
|
|
||||||
assert.lengthOfKeys({a: true, b: 0, c: undefined}, 3);
|
|
||||||
|
|
||||||
assert.throws(function () { assert.lengthOfKeys(); });
|
|
||||||
assert.throws(function () { assert.lengthOfKeys(1); });
|
|
||||||
assert.throws(function () { assert.lengthOfKeys('a'); });
|
|
||||||
assert.throws(function () { assert.lengthOfKeys({}); });
|
|
||||||
assert.throws(function () { assert.lengthOfKeys({}, 1); });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
||||||
|
|
|
@ -1,134 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'boot';
|
|
||||||
var DEPS = ['$', 'core/server'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xConfig = uniq.obj();
|
|
||||||
this.xDefine = sinon.stub(modulejs, 'define');
|
|
||||||
this.xRequire = sinon.stub(modulejs, 'require');
|
|
||||||
this.xServer = {
|
|
||||||
request: sinon.stub().callsArgWith(1, this.xConfig)
|
|
||||||
};
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xDefine.reset();
|
|
||||||
this.xRequire.reset();
|
|
||||||
this.xServer.request.reset();
|
|
||||||
|
|
||||||
return this.definition.fn($, this.xServer);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
this.xDefine.restore();
|
|
||||||
this.xRequire.restore();
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns undefined', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isUndefined(instance);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('no data-module', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.isFalse(this.xServer.request.called);
|
|
||||||
assert.isFalse(this.xDefine.called);
|
|
||||||
assert.isFalse(this.xRequire.called);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('data-module=\'test\'', function () {
|
|
||||||
$('<script/>').attr('data-module', 'test').appendTo('head');
|
|
||||||
this.applyFn();
|
|
||||||
assert.isFalse(this.xServer.request.called);
|
|
||||||
assert.isFalse(this.xDefine.called);
|
|
||||||
assert.isFalse(this.xRequire.called);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('data-module=\'info\'', function () {
|
|
||||||
var expectedData = {
|
|
||||||
action: 'get',
|
|
||||||
setup: true,
|
|
||||||
options: true,
|
|
||||||
types: true,
|
|
||||||
refresh: true
|
|
||||||
};
|
|
||||||
|
|
||||||
$('<script/>').attr('data-module', 'info').appendTo('head');
|
|
||||||
|
|
||||||
this.applyFn();
|
|
||||||
|
|
||||||
assert.isTrue(this.xServer.request.calledOnce);
|
|
||||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
|
||||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
|
||||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
|
||||||
|
|
||||||
assert.isTrue(this.xDefine.calledOnce);
|
|
||||||
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
|
||||||
|
|
||||||
assert.isTrue(this.xRequire.calledOnce);
|
|
||||||
assert.deepEqual(this.xRequire.lastCall.args, ['main/info']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('data-module=\'index\'', function () {
|
|
||||||
var expectedData = {
|
|
||||||
action: 'get',
|
|
||||||
setup: true,
|
|
||||||
options: true,
|
|
||||||
types: true,
|
|
||||||
theme: true,
|
|
||||||
langs: true
|
|
||||||
};
|
|
||||||
|
|
||||||
$('<script/>').attr('data-module', 'index').appendTo('head');
|
|
||||||
|
|
||||||
this.applyFn();
|
|
||||||
|
|
||||||
assert.isTrue(this.xServer.request.calledOnce);
|
|
||||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
|
||||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
|
||||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
|
||||||
|
|
||||||
assert.isTrue(this.xDefine.calledOnce);
|
|
||||||
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
|
||||||
|
|
||||||
assert.isTrue(this.xRequire.calledOnce);
|
|
||||||
assert.deepEqual(this.xRequire.lastCall.args, ['main/index']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,47 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'config';
|
|
||||||
var DEPS = [];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn($);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is only dummy definition', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 1);
|
|
||||||
assert.isTrue(uniq.isId(instance._uniq_id));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,104 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/event';
|
|
||||||
var DEPS = ['_'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 3 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.sub()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.sub);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.unsub()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.unsub);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.pub()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.pub);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('works', function () {
|
|
||||||
it('works', function () {
|
|
||||||
var topic = 'topic';
|
|
||||||
var arg1 = 'arg1';
|
|
||||||
var arg2 = 'arg2';
|
|
||||||
var arg3 = 'arg3';
|
|
||||||
var subSpy = sinon.spy();
|
|
||||||
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.sub(topic, subSpy);
|
|
||||||
instance.pub(topic, arg1, arg2, arg3);
|
|
||||||
|
|
||||||
assert.isTrue(subSpy.calledOnce);
|
|
||||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
|
||||||
|
|
||||||
instance.pub(topic, arg1, arg2);
|
|
||||||
|
|
||||||
assert.isTrue(subSpy.calledTwice);
|
|
||||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
|
||||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
|
||||||
|
|
||||||
instance.unsub(topic, subSpy);
|
|
||||||
|
|
||||||
assert.isTrue(subSpy.calledTwice);
|
|
||||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
|
||||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
|
||||||
|
|
||||||
instance.pub(topic, arg1);
|
|
||||||
|
|
||||||
assert.isTrue(subSpy.calledTwice);
|
|
||||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
|
||||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,188 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/format';
|
|
||||||
var DEPS = ['_'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 4 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setDefaultMetric()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.setDefaultMetric);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.formatSize()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.formatSize);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('defaults to decimal metric', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.formatSize(1024), '1 KB');
|
|
||||||
instance.setDefaultMetric(true);
|
|
||||||
assert.strictEqual(instance.formatSize(1024), '1 KiB');
|
|
||||||
instance.setDefaultMetric(false);
|
|
||||||
assert.strictEqual(instance.formatSize(1024), '1 KB');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('decimal metric', function () {
|
|
||||||
_.each([
|
|
||||||
[0, '0 B'],
|
|
||||||
[10, '10 B'],
|
|
||||||
[999, '999 B'],
|
|
||||||
[1000, '1 KB'],
|
|
||||||
[1001, '1 KB'],
|
|
||||||
[1499, '1 KB'],
|
|
||||||
[1500, '2 KB'],
|
|
||||||
[999999, '1000 KB'],
|
|
||||||
[1000000, '1.0 MB'],
|
|
||||||
[1000001, '1.0 MB'],
|
|
||||||
[1230000, '1.2 MB'],
|
|
||||||
[1250000, '1.3 MB'],
|
|
||||||
[999999999, '1000.0 MB'],
|
|
||||||
[1000000000, '1.0 GB'],
|
|
||||||
[1250000000, '1.3 GB'],
|
|
||||||
[999999999999, '1000.0 GB'],
|
|
||||||
[1000000000000, '1.0 TB'],
|
|
||||||
[1250000000000, '1.3 TB']
|
|
||||||
], function (data) {
|
|
||||||
var arg = data[0];
|
|
||||||
var exp = data[1];
|
|
||||||
|
|
||||||
it(arg + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setDefaultMetric(false);
|
|
||||||
assert.strictEqual(instance.formatSize(arg), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('binary metric', function () {
|
|
||||||
_.each([
|
|
||||||
[0, '0 B'],
|
|
||||||
[10, '10 B'],
|
|
||||||
[999, '999 B'],
|
|
||||||
[1000, '1000 B'],
|
|
||||||
[1001, '1001 B'],
|
|
||||||
[1024, '1 KiB'],
|
|
||||||
[1499, '1 KiB'],
|
|
||||||
[1500, '1 KiB'],
|
|
||||||
[999999, '977 KiB'],
|
|
||||||
[1000000, '977 KiB'],
|
|
||||||
[1000001, '977 KiB'],
|
|
||||||
[1230000, '1.2 MiB'],
|
|
||||||
[1250000, '1.2 MiB'],
|
|
||||||
[999999999, '953.7 MiB'],
|
|
||||||
[1000000000, '953.7 MiB'],
|
|
||||||
[1250000000, '1.2 GiB'],
|
|
||||||
[999999999999, '931.3 GiB'],
|
|
||||||
[1000000000000, '931.3 GiB'],
|
|
||||||
[1250000000000, '1.1 TiB']
|
|
||||||
], function (data) {
|
|
||||||
var arg = data[0];
|
|
||||||
var exp = data[1];
|
|
||||||
|
|
||||||
it(arg + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setDefaultMetric(true);
|
|
||||||
assert.strictEqual(instance.formatSize(arg), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setDefaultDateFormat()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.setDefaultDateFormat);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.formatDate()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.formatDate);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('default format', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.formatDate(0), '');
|
|
||||||
assert.strictEqual(instance.formatDate(1000), '1970-01-01 01:00');
|
|
||||||
assert.strictEqual(instance.formatDate(-1000), '1970-01-01 00:59');
|
|
||||||
assert.strictEqual(instance.formatDate(1400000000000), '2014-05-13 18:53');
|
|
||||||
|
|
||||||
instance.setDefaultDateFormat('YYYY-MM-DD HH:mm:ss');
|
|
||||||
assert.strictEqual(instance.formatDate(0), '');
|
|
||||||
assert.strictEqual(instance.formatDate(1000), '1970-01-01 01:00:01');
|
|
||||||
assert.strictEqual(instance.formatDate(-1000), '1970-01-01 00:59:59');
|
|
||||||
assert.strictEqual(instance.formatDate(1400000000000), '2014-05-13 18:53:20');
|
|
||||||
|
|
||||||
instance.setDefaultDateFormat('H YY s');
|
|
||||||
assert.strictEqual(instance.formatDate(0), '');
|
|
||||||
assert.strictEqual(instance.formatDate(1000), '1 70 1');
|
|
||||||
assert.strictEqual(instance.formatDate(-1000), '0 70 59');
|
|
||||||
assert.strictEqual(instance.formatDate(1400000000000), '18 14 20');
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
[0, 'YYYY-MM-DD HH:mm:ss', ''],
|
|
||||||
[1000, 'YYYY-MM-DD HH:mm:ss', '1970-01-01 01:00:01'],
|
|
||||||
[-1000, 'YYYY-MM-DD HH:mm:ss', '1970-01-01 00:59:59'],
|
|
||||||
[1400000000000, 'YYYY-MM-DD HH:mm:ss', '2014-05-13 18:53:20'],
|
|
||||||
[1400000000000, 'XYYYYXMMXDDXHHXmmXssX', 'X2014X05X13X18X53X20X'],
|
|
||||||
[1400000000000, 'YYYY YY Y MM M DD D HH H mm m ss s', '2014 14 2014 05 5 13 13 18 18 53 53 20 20']
|
|
||||||
], function (data) {
|
|
||||||
var arg1 = data[0];
|
|
||||||
var arg2 = data[1];
|
|
||||||
var exp = data[2];
|
|
||||||
|
|
||||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.formatDate(arg1, arg2), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,49 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/langs';
|
|
||||||
var DEPS = ['_', 'config'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xConfig = {langs: uniq.obj()};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_, this.xConfig);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with right content', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.deepEqual(instance, this.xConfig.langs);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,266 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/location';
|
|
||||||
var DEPS = ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xModernizr = {
|
|
||||||
history: true
|
|
||||||
};
|
|
||||||
this.xSettings = {view: {
|
|
||||||
fastBrowsing: true,
|
|
||||||
unmanagedInNewWindow: true
|
|
||||||
}};
|
|
||||||
this.xEvent = {
|
|
||||||
pub: sinon.stub(),
|
|
||||||
sub: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xNotification = {
|
|
||||||
set: sinon.stub()
|
|
||||||
};
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xEvent.pub.reset();
|
|
||||||
this.xEvent.sub.reset();
|
|
||||||
this.xNotification.set.reset();
|
|
||||||
|
|
||||||
return this.definition.fn(_, this.xEvent, this.xModernizr, this.xSettings, this.xNotification);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
window.onpopstate = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
window.onpopstate = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 7 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 7);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets window.onpopstate function when history and fastBrowsing', function () {
|
|
||||||
this.xModernizr.history = true;
|
|
||||||
this.xSettings.view.fastBrowsing = true;
|
|
||||||
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
this.applyFn();
|
|
||||||
assert.isFunction(window.onpopstate);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets window.onpopstate to null when not history and fastBrowsing', function () {
|
|
||||||
this.xModernizr.history = false;
|
|
||||||
this.xSettings.view.fastBrowsing = true;
|
|
||||||
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
this.applyFn();
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets window.onpopstate to null when history and not fastBrowsing', function () {
|
|
||||||
this.xModernizr.history = true;
|
|
||||||
this.xSettings.view.fastBrowsing = false;
|
|
||||||
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
this.applyFn();
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets window.onpopstate to null when not history and not fastBrowsing', function () {
|
|
||||||
this.xModernizr.history = false;
|
|
||||||
this.xSettings.view.fastBrowsing = false;
|
|
||||||
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
this.applyFn();
|
|
||||||
assert.isNull(window.onpopstate);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.forceEncoding()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.forceEncoding);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
['', ''],
|
|
||||||
['//', '/'],
|
|
||||||
['////', '/'],
|
|
||||||
['//a///b////c//', '/a/b/c/'],
|
|
||||||
['a b', 'a%20b'],
|
|
||||||
['ab ', 'ab%20'],
|
|
||||||
[' ab', '%20ab'],
|
|
||||||
['a!b', 'a%21b'],
|
|
||||||
['a#b', 'a%23b'],
|
|
||||||
['a$b', 'a%24b'],
|
|
||||||
['a&b', 'a%26b'],
|
|
||||||
['a\'b', 'a%27b'],
|
|
||||||
['a(b', 'a%28b'],
|
|
||||||
['a)b', 'a%29b'],
|
|
||||||
['a*b', 'a%2Ab'],
|
|
||||||
['a+b', 'a%2Bb'],
|
|
||||||
['a,b', 'a%2Cb'],
|
|
||||||
['a:b', 'a%3Ab'],
|
|
||||||
['a;b', 'a%3Bb'],
|
|
||||||
['a=b', 'a%3Db'],
|
|
||||||
['a?b', 'a%3Fb'],
|
|
||||||
['a@b', 'a%40b'],
|
|
||||||
['a[b', 'a%5Bb'],
|
|
||||||
['a]b', 'a%5Db']
|
|
||||||
], function (data) {
|
|
||||||
var arg = data[0];
|
|
||||||
var exp = data[1];
|
|
||||||
|
|
||||||
it(arg + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.forceEncoding(arg), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getDomain()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.getDomain);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns document.domain', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.getDomain(), window.document.domain);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getAbsHref()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.getAbsHref);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns null before .setLocation()', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isNull(instance.getAbsHref());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getItem()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.getItem);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setLocation()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.setLocation);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.refresh()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.refresh);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setLink()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.setLink);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets href correct', function () {
|
|
||||||
var $el = $('<a/>');
|
|
||||||
var item = {
|
|
||||||
absHref: uniq.id(),
|
|
||||||
isManaged: false,
|
|
||||||
isFolder: sinon.stub().returns(false)
|
|
||||||
};
|
|
||||||
|
|
||||||
var setLink = this.applyFn().setLink;
|
|
||||||
setLink($el, item);
|
|
||||||
|
|
||||||
assert.strictEqual($el.attr('href'), item.absHref);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets target=\'_blank\' for unmanaged folders', function () {
|
|
||||||
this.xSettings.view.unmanagedInNewWindow = true;
|
|
||||||
|
|
||||||
var $el = $('<a/>');
|
|
||||||
var item = {
|
|
||||||
absHref: uniq.id(),
|
|
||||||
isManaged: false,
|
|
||||||
isFolder: sinon.stub().returns(true)
|
|
||||||
};
|
|
||||||
|
|
||||||
var setLink = this.applyFn().setLink;
|
|
||||||
setLink($el, item);
|
|
||||||
|
|
||||||
assert.strictEqual($el.attr('target'), '_blank');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not set target=\'_blank\' for managed folders', function () {
|
|
||||||
this.xSettings.view.unmanagedInNewWindow = true;
|
|
||||||
|
|
||||||
var $el = $('<a/>');
|
|
||||||
var item = {
|
|
||||||
absHref: uniq.id(),
|
|
||||||
isManaged: true,
|
|
||||||
isFolder: sinon.stub().returns(true)
|
|
||||||
};
|
|
||||||
|
|
||||||
var setLink = this.applyFn().setLink;
|
|
||||||
setLink($el, item);
|
|
||||||
|
|
||||||
assert.isUndefined($el.attr('target'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
|
|
||||||
this.xSettings.view.unmanagedInNewWindow = false;
|
|
||||||
|
|
||||||
var $el = $('<a/>');
|
|
||||||
var item = {
|
|
||||||
absHref: uniq.id(),
|
|
||||||
isManaged: true,
|
|
||||||
isFolder: sinon.stub().returns(true)
|
|
||||||
};
|
|
||||||
|
|
||||||
var setLink = this.applyFn().setLink;
|
|
||||||
setLink($el, item);
|
|
||||||
|
|
||||||
assert.isUndefined($el.attr('target'));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,69 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/modernizr';
|
|
||||||
var DEPS = [];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 3 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOf(_.keys(instance), 3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.canvas', function () {
|
|
||||||
it('is boolean', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isBoolean(instance.canvas);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.history', function () {
|
|
||||||
it('is boolean', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isBoolean(instance.history);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.localstorage', function () {
|
|
||||||
it('is boolean', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isBoolean(instance.localstorage);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,92 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/resource';
|
|
||||||
var DEPS = ['_', 'config', 'core/settings'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xConfig = {
|
|
||||||
theme: {
|
|
||||||
a: 'myTheme/a.svg',
|
|
||||||
b: 'myTheme/b.jpg'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.xSettings = {publicHref: uniq.path('/publicHref/')};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_, this.xConfig, this.xSettings);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 2 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.image()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.image);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('works', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
var ui = this.xSettings.publicHref + 'images/ui/';
|
|
||||||
|
|
||||||
assert.strictEqual(instance.image(), ui + 'undefined.svg');
|
|
||||||
assert.strictEqual(instance.image(1), ui + '1.svg');
|
|
||||||
assert.strictEqual(instance.image(''), ui + '.svg');
|
|
||||||
assert.strictEqual(instance.image('a'), ui + 'a.svg');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.icon()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.icon);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('works', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
var themes = this.xSettings.publicHref + 'images/themes/';
|
|
||||||
|
|
||||||
assert.strictEqual(instance.icon(''), themes + 'default/file.svg');
|
|
||||||
assert.strictEqual(instance.icon('a'), themes + 'myTheme/a.svg');
|
|
||||||
assert.strictEqual(instance.icon('a-sub'), themes + 'myTheme/a.svg');
|
|
||||||
assert.strictEqual(instance.icon('b'), themes + 'myTheme/b.jpg');
|
|
||||||
assert.strictEqual(instance.icon('x'), themes + 'default/x.svg');
|
|
||||||
assert.strictEqual(instance.icon('y'), themes + 'default/file.svg');
|
|
||||||
assert.strictEqual(instance.icon('y-sub'), themes + 'default/file.svg');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,169 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/server';
|
|
||||||
var DEPS = ['_', '$'];
|
|
||||||
var $submitEl;
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xAjaxResult = {
|
|
||||||
done: sinon.stub().returnsThis(),
|
|
||||||
fail: sinon.stub().returnsThis(),
|
|
||||||
always: sinon.stub().returnsThis()
|
|
||||||
};
|
|
||||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
|
||||||
this.xSubmit = sinon.stub($.fn, 'submit', function () {
|
|
||||||
$submitEl = this;
|
|
||||||
return this;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xAjaxResult.done.reset();
|
|
||||||
this.xAjaxResult.fail.reset();
|
|
||||||
this.xAjaxResult.always.reset();
|
|
||||||
this.xAjax.reset();
|
|
||||||
this.xSubmit.reset();
|
|
||||||
$submitEl = undefined;
|
|
||||||
|
|
||||||
return this.definition.fn(_, $);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
this.xAjax.restore();
|
|
||||||
this.xSubmit.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 2 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.request()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.request);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('done() works', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
|
|
||||||
var xData = uniq.obj();
|
|
||||||
var xResult = uniq.obj();
|
|
||||||
var spy = sinon.spy();
|
|
||||||
var res = instance.request(xData, spy);
|
|
||||||
|
|
||||||
assert.isUndefined(res);
|
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
|
||||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
|
||||||
url: '?',
|
|
||||||
data: xData,
|
|
||||||
type: 'post',
|
|
||||||
dataType: 'json'
|
|
||||||
}]);
|
|
||||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
|
||||||
assert.isTrue(this.xAjaxResult.fail.calledOnce);
|
|
||||||
assert.isFalse(spy.called);
|
|
||||||
|
|
||||||
this.xAjaxResult.done.callArgWith(0, xResult);
|
|
||||||
|
|
||||||
assert.isTrue(spy.calledOnce);
|
|
||||||
assert.deepEqual(spy.firstCall.args, [xResult]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fail() works', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
|
|
||||||
var xData = uniq.obj();
|
|
||||||
var spy = sinon.spy();
|
|
||||||
var res = instance.request(xData, spy);
|
|
||||||
|
|
||||||
assert.isUndefined(res);
|
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
|
||||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
|
||||||
url: '?',
|
|
||||||
data: xData,
|
|
||||||
type: 'post',
|
|
||||||
dataType: 'json'
|
|
||||||
}]);
|
|
||||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
|
||||||
assert.isTrue(this.xAjaxResult.fail.calledOnce);
|
|
||||||
assert.isFalse(spy.called);
|
|
||||||
|
|
||||||
this.xAjaxResult.fail.callArg(0);
|
|
||||||
|
|
||||||
assert.isTrue(spy.calledOnce);
|
|
||||||
assert.deepEqual(spy.firstCall.args, []);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.formRequest()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.formRequest);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('works', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
|
|
||||||
var xData = {
|
|
||||||
a: uniq.id(),
|
|
||||||
b: uniq.id()
|
|
||||||
};
|
|
||||||
var res = instance.formRequest(xData);
|
|
||||||
|
|
||||||
assert.isUndefined(res);
|
|
||||||
|
|
||||||
assert.isTrue(this.xSubmit.calledOnce);
|
|
||||||
|
|
||||||
assert.lengthOf($submitEl, 1);
|
|
||||||
assert.strictEqual($submitEl.get(0).tagName.toLowerCase(), 'form');
|
|
||||||
assert.strictEqual($submitEl.attr('method'), 'post');
|
|
||||||
assert.strictEqual($submitEl.attr('style').replace(/\s+/g, ''), 'display:none;');
|
|
||||||
assert.strictEqual($submitEl.attr('action'), '?');
|
|
||||||
|
|
||||||
var $children = $submitEl.children();
|
|
||||||
|
|
||||||
assert.lengthOf($children, 2);
|
|
||||||
|
|
||||||
assert.strictEqual($children.eq(0).attr('type'), 'hidden');
|
|
||||||
assert.strictEqual($children.eq(0).attr('name'), 'a');
|
|
||||||
assert.strictEqual($children.eq(0).attr('value'), xData.a);
|
|
||||||
|
|
||||||
assert.strictEqual($children.eq(1).attr('type'), 'hidden');
|
|
||||||
assert.strictEqual($children.eq(1).attr('name'), 'b');
|
|
||||||
assert.strictEqual($children.eq(1).attr('value'), xData.b);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,83 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/settings';
|
|
||||||
var DEPS = ['_', 'config'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xConfig = {
|
|
||||||
options: {
|
|
||||||
someOptions: uniq.obj(),
|
|
||||||
otherOptions: uniq.obj(),
|
|
||||||
more: uniq.obj()
|
|
||||||
},
|
|
||||||
setup: {
|
|
||||||
PUBLIC_HREF: uniq.id(),
|
|
||||||
ROOT_HREF: uniq.id()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_, this.xConfig);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.isAbove(_.keys(instance).length, 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('publics', function () {
|
|
||||||
it('extended from options', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.someOptions, this.xConfig.options.someOptions);
|
|
||||||
assert.strictEqual(instance.otherOptions, this.xConfig.options.otherOptions);
|
|
||||||
assert.strictEqual(instance.more, this.xConfig.options.more);
|
|
||||||
assert.strictEqual(_.keys(instance).length, _.keys(this.xConfig.options).length + 2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.publicHref', function () {
|
|
||||||
it('set correct', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.publicHref, this.xConfig.setup.PUBLIC_HREF);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.rootHref', function () {
|
|
||||||
it('set correct', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.rootHref, this.xConfig.setup.ROOT_HREF);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,108 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/store';
|
|
||||||
var DEPS = ['core/modernizr'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.storeKey = '_h5ai';
|
|
||||||
this.xModernizr = {localstorage: true};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(this.xModernizr);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 2 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.put()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.put);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.get()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.get);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('works', function () {
|
|
||||||
it('works', function () {
|
|
||||||
var key1 = 'test1';
|
|
||||||
var value1 = '1234';
|
|
||||||
var key2 = 'test2';
|
|
||||||
var value2 = '5678';
|
|
||||||
var instance = this.applyFn();
|
|
||||||
|
|
||||||
assert.isNull(window.localStorage.getItem(this.storeKey));
|
|
||||||
|
|
||||||
assert.isUndefined(instance.get(key1));
|
|
||||||
assert.isNull(window.localStorage.getItem(this.storeKey));
|
|
||||||
|
|
||||||
assert.isUndefined(instance.put(key1, value1));
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
|
|
||||||
|
|
||||||
assert.strictEqual(instance.get(key1), value1);
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
|
|
||||||
|
|
||||||
assert.isUndefined(instance.put(key1, undefined));
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{}');
|
|
||||||
|
|
||||||
assert.isUndefined(instance.get(key1));
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{}');
|
|
||||||
|
|
||||||
assert.isUndefined(instance.put(key1, value1));
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
|
|
||||||
|
|
||||||
assert.isUndefined(instance.put(key2, value2));
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234","test2":"5678"}');
|
|
||||||
|
|
||||||
assert.isUndefined(instance.put(key1, undefined));
|
|
||||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test2":"5678"}');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,84 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/types';
|
|
||||||
var DEPS = ['_', 'config'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xConfig = {types: {
|
|
||||||
a: ['*.a', '*.aa'],
|
|
||||||
b: ['*.b'],
|
|
||||||
c: ['*.c']
|
|
||||||
}};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_, this.xConfig);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 1 property', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getType()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.getType);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
['file.a', 'a'],
|
|
||||||
['file.aa', 'a'],
|
|
||||||
['foo.b', 'b'],
|
|
||||||
['some/path/file.c', 'c'],
|
|
||||||
['/some/abs/path/file.c', 'c'],
|
|
||||||
['file.x', 'file'],
|
|
||||||
['foo', 'file'],
|
|
||||||
['some/path/foo', 'file'],
|
|
||||||
['/some/path/foo', 'file'],
|
|
||||||
['foo/', 'folder'],
|
|
||||||
['/', 'folder'],
|
|
||||||
['some/path/foo/', 'folder'],
|
|
||||||
['/some/path/foo/', 'folder']
|
|
||||||
], function (data) {
|
|
||||||
var arg = data[0];
|
|
||||||
var exp = data[1];
|
|
||||||
|
|
||||||
it(arg + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.getType(arg), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,201 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'core/util';
|
|
||||||
var DEPS = ['_'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 4 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.regularCmpFn()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.regularCmpFn);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
[0, 0, 0],
|
|
||||||
[1, 0, 1],
|
|
||||||
[1, 2, -1],
|
|
||||||
['a', 'a', 0],
|
|
||||||
['b', 'a', 1],
|
|
||||||
['a', 'b', -1],
|
|
||||||
['a 2', 'a 10', 1]
|
|
||||||
], function (data) {
|
|
||||||
var arg1 = data[0];
|
|
||||||
var arg2 = data[1];
|
|
||||||
var exp = data[2];
|
|
||||||
|
|
||||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.naturalCmpFn()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.naturalCmpFn);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
[0, 0, 0],
|
|
||||||
[1, 0, 1],
|
|
||||||
[1, 2, -1],
|
|
||||||
['a', 'a', 0],
|
|
||||||
['b', 'a', 1],
|
|
||||||
['a', 'b', -1],
|
|
||||||
['a 2', 'a 10', -1]
|
|
||||||
], function (data) {
|
|
||||||
var arg1 = data[0];
|
|
||||||
var arg2 = data[1];
|
|
||||||
var exp = data[2];
|
|
||||||
|
|
||||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.escapePattern()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.escapePattern);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
['a', 'a'],
|
|
||||||
['1', '1'],
|
|
||||||
['ä', 'ä'],
|
|
||||||
['~', '~'],
|
|
||||||
[':', ':'],
|
|
||||||
['_', '_'],
|
|
||||||
['<', '<'],
|
|
||||||
['-', '\\-'],
|
|
||||||
['[', '\\['],
|
|
||||||
[']', '\\]'],
|
|
||||||
['{', '\\{'],
|
|
||||||
['}', '\\}'],
|
|
||||||
['(', '\\('],
|
|
||||||
[')', '\\)'],
|
|
||||||
['*', '\\*'],
|
|
||||||
['+', '\\+'],
|
|
||||||
['?', '\\?'],
|
|
||||||
['.', '\\.'],
|
|
||||||
[',', '\\,'],
|
|
||||||
['\\', '\\\\'],
|
|
||||||
['$', '\\$'],
|
|
||||||
['^', '\\^'],
|
|
||||||
['|', '\\|'],
|
|
||||||
['#', '\\#'],
|
|
||||||
[' ', '\\ '],
|
|
||||||
['-[]{}()*+?.,\\$^|# ', '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
|
||||||
['abc123', 'abc123'],
|
|
||||||
['a.b+c*1', 'a\\.b\\+c\\*1']
|
|
||||||
], function (data) {
|
|
||||||
var arg = data[0];
|
|
||||||
var exp = data[1];
|
|
||||||
|
|
||||||
it(arg + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.escapePattern(arg), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.parsePattern()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.parsePattern);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
['a', false, 'a'],
|
|
||||||
['1', false, '1'],
|
|
||||||
['ä', false, 'ä'],
|
|
||||||
['~', false, '~'],
|
|
||||||
[':', false, ':'],
|
|
||||||
['_', false, '_'],
|
|
||||||
['<', false, '<'],
|
|
||||||
['-', false, '\\-'],
|
|
||||||
['[', false, '\\['],
|
|
||||||
[']', false, '\\]'],
|
|
||||||
['{', false, '\\{'],
|
|
||||||
['}', false, '\\}'],
|
|
||||||
['(', false, '\\('],
|
|
||||||
[')', false, '\\)'],
|
|
||||||
['*', false, '\\*'],
|
|
||||||
['+', false, '\\+'],
|
|
||||||
['?', false, '\\?'],
|
|
||||||
['.', false, '\\.'],
|
|
||||||
[',', false, '\\,'],
|
|
||||||
['\\', false, '\\\\'],
|
|
||||||
['$', false, '\\$'],
|
|
||||||
['^', false, '\\^'],
|
|
||||||
['|', false, '\\|'],
|
|
||||||
['#', false, '\\#'],
|
|
||||||
[' ', false, '\\ '],
|
|
||||||
['-[]{}()*+?.,\\$^|# ', false, '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
|
||||||
['abc123', false, 'abc123'],
|
|
||||||
['a.b+c*1', false, 'a\\.b\\+c\\*1'],
|
|
||||||
|
|
||||||
['abc', true, 'a.*?b.*?c'],
|
|
||||||
['abc def', true, 'a.*?b.*?c|d.*?e.*?f'],
|
|
||||||
['*#a b.=', true, '\\*.*?\\#.*?a|b.*?\\..*?='],
|
|
||||||
['re:.', true, '.'],
|
|
||||||
[' .', true, '\\.'],
|
|
||||||
['re: .', true, ' .']
|
|
||||||
|
|
||||||
], function (data) {
|
|
||||||
var arg1 = data[0];
|
|
||||||
var arg2 = data[1];
|
|
||||||
var exp = data[2];
|
|
||||||
|
|
||||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.strictEqual(instance.parsePattern(arg1, arg2), exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,104 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'ext/title';
|
|
||||||
var DEPS = ['_', 'core/event', 'core/settings'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xEvent = {
|
|
||||||
sub: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xSettings = {title: {
|
|
||||||
enabled: true
|
|
||||||
}};
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xEvent.sub.reset();
|
|
||||||
|
|
||||||
return this.definition.fn(_, this.xEvent, this.xSettings);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns undefined', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isUndefined(instance);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('subscribes to location.changed', function () {
|
|
||||||
this.xSettings.title.enabled = true;
|
|
||||||
|
|
||||||
this.applyFn();
|
|
||||||
assert.isTrue(this.xEvent.sub.calledOnce);
|
|
||||||
assert.strictEqual(this.xEvent.sub.lastCall.args[0], 'location.changed');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not subscribe to events if disabled', function () {
|
|
||||||
this.xSettings.title.enabled = false;
|
|
||||||
|
|
||||||
this.applyFn();
|
|
||||||
assert.isFalse(this.xEvent.sub.called);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sets title on location.changed', function () {
|
|
||||||
_.each([
|
|
||||||
[''],
|
|
||||||
['a', 'a'],
|
|
||||||
['a', 'b', 'b - a > b'],
|
|
||||||
['a', 'b', 'c', 'c - a > b > c']
|
|
||||||
], function (data) {
|
|
||||||
var labels = data.slice(0, -1);
|
|
||||||
var exp = data.slice(-1)[0];
|
|
||||||
|
|
||||||
it(labels + ' => ' + exp, function () {
|
|
||||||
this.xSettings.title.enabled = true;
|
|
||||||
|
|
||||||
this.applyFn();
|
|
||||||
|
|
||||||
var fn = this.xEvent.sub.lastCall.args[1];
|
|
||||||
var crumb = _.map(labels, function (x) { return {label: x}; });
|
|
||||||
var item = {
|
|
||||||
getCrumb: sinon.stub().returns(crumb)
|
|
||||||
};
|
|
||||||
|
|
||||||
fn(item);
|
|
||||||
|
|
||||||
assert.isTrue(item.getCrumb.calledOnce);
|
|
||||||
assert.strictEqual(document.title, exp);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,29 +0,0 @@
|
||||||
(function () {
|
|
||||||
describe('libs', function () {
|
|
||||||
var libs = {
|
|
||||||
_: window._,
|
|
||||||
$: window.jQuery,
|
|
||||||
marked: window.marked,
|
|
||||||
prism: window.Prism
|
|
||||||
};
|
|
||||||
|
|
||||||
_.each(libs, function (lib, id) {
|
|
||||||
describe('module \'' + id + '\'', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isDefined(modulejs._private.definitions[id]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns global lib', function () {
|
|
||||||
var definition = modulejs._private.definitions[id];
|
|
||||||
var instance = definition.fn();
|
|
||||||
assert.isDefined(instance);
|
|
||||||
assert.strictEqual(instance, lib);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,102 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'main/index';
|
|
||||||
var DEPS = ['_', 'core/location'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xLocation = {setLocation: sinon.stub()};
|
|
||||||
this.xRequire = sinon.stub(modulejs, 'require');
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xLocation.setLocation.reset();
|
|
||||||
this.xRequire.reset();
|
|
||||||
return this.definition.fn(_, this.xLocation);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
this.xRequire.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns undefined', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isUndefined(instance);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires view/viewmode', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.isTrue(this.xRequire.calledWithExactly('view/viewmode'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires all extensions', function () {
|
|
||||||
this.applyFn();
|
|
||||||
var re = /^ext\//;
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
_.each(modulejs.state(), function (state, id) {
|
|
||||||
if (re.test(id)) {
|
|
||||||
assert.isTrue(self.xRequire.calledWithExactly(id));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires only views and extensions', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.isTrue(this.xRequire.alwaysCalledWithMatch(/^(view|ext)\//));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires views before extensions', function () {
|
|
||||||
this.applyFn();
|
|
||||||
var foundExtension = false;
|
|
||||||
var reView = /^view\//;
|
|
||||||
var reExt = /^ext\//;
|
|
||||||
|
|
||||||
_.each(this.xRequire.args, function (args) {
|
|
||||||
if (foundExtension) {
|
|
||||||
assert.match(args[0], reExt);
|
|
||||||
} else if (reExt.test(args[0])) {
|
|
||||||
foundExtension = true;
|
|
||||||
} else {
|
|
||||||
assert.match(args[0], reView);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls setLocation with current href, keeping browser url', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.isTrue(this.xLocation.setLocation.calledOnce);
|
|
||||||
assert.deepEqual(this.xLocation.setLocation.firstCall.args, [document.location.href, true]);
|
|
||||||
assert.isTrue(this.xLocation.setLocation.calledAfter(this.xRequire));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,180 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'main/info';
|
|
||||||
var DEPS = ['$', 'config', 'core/resource', 'core/server'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xConfig = {
|
|
||||||
setup: {
|
|
||||||
VERSION: uniq.id()
|
|
||||||
},
|
|
||||||
options: {}
|
|
||||||
};
|
|
||||||
this.xResource = {
|
|
||||||
image: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xServer = {
|
|
||||||
request: sinon.stub()
|
|
||||||
};
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xServer.request.reset();
|
|
||||||
|
|
||||||
return this.definition.fn($, this.xConfig, this.xResource, this.xServer);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
$('<div id="content"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns undefined', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isUndefined(instance);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #support to #content', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#content > #support'), 1);
|
|
||||||
assert.lengthOf($('#support > .paypal'), 1);
|
|
||||||
assert.lengthOf($('.paypal > form'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #login-wrapper to #content', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#content > #login-wrapper'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('no admin', function () {
|
|
||||||
it('adds HTML #pass to #login-wrapper', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#login-wrapper > #pass'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets #pass val to empty string', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual($('#login-wrapper > #pass').val(), '');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #login to #login-wrapper', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#login-wrapper > #login'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not add HTML #logout to #login-wrapper', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#login-wrapper > #logout'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not add HTML #tests to #content', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#content > #tests'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('login works', function () {
|
|
||||||
var pass = uniq.id();
|
|
||||||
var expectedData = {
|
|
||||||
action: 'login',
|
|
||||||
pass: pass
|
|
||||||
};
|
|
||||||
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
|
||||||
this.applyFn();
|
|
||||||
$('#pass').val(pass);
|
|
||||||
$('#login').trigger('click');
|
|
||||||
|
|
||||||
assert.isTrue(this.xServer.request.calledOnce);
|
|
||||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
|
||||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
|
||||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('as admin', function () {
|
|
||||||
it('does not add HTML #pass to #login-wrapper', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#login-wrapper > #pass'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not add #login to #login-wrapper', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#login-wrapper > #login'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #logout to #login-wrapper', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#login-wrapper > #logout'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #tests to #content', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#content > #tests'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #test 15x to #tests', function () {
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual($('#tests > .test').length, 15);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('logout works', function () {
|
|
||||||
var expectedData = {
|
|
||||||
action: 'logout'
|
|
||||||
};
|
|
||||||
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
|
||||||
this.applyFn();
|
|
||||||
$('#logout').trigger('click');
|
|
||||||
|
|
||||||
assert.isTrue(this.xServer.request.calledOnce);
|
|
||||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
|
||||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
|
||||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,356 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'model/item';
|
|
||||||
var DEPS = ['_', 'core/event', 'core/location', 'core/server', 'core/settings', 'core/types'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xRootName = uniq.id();
|
|
||||||
this.xTypes = {
|
|
||||||
getType: sinon.stub().returns(uniq.id())
|
|
||||||
};
|
|
||||||
this.xEvent = uniq.obj();
|
|
||||||
this.xSettings = {
|
|
||||||
rootHref: uniq.path('/' + this.xRootName + '/')
|
|
||||||
};
|
|
||||||
this.xServer = uniq.obj();
|
|
||||||
this.xLocation = {
|
|
||||||
forceEncoding: sinon.stub().returnsArg(0),
|
|
||||||
getDomain: sinon.stub().returns(uniq.id()),
|
|
||||||
getAbsHref: sinon.stub().returns(uniq.id())
|
|
||||||
};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn(_, this.xEvent, this.xLocation, this.xServer, this.xSettings, this.xTypes);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 2 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.get()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.get);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns null with no argument', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isNull(instance.get());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns null for no string argument', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isNull(instance.get(1));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns null for href not starting with rootHref', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isNull(instance.get('/a/'));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('for rootHref', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
this.item = instance.get(this.xSettings.rootHref);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns object', function () {
|
|
||||||
assert.isObject(this.item);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets href correct', function () {
|
|
||||||
assert.strictEqual(this.item.absHref, this.xSettings.rootHref);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets type correct', function () {
|
|
||||||
assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets label correct', function () {
|
|
||||||
assert.strictEqual(this.item.label, this.xRootName);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets time to null', function () {
|
|
||||||
assert.isNull(this.item.time);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets size to null', function () {
|
|
||||||
assert.isNull(this.item.size);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets parent to null', function () {
|
|
||||||
assert.isNull(this.item.parent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets isManaged to null', function () {
|
|
||||||
assert.isNull(this.item.isManaged);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets content correct', function () {
|
|
||||||
assert.isPlainObject(this.item.content);
|
|
||||||
assert.lengthOfKeys(this.item.content, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isFolder() returns true', function () {
|
|
||||||
assert.isTrue(this.item.isFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isCurrentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isCurrentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isInCurrentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isInCurrentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isCurrentParentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isCurrentParentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isDomain() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isDomain());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isRoot() returns true', function () {
|
|
||||||
assert.isTrue(this.item.isRoot());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isEmpty() returns true', function () {
|
|
||||||
assert.isTrue(this.item.isEmpty());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('for folder href other than rootHref', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
this.item = instance.get(this.xSettings.rootHref + 'a/');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns object', function () {
|
|
||||||
assert.isObject(this.item);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets href correct', function () {
|
|
||||||
assert.strictEqual(this.item.absHref, this.xSettings.rootHref + 'a/');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets type correct', function () {
|
|
||||||
assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets label correct', function () {
|
|
||||||
assert.strictEqual(this.item.label, 'a');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets time to null', function () {
|
|
||||||
assert.isNull(this.item.time);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets size to null', function () {
|
|
||||||
assert.isNull(this.item.size);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets parent to object', function () {
|
|
||||||
assert.isObject(this.item.parent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parent has same constructor', function () {
|
|
||||||
assert.strictEqual(this.item.constructor, this.item.parent.constructor);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets isManaged to null', function () {
|
|
||||||
assert.isNull(this.item.isManaged);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets content correct', function () {
|
|
||||||
assert.isPlainObject(this.item.content);
|
|
||||||
assert.lengthOfKeys(this.item.content, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isFolder() returns true', function () {
|
|
||||||
assert.isTrue(this.item.isFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isCurrentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isCurrentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isInCurrentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isInCurrentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isCurrentParentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isCurrentParentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isDomain() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isDomain());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isRoot() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isRoot());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isEmpty() returns true', function () {
|
|
||||||
assert.isTrue(this.item.isEmpty());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('for file href', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
this.item = instance.get(this.xSettings.rootHref + 'a');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns object', function () {
|
|
||||||
assert.isObject(this.item);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets href correct', function () {
|
|
||||||
assert.strictEqual(this.item.absHref, this.xSettings.rootHref + 'a');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets type correct', function () {
|
|
||||||
assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets label correct', function () {
|
|
||||||
assert.strictEqual(this.item.label, 'a');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets time to null', function () {
|
|
||||||
assert.isNull(this.item.time);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets size to null', function () {
|
|
||||||
assert.isNull(this.item.size);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets parent to object', function () {
|
|
||||||
assert.isObject(this.item.parent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parent has same constructor', function () {
|
|
||||||
assert.strictEqual(this.item.constructor, this.item.parent.constructor);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets isManaged to null', function () {
|
|
||||||
assert.isNull(this.item.isManaged);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets content correct', function () {
|
|
||||||
assert.isPlainObject(this.item.content);
|
|
||||||
assert.lengthOfKeys(this.item.content, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isCurrentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isCurrentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isInCurrentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isInCurrentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isCurrentParentFolder() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isCurrentParentFolder());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isDomain() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isDomain());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isRoot() returns false', function () {
|
|
||||||
assert.isFalse(this.item.isRoot());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.isEmpty() returns true', function () {
|
|
||||||
assert.isTrue(this.item.isEmpty());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('parents', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
this.item = instance.get(this.xSettings.rootHref + 'p/a/');
|
|
||||||
this.parent = this.item.parent;
|
|
||||||
this.grandpa = this.parent.parent;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parent is object', function () {
|
|
||||||
assert.isObject(this.parent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parent has correct href', function () {
|
|
||||||
assert.strictEqual(this.parent.absHref, this.xSettings.rootHref + 'p/');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parent has correct label', function () {
|
|
||||||
assert.strictEqual(this.parent.label, 'p');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parent .isEmpty() returns false', function () {
|
|
||||||
assert.isFalse(this.parent.isEmpty());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandpa is object', function () {
|
|
||||||
assert.isObject(this.grandpa);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandpa has correct href', function () {
|
|
||||||
assert.strictEqual(this.grandpa.absHref, this.xSettings.rootHref);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandpa has correct label', function () {
|
|
||||||
assert.strictEqual(this.grandpa.label, this.xRootName);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('grandpa .isEmpty() returns false', function () {
|
|
||||||
assert.isFalse(this.grandpa.isEmpty());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.remove()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isFunction(instance.remove);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,36 +0,0 @@
|
||||||
(function () {
|
|
||||||
describe('modulejs', function () {
|
|
||||||
it('is global object', function () {
|
|
||||||
assert.isPlainObject(modulejs);
|
|
||||||
assert.strictEqual(modulejs, window.modulejs);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.define() is function', function () {
|
|
||||||
assert.isFunction(modulejs.define);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.require() is function', function () {
|
|
||||||
assert.isFunction(modulejs.require);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.state() is function', function () {
|
|
||||||
assert.isFunction(modulejs.state);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.log() is function', function () {
|
|
||||||
assert.isFunction(modulejs.log);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('._private is object', function () {
|
|
||||||
assert.isObject(modulejs._private);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has definitions', function () {
|
|
||||||
assert.isAbove(_.keys(modulejs._private.definitions).length, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instances', function () {
|
|
||||||
assert.lengthOfKeys(modulejs._private.instances, 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,73 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/content';
|
|
||||||
var DEPS = ['$', 'view/mainrow'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xMainrow = {$el: null};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn($, this.xMainrow);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xMainrow.$el = $('<div id="mainrow"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns object with 1 property', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #content to #mainrow', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#mainrow > #content'), 1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#content\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'content');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,73 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/mainrow';
|
|
||||||
var DEPS = ['$', 'view/root'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xRoot = {$el: null};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn($, this.xRoot);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xRoot.$el = $('<div id="root"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns object with 1 property', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #mainrow to #root', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#root > #mainrow'), 1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#mainrow\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'mainrow');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,102 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/notification';
|
|
||||||
var DEPS = ['$', 'view/root'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xRoot = {$el: null};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn($, this.xRoot);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xRoot.$el = $('<div id="root"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns plain object with 2 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #notification to #root (hidden)', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#root > #notification'), 1);
|
|
||||||
assert.lengthOf($('#notification:visible'), 0);
|
|
||||||
assert.strictEqual($('#notification').text(), '');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#notification\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'notification');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.set()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.set));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('works', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
|
|
||||||
instance.set();
|
|
||||||
assert.lengthOf($('#notification:visible'), 0);
|
|
||||||
assert.strictEqual($('#notification').text(), '');
|
|
||||||
|
|
||||||
instance.set('hello');
|
|
||||||
assert.lengthOf($('#notification:visible'), 1);
|
|
||||||
assert.strictEqual($('#notification').text(), 'hello');
|
|
||||||
|
|
||||||
instance.set('world');
|
|
||||||
assert.lengthOf($('#notification:visible'), 1);
|
|
||||||
assert.strictEqual($('#notification').text(), 'world');
|
|
||||||
|
|
||||||
instance.set();
|
|
||||||
// assert.lengthOf($('#notification:visible'), 0);
|
|
||||||
assert.strictEqual($('#notification').text(), 'world');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,83 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/root';
|
|
||||||
var DEPS = ['$'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn($);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
$('<div id="fallback"/>').appendTo('body');
|
|
||||||
$('<div id="fallback-hints"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns object with 1 property', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds id root to body', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual($('body').attr('id'), 'root');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes HTML #fallback', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#fallback'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes HTML #fallback-hints', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#fallback-hints'), 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#root\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'root');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,121 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/sidebar';
|
|
||||||
var DEPS = ['$', 'core/resource', 'core/store', 'view/mainrow', 'view/topbar'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xResource = {
|
|
||||||
image: sinon.stub().throws('invalid image request')
|
|
||||||
};
|
|
||||||
this.xResource.image.withArgs('back').returns(uniq.path('-back.png'));
|
|
||||||
this.xResource.image.withArgs('sidebar').returns(uniq.path('-sidebar.png'));
|
|
||||||
this.xStore = {
|
|
||||||
get: sinon.stub().returns(false),
|
|
||||||
put: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xStore.get.returns(false);
|
|
||||||
this.xMainrow = {$el: null};
|
|
||||||
this.xTopbar = {$toolbar: null};
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xResource.image.reset();
|
|
||||||
this.xStore.get.reset();
|
|
||||||
this.xStore.put.reset();
|
|
||||||
|
|
||||||
return this.definition.fn($, this.xResource, this.xStore, this.xMainrow, this.xTopbar);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xMainrow.$el = $('<div id="mainrow"/>').appendTo('body');
|
|
||||||
this.xTopbar.$toolbar = $('<div id="toolbar"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.instance = this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns object with 1 property', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #sidebar-toggle to #toolbar', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#toolbar > #sidebar-toggle'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('toggle works', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#sidebar:visible'), 0);
|
|
||||||
|
|
||||||
this.xStore.get.returns(false).reset();
|
|
||||||
this.xStore.put.reset();
|
|
||||||
|
|
||||||
$('#sidebar-toggle').trigger('click');
|
|
||||||
|
|
||||||
assert.isTrue(this.xStore.get.calledOnce);
|
|
||||||
assert.strictEqual(this.xStore.get.lastCall.args[0], 'sidebarIsVisible');
|
|
||||||
assert.isTrue(this.xStore.put.calledOnce);
|
|
||||||
assert.strictEqual(this.xStore.put.lastCall.args[0], 'sidebarIsVisible');
|
|
||||||
assert.isTrue(this.xStore.put.lastCall.args[1]);
|
|
||||||
|
|
||||||
assert.lengthOf($('#sidebar:visible'), 1);
|
|
||||||
|
|
||||||
this.xStore.get.returns(true).reset();
|
|
||||||
this.xStore.put.reset();
|
|
||||||
|
|
||||||
$('#sidebar-toggle').trigger('click');
|
|
||||||
|
|
||||||
assert.isTrue(this.xStore.get.calledOnce);
|
|
||||||
assert.strictEqual(this.xStore.get.lastCall.args[0], 'sidebarIsVisible');
|
|
||||||
assert.isTrue(this.xStore.put.calledOnce);
|
|
||||||
assert.strictEqual(this.xStore.put.lastCall.args[0], 'sidebarIsVisible');
|
|
||||||
assert.isFalse(this.xStore.put.lastCall.args[1]);
|
|
||||||
|
|
||||||
assert.lengthOf($('#sidebar:visible'), 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#sidebar\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'sidebar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,124 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/topbar';
|
|
||||||
var DEPS = ['$', 'view/root'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xRoot = {$el: null};
|
|
||||||
this.applyFn = function () {
|
|
||||||
return this.definition.fn($, this.xRoot);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xRoot.$el = $('<div id="root"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns object with 3 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 3);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #topbar to #root', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#root > #topbar'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #toolbar to #topbar', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#topbar > #toolbar'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #flowbar to #topbar', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#topbar > #flowbar'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #backlink to #topbar', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#topbar > #backlink'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('#backlink has correct href', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual($('#backlink').attr('href'), 'https://larsjung.de/h5ai/');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('#backlink has correct title', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual($('#backlink').attr('title'), 'powered by h5ai - https://larsjung.de/h5ai/');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('#backlink has correct text', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual($('#backlink > div').eq(0).text(), 'powered');
|
|
||||||
assert.strictEqual($('#backlink > div').eq(1).text(), 'by h5ai');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#topbar\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'topbar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$toolbar', function () {
|
|
||||||
it('is $(\'#toolbar\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$toolbar);
|
|
||||||
assert.lengthOf(instance.$toolbar, 1);
|
|
||||||
assert.isString(instance.$toolbar.jquery);
|
|
||||||
assert.strictEqual(instance.$toolbar.attr('id'), 'toolbar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$flowbar', function () {
|
|
||||||
it('is $(\'#flowbar\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$flowbar);
|
|
||||||
assert.lengthOf(instance.$flowbar, 1);
|
|
||||||
assert.isString(instance.$flowbar.jquery);
|
|
||||||
assert.strictEqual(instance.$flowbar.attr('id'), 'flowbar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,385 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/view';
|
|
||||||
var DEPS = ['_', '$', 'core/event', 'core/format', 'core/location', 'core/resource', 'core/settings', 'core/store', 'view/content'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xEvent = {
|
|
||||||
sub: sinon.stub(),
|
|
||||||
pub: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xFormat = {
|
|
||||||
setDefaultMetric: sinon.stub(),
|
|
||||||
formatDate: sinon.stub().returns(uniq.id()),
|
|
||||||
formatSize: sinon.stub().returns(uniq.id())
|
|
||||||
};
|
|
||||||
this.xLocation = {
|
|
||||||
setLink: sinon.stub().returns(uniq.id())
|
|
||||||
};
|
|
||||||
this.xResource = {
|
|
||||||
icon: sinon.stub().returns(uniq.id())
|
|
||||||
};
|
|
||||||
this.xSettings = {view: {
|
|
||||||
binaryPrefix: false,
|
|
||||||
hideFolders: false,
|
|
||||||
hideParentFolder: false,
|
|
||||||
modes: ['details', 'grid', 'icons'],
|
|
||||||
setParentFolderLabels: false,
|
|
||||||
sizes: [20, 40, 60, 80, 100, 150, 200, 250, 300, 350, 400]
|
|
||||||
}};
|
|
||||||
this.xStore = {
|
|
||||||
get: sinon.stub(),
|
|
||||||
put: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xContent = {$el: null};
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xEvent.sub.reset();
|
|
||||||
this.xEvent.pub.reset();
|
|
||||||
this.xFormat.setDefaultMetric.reset();
|
|
||||||
this.xFormat.formatDate.reset();
|
|
||||||
this.xFormat.formatSize.reset();
|
|
||||||
this.xLocation.setLink.reset();
|
|
||||||
this.xResource.icon.reset();
|
|
||||||
|
|
||||||
return this.definition.fn(_, $, this.xEvent, this.xFormat, this.xLocation, this.xResource, this.xSettings, this.xStore, this.xContent);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xContent.$el = $('<div id="content"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns object with 12 properties', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isPlainObject(instance);
|
|
||||||
assert.lengthOfKeys(instance, 12);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #view to #content', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#content > #view'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #items to #view', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#view > #items'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #view-hint to #view', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#view > #view-hint'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds style to head', function () {
|
|
||||||
var styleTagCount = $('head > style').length;
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('head > style'), styleTagCount + 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('style contains possibly correct text', function () {
|
|
||||||
this.xSettings.sizes = [20];
|
|
||||||
this.applyFn();
|
|
||||||
var text = $('head > style').eq(0).text();
|
|
||||||
assert.isTrue(text.indexOf('#view.view-details.view-size-20 ') >= 0);
|
|
||||||
assert.isTrue(text.indexOf('#view.view-grid.view-size-20 ') >= 0);
|
|
||||||
assert.isTrue(text.indexOf('#view.view-icons.view-size-20 ') >= 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets default metric', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.isTrue(this.xFormat.setDefaultMetric.calledOnce);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('subscribes to 2 events', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.isTrue(this.xEvent.sub.calledTwice);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('subscribes to location.changed', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual(this.xEvent.sub.firstCall.args[0], 'location.changed');
|
|
||||||
assert.isFunction(this.xEvent.sub.firstCall.args[1]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('subscribes to location.refreshed', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.strictEqual(this.xEvent.sub.secondCall.args[0], 'location.refreshed');
|
|
||||||
assert.isFunction(this.xEvent.sub.secondCall.args[1]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$el', function () {
|
|
||||||
it('is $(\'#view\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$el);
|
|
||||||
assert.lengthOf(instance.$el, 1);
|
|
||||||
assert.isString(instance.$el.jquery);
|
|
||||||
assert.strictEqual(instance.$el.attr('id'), 'view');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.$items', function () {
|
|
||||||
it('is $(\'#items\')', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isObject(instance.$items);
|
|
||||||
assert.lengthOf(instance.$items, 1);
|
|
||||||
assert.isString(instance.$items.jquery);
|
|
||||||
assert.strictEqual(instance.$items.attr('id'), 'items');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setItems()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.setItems));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('publishes view.changed', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setItems();
|
|
||||||
assert.isTrue(this.xEvent.pub.calledTwice);
|
|
||||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.changeItems()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.changeItems));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('publishes view.changed', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setItems();
|
|
||||||
assert.isTrue(this.xEvent.pub.calledTwice);
|
|
||||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setLocation()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.setLocation));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('publishes view.changed', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setItems();
|
|
||||||
assert.isTrue(this.xEvent.pub.calledTwice);
|
|
||||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setHint()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.setHint));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets correct class to #view-hint', function () {
|
|
||||||
var key = uniq.id();
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setHint(key);
|
|
||||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes all other classes from #view-hint', function () {
|
|
||||||
var key = uniq.id();
|
|
||||||
var instance = this.applyFn();
|
|
||||||
$('#view-hint').addClass('a');
|
|
||||||
instance.setHint(key);
|
|
||||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getModes()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.getModes));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getMode()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.getMode));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setMode()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.setMode));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.setMode(\'details\') changes #view class to .view-details', function () {
|
|
||||||
this.xSettings.view.modes = ['details', 'grid', 'icons'];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setMode('details');
|
|
||||||
assert.isTrue($('#view').hasClass('view-details'));
|
|
||||||
assert.isFalse($('#view').hasClass('view-grid'));
|
|
||||||
assert.isFalse($('#view').hasClass('view-icons'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.setMode(\'grid\') changes #view class to .view-grid', function () {
|
|
||||||
this.xSettings.view.modes = ['details', 'grid', 'icons'];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setMode('grid');
|
|
||||||
assert.isFalse($('#view').hasClass('view-details'));
|
|
||||||
assert.isTrue($('#view').hasClass('view-grid'));
|
|
||||||
assert.isFalse($('#view').hasClass('view-icons'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.setMode(\'icons\') changes #view class to .view-icons', function () {
|
|
||||||
this.xSettings.view.modes = ['details', 'grid', 'icons'];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setMode('icons');
|
|
||||||
assert.isFalse($('#view').hasClass('view-details'));
|
|
||||||
assert.isFalse($('#view').hasClass('view-grid'));
|
|
||||||
assert.isTrue($('#view').hasClass('view-icons'));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getSizes()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.getSizes));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns sorted sizes', function () {
|
|
||||||
this.xSettings.view.sizes = [20, 60, 40];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.deepEqual(instance.getSizes(), [20, 40, 60]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns sorted sizes', function () {
|
|
||||||
this.xSettings.view.sizes = [60, 40, 20];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.deepEqual(instance.getSizes(), [20, 40, 60]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getSize()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.getSize));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.setSize()', function () {
|
|
||||||
it('is function', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isTrue(_.isFunction(instance.setSize));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.setSize(20) changes #view class to .view-size-20', function () {
|
|
||||||
this.xSettings.view.sizes = [20, 40, 60];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setSize(20);
|
|
||||||
assert.isTrue($('#view').hasClass('view-size-20'), 20);
|
|
||||||
assert.isFalse($('#view').hasClass('view-size-40'), 40);
|
|
||||||
assert.isFalse($('#view').hasClass('view-size-60'), 60);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.setSize(40) changes #view class to .view-size-40', function () {
|
|
||||||
this.xSettings.view.sizes = [20, 40, 60];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setSize(20);
|
|
||||||
instance.setSize(40);
|
|
||||||
assert.isFalse($('#view').hasClass('view-size-20'), 20);
|
|
||||||
assert.isTrue($('#view').hasClass('view-size-40'), 40);
|
|
||||||
assert.isFalse($('#view').hasClass('view-size-60'), 60);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.setSize(60) changes #view class to .view-size-60', function () {
|
|
||||||
this.xSettings.view.sizes = [20, 40, 60];
|
|
||||||
var instance = this.applyFn();
|
|
||||||
instance.setSize(20);
|
|
||||||
instance.setSize(60);
|
|
||||||
assert.isFalse($('#view').hasClass('view-size-20'), 20);
|
|
||||||
assert.isFalse($('#view').hasClass('view-size-40'), 40);
|
|
||||||
assert.isTrue($('#view').hasClass('view-size-60'), 60);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// describe('._.createHtml()', function () {
|
|
||||||
// before(function () {
|
|
||||||
// this.createItem = function () {
|
|
||||||
// return {
|
|
||||||
// isFolder: sinon.stub().returns(false),
|
|
||||||
// label: uniq.id(),
|
|
||||||
// time: 0,
|
|
||||||
// size: 0,
|
|
||||||
// type: uniq.id(),
|
|
||||||
// isManaged: false,
|
|
||||||
// icon: null,
|
|
||||||
// isCurrentParentFolder: sinon.stub().returns(false)
|
|
||||||
// };
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it('is function', function () {
|
|
||||||
// var instance = this.applyFn();
|
|
||||||
// assert.isFunction(instance._.createHtml);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it('returns jQuery instance of single HTML element', function () {
|
|
||||||
// var item = this.createItem();
|
|
||||||
// var instance = this.applyFn();
|
|
||||||
// var $item = instance._.createHtml(item);
|
|
||||||
// assert.isObject($item);
|
|
||||||
// assert.lengthOf($item, 1);
|
|
||||||
// assert.isString($item.jquery);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it('$item.data(\'item\') is back reference to item', function () {
|
|
||||||
// var item = this.createItem();
|
|
||||||
// var instance = this.applyFn();
|
|
||||||
// var $item = instance._.createHtml(item);
|
|
||||||
// assert.strictEqual($item.data('item'), item);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it('sets item.$view as reference to $item', function () {
|
|
||||||
// var item = this.createItem();
|
|
||||||
// var instance = this.applyFn();
|
|
||||||
// var $item = instance._.createHtml(item);
|
|
||||||
// assert.strictEqual(item.$view, $item);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,189 +0,0 @@
|
||||||
(function () {
|
|
||||||
var ID = 'view/viewmode';
|
|
||||||
var DEPS = ['_', '$', 'core/event', 'core/resource', 'core/settings', 'view/sidebar', 'view/topbar', 'view/view'];
|
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
|
||||||
before(function () {
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
|
||||||
|
|
||||||
this.xEvent = {
|
|
||||||
sub: sinon.stub(),
|
|
||||||
pub: sinon.stub()
|
|
||||||
};
|
|
||||||
this.xResource = {
|
|
||||||
image: sinon.stub().returns(uniq.path('-image.png'))
|
|
||||||
};
|
|
||||||
this.xSettings = {view: {
|
|
||||||
modeToggle: false
|
|
||||||
}};
|
|
||||||
this.xSidebar = {$el: null};
|
|
||||||
this.xTopbar = {$el: null};
|
|
||||||
this.xView = {
|
|
||||||
$el: null,
|
|
||||||
getModes: sinon.stub().returns(['details', 'grid', 'icons']),
|
|
||||||
getMode: sinon.stub(),
|
|
||||||
setMode: sinon.stub(),
|
|
||||||
getSizes: sinon.stub().returns([20, 30, 40]),
|
|
||||||
getSize: sinon.stub(),
|
|
||||||
setSize: sinon.stub()
|
|
||||||
};
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
|
||||||
this.xEvent.sub.reset();
|
|
||||||
this.xEvent.pub.reset();
|
|
||||||
this.xResource.image.reset();
|
|
||||||
this.xView.getModes.reset();
|
|
||||||
this.xView.getMode.reset();
|
|
||||||
this.xView.setMode.reset();
|
|
||||||
this.xView.getSizes.reset();
|
|
||||||
this.xView.getSize.reset();
|
|
||||||
this.xView.setSize.reset();
|
|
||||||
|
|
||||||
return this.definition.fn(_, $, this.xEvent, this.xResource, this.xSettings, this.xSidebar, this.xTopbar, this.xView);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
util.restoreHtml();
|
|
||||||
this.xSidebar.$el = $('<div id="sidebar"/>').appendTo('body');
|
|
||||||
this.xTopbar.$el = $('<div id="topbar"/>').appendTo('body');
|
|
||||||
this.xView.$el = $('<div id="view"/>').appendTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('definition', function () {
|
|
||||||
it('is defined', function () {
|
|
||||||
assert.isPlainObject(this.definition);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has correct id', function () {
|
|
||||||
assert.strictEqual(this.definition.id, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('requires correct', function () {
|
|
||||||
assert.deepEqual(this.definition.deps, DEPS);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('args for each request', function () {
|
|
||||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has no instance', function () {
|
|
||||||
assert.notProperty(modulejs._private.instances, ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inits without errors', function () {
|
|
||||||
this.applyFn();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('application', function () {
|
|
||||||
it('returns undefined', function () {
|
|
||||||
var instance = this.applyFn();
|
|
||||||
assert.isUndefined(instance);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #viewmode-settings to #sidebar', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#sidebar > #viewmode-settings'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #viewmode-details to #viewmode-settings', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#viewmode-settings > #viewmode-details'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #viewmode-grid to #viewmode-settings', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#viewmode-settings > #viewmode-grid'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #viewmode-icons to #viewmode-settings', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#viewmode-settings > #viewmode-icons'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds HTML #viewmode-size to #viewmode-settings', function () {
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#viewmode-settings > #viewmode-size'), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not add HTML #viewmode-details, #viewmode-grid, #viewmode-icons when only one mode', function () {
|
|
||||||
this.xView.getModes.returns(['details']);
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#viewmode-details'), 0);
|
|
||||||
assert.lengthOf($('#viewmode-grid'), 0);
|
|
||||||
assert.lengthOf($('#viewmode-icons'), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not add HTML #viewmode-size when only one size', function () {
|
|
||||||
this.xView.getSizes.returns([20]);
|
|
||||||
this.applyFn();
|
|
||||||
assert.lengthOf($('#viewmode-size'), 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('works', function () {
|
|
||||||
it('clicking #viewmode-details triggers view.setMode(\'details\')', function () {
|
|
||||||
this.xView.getModes.returns(['details', 'grid', 'icons']);
|
|
||||||
this.applyFn();
|
|
||||||
$('#viewmode-details').trigger('click');
|
|
||||||
assert.isTrue(this.xView.setMode.calledOnce);
|
|
||||||
assert.deepEqual(this.xView.setMode.lastCall.args, ['details']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('clicking #viewmode-grid triggers view.setMode(\'grid\')', function () {
|
|
||||||
this.xView.getModes.returns(['details', 'grid', 'icons']);
|
|
||||||
this.applyFn();
|
|
||||||
$('#viewmode-grid').trigger('click');
|
|
||||||
assert.isTrue(this.xView.setMode.calledOnce);
|
|
||||||
assert.deepEqual(this.xView.setMode.lastCall.args, ['grid']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('clicking #viewmode-icons triggers view.setMode(\'icons\')', function () {
|
|
||||||
this.xView.getModes.returns(['details', 'grid', 'icons']);
|
|
||||||
this.applyFn();
|
|
||||||
$('#viewmode-icons').trigger('click');
|
|
||||||
assert.isTrue(this.xView.setMode.calledOnce);
|
|
||||||
assert.deepEqual(this.xView.setMode.lastCall.args, ['icons']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('changing #viewmode-size triggers view.setSize(*)', function () {
|
|
||||||
this.xView.getSizes.returns([20, 40, 60]);
|
|
||||||
this.applyFn();
|
|
||||||
|
|
||||||
$('#viewmode-size').val(0).trigger('change');
|
|
||||||
assert.isTrue(this.xView.setSize.calledOnce);
|
|
||||||
assert.deepEqual(this.xView.setSize.lastCall.args, [20]);
|
|
||||||
|
|
||||||
$('#viewmode-size').val(1).trigger('change');
|
|
||||||
assert.isTrue(this.xView.setSize.calledTwice);
|
|
||||||
assert.deepEqual(this.xView.setSize.lastCall.args, [40]);
|
|
||||||
|
|
||||||
$('#viewmode-size').val(2).trigger('change');
|
|
||||||
assert.isTrue(this.xView.setSize.calledThrice);
|
|
||||||
assert.deepEqual(this.xView.setSize.lastCall.args, [60]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inputing #viewmode-size triggers view.setSize(*)', function () {
|
|
||||||
this.xView.getSizes.returns([20, 40, 60]);
|
|
||||||
this.applyFn();
|
|
||||||
|
|
||||||
$('#viewmode-size').val(0).trigger('input');
|
|
||||||
assert.isTrue(this.xView.setSize.calledOnce);
|
|
||||||
assert.deepEqual(this.xView.setSize.lastCall.args, [20]);
|
|
||||||
|
|
||||||
$('#viewmode-size').val(1).trigger('input');
|
|
||||||
assert.isTrue(this.xView.setSize.calledTwice);
|
|
||||||
assert.deepEqual(this.xView.setSize.lastCall.args, [40]);
|
|
||||||
|
|
||||||
$('#viewmode-size').val(2).trigger('input');
|
|
||||||
assert.isTrue(this.xView.setSize.calledThrice);
|
|
||||||
assert.deepEqual(this.xView.setSize.lastCall.args, [60]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}());
|
|
|
@ -1,12 +0,0 @@
|
||||||
(function () {
|
|
||||||
var assert = window.chai.assert;
|
|
||||||
|
|
||||||
assert.lengthOfKeys = function (val, count, msg) {
|
|
||||||
var keyCount = _.keys(val).length;
|
|
||||||
assert(keyCount === count, msg ? msg : 'expected ' + val + ' to have ' + count + ' keys, but has ' + keyCount);
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.isPlainObject = function (val, msg) {
|
|
||||||
assert($.isPlainObject(val), msg ? msg : 'expected ' + val + ' to be a plain Object');
|
|
||||||
};
|
|
||||||
}());
|
|
|
@ -1,107 +0,0 @@
|
||||||
(function () {
|
|
||||||
var showOnlyFailures = false;
|
|
||||||
var template =
|
|
||||||
'<div id="mocha-bar">' +
|
|
||||||
'<a class="title" href="?">' + document.title + '</a>' +
|
|
||||||
'<div class="stats"/>' +
|
|
||||||
'<div class="progress"/>' +
|
|
||||||
'</div>';
|
|
||||||
var $mochaBar = $(template);
|
|
||||||
var $mochaStats = $mochaBar.find('.stats');
|
|
||||||
var $mochaProgress = $mochaBar.find('.progress');
|
|
||||||
|
|
||||||
function toggleFailureFilter(ev) {
|
|
||||||
ev.stopImmediatePropagation();
|
|
||||||
|
|
||||||
showOnlyFailures = !showOnlyFailures;
|
|
||||||
if (showOnlyFailures) {
|
|
||||||
$('.suite, .test').hide();
|
|
||||||
$('.suite.fail, .test.fail').show();
|
|
||||||
} else {
|
|
||||||
$('.suite, .test').show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addSuiteStats() {
|
|
||||||
var $suite = $(this);
|
|
||||||
|
|
||||||
var tests = $suite.find('.test').length;
|
|
||||||
var passed = $suite.find('.test.pass').length;
|
|
||||||
var failed = tests - passed;
|
|
||||||
|
|
||||||
var $header = $suite.find('> h1 a');
|
|
||||||
var $list = $suite.find('> ul');
|
|
||||||
var $count = $('<span class="count"><span class="passed">' + passed + '</span><span class="failed">' + failed + '</span></span>');
|
|
||||||
var $toggle = $('<span class="toggle">-</span>');
|
|
||||||
var visible = true;
|
|
||||||
|
|
||||||
$toggle.on('click', function (ev) {
|
|
||||||
ev.stopImmediatePropagation();
|
|
||||||
|
|
||||||
visible = !visible;
|
|
||||||
if (visible) {
|
|
||||||
$toggle.text('-');
|
|
||||||
$list.show();
|
|
||||||
} else {
|
|
||||||
$toggle.text('+');
|
|
||||||
$list.hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!failed) {
|
|
||||||
$count.find('.failed').remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
$suite.addClass(tests === passed ? 'pass' : 'fail');
|
|
||||||
// $suite.append($toggle);
|
|
||||||
$header.append($count);
|
|
||||||
}
|
|
||||||
|
|
||||||
function fixCodeFormatting() {
|
|
||||||
var $code = $(this);
|
|
||||||
$code.text($code.text().trim().replace(/;\n\s*/g, ';\n'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function onEnd() {
|
|
||||||
var runner = this;
|
|
||||||
var failed = runner.stats.failures > 0;
|
|
||||||
var stats = (runner.stats.duration / 1000.0).toFixed(3) + 's';
|
|
||||||
|
|
||||||
if (failed) {
|
|
||||||
$mochaStats.on('click', toggleFailureFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mochaBar.addClass(failed ? 'fail' : 'pass');
|
|
||||||
$mochaProgress.hide();
|
|
||||||
$mochaStats.text(stats);
|
|
||||||
$('#mocha-report .suite').each(addSuiteStats);
|
|
||||||
$('#mocha-report code').each(fixCodeFormatting);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTest() {
|
|
||||||
var runner = this;
|
|
||||||
var percent = 100.0 * runner.stats.tests / runner.total;
|
|
||||||
var stats = ((new Date().getTime() - runner.stats.start) / 1000.0).toFixed(3) + 's';
|
|
||||||
|
|
||||||
if (runner.stats.failures) {
|
|
||||||
$mochaBar.addClass('fail');
|
|
||||||
}
|
|
||||||
$mochaProgress.css('width', 100 - percent + '%');
|
|
||||||
$mochaStats.text(stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupMocha() {
|
|
||||||
window.assert = window.chai.assert;
|
|
||||||
mocha.setup('bdd');
|
|
||||||
$(function () { $mochaBar.appendTo('#mocha'); });
|
|
||||||
}
|
|
||||||
|
|
||||||
function runMocha() {
|
|
||||||
mocha.run().on('test', onTest).on('end', onEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.util = window.util || {};
|
|
||||||
window.util.setupMocha = setupMocha;
|
|
||||||
window.util.runMocha = runMocha;
|
|
||||||
}());
|
|
|
@ -1,15 +0,0 @@
|
||||||
(function () {
|
|
||||||
function clearModulejs() {
|
|
||||||
_.each(modulejs._private.instances, function (val, key) {
|
|
||||||
delete modulejs._private.instances[key];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockConfigModule() {
|
|
||||||
modulejs.define('config', window.uniq.obj());
|
|
||||||
}
|
|
||||||
|
|
||||||
window.util = window.util || {};
|
|
||||||
window.util.clearModulejs = clearModulejs;
|
|
||||||
window.util.mockConfigModule = mockConfigModule;
|
|
||||||
}());
|
|
|
@ -1,33 +1,33 @@
|
||||||
(function () {
|
const win = global.window;
|
||||||
var title;
|
const doc = win.document;
|
||||||
var htmlId;
|
const jq = win.jQuery;
|
||||||
var htmlClasses;
|
let title;
|
||||||
var bodyId;
|
let htmlId;
|
||||||
var bodyClasses;
|
let htmlClasses;
|
||||||
var $pinnedElements;
|
let bodyId;
|
||||||
|
let bodyClasses;
|
||||||
|
let $pinnedElements;
|
||||||
|
|
||||||
function pinHtml() {
|
function pinHtml() {
|
||||||
title = document.title;
|
title = doc.title;
|
||||||
htmlId = $('html').attr('id');
|
htmlId = jq('html').attr('id');
|
||||||
htmlClasses = $('html').attr('class');
|
htmlClasses = jq('html').attr('class');
|
||||||
bodyId = $('body').attr('id');
|
bodyId = jq('body').attr('id');
|
||||||
bodyClasses = $('body').attr('class');
|
bodyClasses = jq('body').attr('class');
|
||||||
$pinnedElements = $('head,body').children();
|
$pinnedElements = jq('head,body').children();
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreHtml() {
|
function restoreHtml() {
|
||||||
document.title = title;
|
doc.title = title;
|
||||||
$('html').attr('id', htmlId);
|
jq('html').attr('id', htmlId);
|
||||||
$('html').attr('class', htmlClasses);
|
jq('html').attr('class', htmlClasses);
|
||||||
$('body').attr('id', bodyId);
|
jq('body').attr('id', bodyId);
|
||||||
$('body').attr('class', bodyClasses);
|
jq('body').attr('class', bodyClasses);
|
||||||
$('head,body').children().not($pinnedElements).remove();
|
jq('head,body').children().not($pinnedElements).remove();
|
||||||
if (window.localStorage && window.localStorage.clear) {
|
win.localStorage.clear();
|
||||||
window.localStorage.clear();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.util = window.util || {};
|
module.exports = {
|
||||||
window.util.pinHtml = pinHtml;
|
pinHtml,
|
||||||
window.util.restoreHtml = restoreHtml;
|
restoreHtml
|
||||||
}());
|
};
|
||||||
|
|
5332
test/vendor/chai.js
vendored
5332
test/vendor/chai.js
vendored
File diff suppressed because it is too large
Load diff
6564
test/vendor/mocha.js
vendored
6564
test/vendor/mocha.js
vendored
File diff suppressed because it is too large
Load diff
6437
test/vendor/sinon.js
vendored
6437
test/vendor/sinon.js
vendored
File diff suppressed because it is too large
Load diff
46
test/vendor/uniq.js
vendored
46
test/vendor/uniq.js
vendored
|
@ -1,46 +0,0 @@
|
||||||
/* uniq 0.4.0 - http://larsjung.de/uniq/ */
|
|
||||||
(function (root, factory) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// istanbul ignore else
|
|
||||||
if (typeof exports === 'object') {
|
|
||||||
module.exports = factory();
|
|
||||||
} else {
|
|
||||||
root.uniq = factory();
|
|
||||||
}
|
|
||||||
|
|
||||||
}(this, function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var PREFIX = 'UNIQ-';
|
|
||||||
var SUFFIX = '-ID';
|
|
||||||
var LENGTH = 4;
|
|
||||||
var ZERO_PAD = new Array(LENGTH + 1).join('0');
|
|
||||||
var RE_ID = new RegExp('^' + PREFIX + '\\d{' + LENGTH + '}' + SUFFIX + '$');
|
|
||||||
|
|
||||||
var counter = 0;
|
|
||||||
|
|
||||||
function id() {
|
|
||||||
counter += 1;
|
|
||||||
return PREFIX + (ZERO_PAD + counter).substr(-LENGTH) + SUFFIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isId(sequence) {
|
|
||||||
return RE_ID.test(sequence);
|
|
||||||
}
|
|
||||||
|
|
||||||
function obj() {
|
|
||||||
return {_uniq_id: id()};
|
|
||||||
}
|
|
||||||
|
|
||||||
function path(suffix) {
|
|
||||||
return '/_uniq_path/' + id() + (suffix ? suffix : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: id,
|
|
||||||
isId: isId,
|
|
||||||
obj: obj,
|
|
||||||
path: path
|
|
||||||
};
|
|
||||||
}));
|
|
Loading…
Add table
Add a link
Reference in a new issue