Adds onpopstate tests.

This commit is contained in:
Lars Jung 2015-04-29 00:39:22 +02:00
parent 344c61bd23
commit 2525ad8393

View file

@ -13,10 +13,10 @@ describe('module \'' + ID + '\'', function () {
this.xModernizr = { this.xModernizr = {
history: true history: true
}; };
this.xSettings = { this.xSettings = {view: {
smartBrowsing: true, fastBrowsing: true,
unmanagedInNewWindow: true unmanagedInNewWindow: true
}; }};
this.xEvent = { this.xEvent = {
pub: sinon.stub(), pub: sinon.stub(),
sub: sinon.stub() sub: sinon.stub()
@ -26,10 +26,24 @@ describe('module \'' + ID + '\'', function () {
}; };
this.applyFn = function () { this.applyFn = function () {
this.xEvent.pub.reset();
this.xEvent.sub.reset();
this.xNotify.set.reset();
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xNotify, this.xSettings); return this.definition.fn(_, this.xModernizr, this.xEvent, this.xNotify, this.xSettings);
}; };
}); });
after(function () {
window.onpopstate = null;
});
beforeEach(function () {
window.onpopstate = null;
});
describe('definition', function () { describe('definition', function () {
it('is defined', function () { it('is defined', function () {
@ -71,6 +85,46 @@ describe('module \'' + ID + '\'', function () {
assert.isPlainObject(instance); assert.isPlainObject(instance);
assert.lengthOfKeys(instance, 7); assert.lengthOfKeys(instance, 7);
}); });
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);
});
}); });
describe('.forceEncoding()', function () { describe('.forceEncoding()', function () {
@ -201,7 +255,7 @@ describe('module \'' + ID + '\'', function () {
it('sets target=\'_blank\' for unmanaged folders', function () { it('sets target=\'_blank\' for unmanaged folders', function () {
this.xSettings.unmanagedInNewWindow = true; this.xSettings.view.unmanagedInNewWindow = true;
var $el = $('<a/>'); var $el = $('<a/>');
var item = { var item = {
@ -218,7 +272,7 @@ describe('module \'' + ID + '\'', function () {
it('does not set target=\'_blank\' for managed folders', function () { it('does not set target=\'_blank\' for managed folders', function () {
this.xSettings.unmanagedInNewWindow = true; this.xSettings.view.unmanagedInNewWindow = true;
var $el = $('<a/>'); var $el = $('<a/>');
var item = { var item = {
@ -235,7 +289,7 @@ describe('module \'' + ID + '\'', function () {
it('does not set target=\'_blank\' for unmanaged folders if disabled', function () { it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
this.xSettings.unmanagedInNewWindow = false; this.xSettings.view.unmanagedInNewWindow = false;
var $el = $('<a/>'); var $el = $('<a/>');
var item = { var item = {