2015-04-22 17:12:45 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ID = 'core/location';
|
|
|
|
var DEPS = ['_', 'modernizr', 'core/event', 'core/notify', 'core/settings'];
|
|
|
|
|
2015-04-22 23:21:48 +02:00
|
|
|
describe('module \'' + ID + '\'', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
|
|
|
|
this.definition = modulejs._private.definitions[ID];
|
|
|
|
|
|
|
|
this.xModernizr = {
|
|
|
|
history: true
|
|
|
|
};
|
2015-04-29 00:39:22 +02:00
|
|
|
this.xSettings = {view: {
|
|
|
|
fastBrowsing: true,
|
2015-04-22 17:12:45 +02:00
|
|
|
unmanagedInNewWindow: true
|
2015-04-29 00:39:22 +02:00
|
|
|
}};
|
2015-04-22 17:12:45 +02:00
|
|
|
this.xEvent = {
|
|
|
|
pub: sinon.stub(),
|
|
|
|
sub: sinon.stub()
|
|
|
|
};
|
|
|
|
this.xNotify = {
|
|
|
|
set: sinon.stub()
|
|
|
|
};
|
|
|
|
this.applyFn = function () {
|
|
|
|
|
2015-04-29 00:39:22 +02:00
|
|
|
this.xEvent.pub.reset();
|
|
|
|
this.xEvent.sub.reset();
|
|
|
|
this.xNotify.set.reset();
|
|
|
|
|
2015-04-22 17:12:45 +02:00
|
|
|
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xNotify, this.xSettings);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2015-04-29 00:39:22 +02:00
|
|
|
after(function () {
|
|
|
|
|
|
|
|
window.onpopstate = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
|
|
|
window.onpopstate = null;
|
|
|
|
});
|
|
|
|
|
2015-04-22 17:12:45 +02:00
|
|
|
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);
|
|
|
|
});
|
2015-04-29 00:39:22 +02:00
|
|
|
|
|
|
|
it('sets window.onpopstate 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('does not set window.onpopstate 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('does not set window.onpopstate 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('does not set window.onpopstate 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);
|
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.forceEncoding()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.forceEncoding);
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 21:30:29 +02:00
|
|
|
|
|
|
|
_.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];
|
|
|
|
|
2015-04-22 23:45:23 +02:00
|
|
|
it(arg + ' => ' + exp, function () {
|
2015-04-22 21:30:29 +02:00
|
|
|
|
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.strictEqual(instance.forceEncoding(arg), exp);
|
|
|
|
});
|
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.getDomain()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.getDomain);
|
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('returns document.domain', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
2015-04-22 21:30:29 +02:00
|
|
|
assert.strictEqual(instance.getDomain(), window.document.domain);
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.getAbsHref()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.getAbsHref);
|
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('returns null before .setLocation()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isNull(instance.getAbsHref());
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.getItem()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.getItem);
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.setLocation()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.setLocation);
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.refresh()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.refresh);
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.setLink()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.setLink);
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
2015-04-22 21:30:29 +02:00
|
|
|
|
|
|
|
it('sets href correct', function () {
|
|
|
|
|
|
|
|
var $el = $('<a/>');
|
|
|
|
var item = {
|
|
|
|
absHref: util.uniqId(),
|
|
|
|
isManaged: false,
|
|
|
|
isFolder: sinon.stub().returns(false)
|
|
|
|
};
|
|
|
|
|
|
|
|
var setLink = this.applyFn().setLink;
|
|
|
|
setLink($el, item);
|
|
|
|
|
|
|
|
assert.strictEqual($el.attr('href'), item.absHref);
|
|
|
|
});
|
|
|
|
|
2015-04-22 23:21:48 +02:00
|
|
|
it('sets target=\'_blank\' for unmanaged folders', function () {
|
2015-04-22 21:30:29 +02:00
|
|
|
|
2015-04-29 00:39:22 +02:00
|
|
|
this.xSettings.view.unmanagedInNewWindow = true;
|
2015-04-22 21:30:29 +02:00
|
|
|
|
|
|
|
var $el = $('<a/>');
|
|
|
|
var item = {
|
|
|
|
absHref: util.uniqId(),
|
|
|
|
isManaged: false,
|
|
|
|
isFolder: sinon.stub().returns(true)
|
|
|
|
};
|
|
|
|
|
|
|
|
var setLink = this.applyFn().setLink;
|
|
|
|
setLink($el, item);
|
|
|
|
|
|
|
|
assert.strictEqual($el.attr('target'), '_blank');
|
|
|
|
});
|
|
|
|
|
2015-04-22 23:21:48 +02:00
|
|
|
it('does not set target=\'_blank\' for managed folders', function () {
|
2015-04-22 21:30:29 +02:00
|
|
|
|
2015-04-29 00:39:22 +02:00
|
|
|
this.xSettings.view.unmanagedInNewWindow = true;
|
2015-04-22 21:30:29 +02:00
|
|
|
|
|
|
|
var $el = $('<a/>');
|
|
|
|
var item = {
|
|
|
|
absHref: util.uniqId(),
|
|
|
|
isManaged: true,
|
|
|
|
isFolder: sinon.stub().returns(true)
|
|
|
|
};
|
|
|
|
|
|
|
|
var setLink = this.applyFn().setLink;
|
|
|
|
setLink($el, item);
|
|
|
|
|
|
|
|
assert.isUndefined($el.attr('target'));
|
|
|
|
});
|
|
|
|
|
2015-04-22 23:21:48 +02:00
|
|
|
it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
|
2015-04-22 21:30:29 +02:00
|
|
|
|
2015-04-29 00:39:22 +02:00
|
|
|
this.xSettings.view.unmanagedInNewWindow = false;
|
2015-04-22 21:30:29 +02:00
|
|
|
|
|
|
|
var $el = $('<a/>');
|
|
|
|
var item = {
|
|
|
|
absHref: util.uniqId(),
|
|
|
|
isManaged: true,
|
|
|
|
isFolder: sinon.stub().returns(true)
|
|
|
|
};
|
|
|
|
|
|
|
|
var setLink = this.applyFn().setLink;
|
|
|
|
setLink($el, item);
|
|
|
|
|
|
|
|
assert.isUndefined($el.attr('target'));
|
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}());
|