h5ai/test/tests/unit/core/location.js

256 lines
6.3 KiB
JavaScript
Raw Normal View History

2015-04-22 11:12:45 -04:00
(function () {
'use strict';
var ID = 'core/location';
var DEPS = ['_', 'modernizr', 'core/event', 'core/notify', 'core/settings'];
describe('module "' + ID + '"', function () {
before(function () {
this.definition = modulejs._private.definitions[ID];
this.xModernizr = {
history: true
};
this.xSettings = {
smartBrowsing: true,
unmanagedInNewWindow: true
};
this.xEvent = {
pub: sinon.stub(),
sub: sinon.stub()
};
this.xNotify = {
set: sinon.stub()
};
this.applyFn = function () {
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xNotify, 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 7 properties', function () {
var instance = this.applyFn();
assert.isPlainObject(instance);
assert.lengthOfKeys(instance, 7);
});
});
2015-04-22 13:34:35 -04:00
describe('.forceEncoding()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.forceEncoding);
2015-04-22 11:12:45 -04:00
});
2015-04-22 15:30:29 -04: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];
it('.forceEncoding("' + arg + '") => "' + exp + '"', function () {
var instance = this.applyFn();
assert.strictEqual(instance.forceEncoding(arg), exp);
});
});
2015-04-22 13:34:35 -04:00
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
describe('.getDomain()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.getDomain);
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('returns document.domain', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
2015-04-22 15:30:29 -04:00
assert.strictEqual(instance.getDomain(), window.document.domain);
2015-04-22 11:12:45 -04:00
});
2015-04-22 13:34:35 -04:00
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
describe('.getAbsHref()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.getAbsHref);
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('returns null before .setLocation()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isNull(instance.getAbsHref());
2015-04-22 11:12:45 -04:00
});
2015-04-22 13:34:35 -04:00
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
describe('.getItem()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.getItem);
2015-04-22 11:12:45 -04:00
});
2015-04-22 13:34:35 -04:00
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
describe('.setLocation()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.setLocation);
2015-04-22 11:12:45 -04:00
});
2015-04-22 13:34:35 -04:00
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
describe('.refresh()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.refresh);
2015-04-22 11:12:45 -04:00
});
2015-04-22 13:34:35 -04:00
});
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
describe('.setLink()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
var instance = this.applyFn();
assert.isFunction(instance.setLink);
2015-04-22 11:12:45 -04:00
});
2015-04-22 15:30:29 -04: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);
});
it('sets target="_blank" for unmanaged folders', function () {
this.xSettings.unmanagedInNewWindow = true;
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');
});
it('does not set target="_blank" for managed folders', function () {
this.xSettings.unmanagedInNewWindow = true;
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'));
});
it('does not set target="_blank" for unmanaged folders if disabled', function () {
this.xSettings.unmanagedInNewWindow = false;
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 11:12:45 -04:00
});
});
}());