pjax-test.js revision 966da8f301a2247df62862717f672f40644a2093
/*
These tests test Y.Plugin.Pjax, since it sits at the top of a stack that
includes Y.PjaxBase and Y.Pjax, giving us full coverage of all three.
Note: These tests should ideally be run from an HTTP URL. If run from the local
filesystem, the tests that require XHR will be skipped.
*/
// Tests that require XHR are ignored when the protocol isn't http or https,
// since the XHR requests will fail.
function resetURL() {
if (html5) {
}
}
// -- Suite --------------------------------------------------------------------
name: 'Pjax',
setUp: function () {
resetURL();
},
tearDown: function () {
resetURL();
}
});
// -- Lifecycle ----------------------------------------------------------------
name: 'Lifecycle',
setUp: function () {
},
tearDown: function () {
delete this.node;
},
'should plug into a Node instance': function () {
}
}));
// -- Attributes and Properties ------------------------------------------------
name: 'Attributes and Properties',
_should: {
ignore: {
'Pjax param should be appended to an existing query string when `addPjaxParam` is true': disableXHR || !html5,
}
},
setUp: function () {
},
tearDown: function () {
resetURL();
delete this.node;
delete this.pjax;
},
'`addPjaxParam` should be true by default': function () {
},
'Pjax param should be added when `addPjaxParam` is true': function () {
var test = this;
e.preventDefault();
});
});
this.wait(1000);
},
'Pjax param should be appended to an existing query string when `addPjaxParam` is true': function () {
var test = this;
e.preventDefault();
});
});
this.wait(1000);
},
'Pjax param should not be added when `addPjaxParam` is false': function () {
var test = this;
e.preventDefault();
});
});
this.wait(1000);
},
'`container` should be null by default': function () {
},
'container` should always be `null` or a Node instance': function () {
},
'`contentSelector` should be null by default': function () {
},
'`linkSelector` should select links with class "yui3-pjax" by default': function () {
},
'`scrollToTop` should be true by default': function () {
},
'`timeout` should default to 30000ms': function () {
},
'`titleSelector` should select the title tag by default': function () {
}
}));
// -- Events -------------------------------------------------------------------
name: 'Events',
_should: {
ignore: {
'`navigate` event should fire when a pjax link is clicked': !html5,
'`navigate` event should be preventable': !html5,
'`navigate` event should not fire when a link is clicked with a button other than the left button': !html5,
'`navigate` event should not fire when a modifier key is pressed': !html5
}
},
setUp: function () {
},
tearDown: function () {
resetURL();
delete this.node;
delete this.pjax;
delete this.oldPath;
},
'should attach events on init in HTML5 browsers': function () {
if (html5) {
} else {
}
},
'`error` event should fire on Ajax failure': function () {
var test = this;
});
});
this.wait(1000);
},
'`error` event should be preventable': function () {
this.pjax._defCompletefn = function () {
};
e.preventDefault();
});
},
'`load` event should fire on Ajax success': function () {
var test = this;
e.preventDefault();
Assert.isTrue(/\/assets\/page-full\.html\?pjax=1$/.test(e.url), 'URL should be passed on the event facade.');
});
});
this.wait(1000);
},
'`load` event should be preventable': function () {
this.pjax._defCompleteFn = function () {
};
e.preventDefault();
});
},
'`navigate` event facade should contain the options passed to `navigate()`': function () {
var called = 0,
options = {
title: 'Bogus Page'
},
called++;
});
},
'`navigate` event should fire when a pjax link is clicked': function () {
var event = {
button : 1,
preventDefault: function () {}
},
called = 1;
e.preventDefault();
});
// Fake click event.
},
'`navigate` event should be preventable': function () {
var called;
e.preventDefault();
});
// Fake click event.
this.pjax._onLinkClick({
button : 1,
preventDefault: function () {
called = 1;
}
});
},
'`navigate` event should not fire when a link is clicked with a button other than the left button': function () {
});
// Fake click event.
this.pjax._onLinkClick({
button : 2,
preventDefault: function () {}
});
},
'`navigate` event should not fire when a modifier key is pressed': function () {
});
// Fake click event.
this.pjax._onLinkClick({
button : 1,
ctrlKey : true,
preventDefault: function () {}
});
this.pjax._onLinkClick({
button : 1,
metaKey : true,
preventDefault: function () {}
});
}
}));
// -- Methods ------------------------------------------------------------------
name: 'Methods',
_should: {
ignore: {
},
error: {
'`navigate()` should throw an error when the specified URL is not of the same origin': true
}
},
setUp: function () {
},
tearDown: function () {
resetURL();
delete this.node;
delete this.pjax;
delete this.oldPath;
},
'`navigate()` should load the specified URL and fire a `load` event': function () {
var test = this,
e.preventDefault();
});
this.wait(1000);
},
'`navigate()` should normalize the specified URL': function () {
var test = this,
calls = 0;
// Browser normalizes anchor href URLs.
force : true,
});
}
e.preventDefault();
calls += 1;
});
navigate('assets/../assets/page-full.html');
navigate('/');
// navigate(''); // IE6 has an issue with this...
navigate('/foo/../');
navigate('/foo/..');
},
'`navigate()` should throw an error when the specified URL is not of the same origin': function () {
var didNavigate;
}
}));
// -- General Behavior ---------------------------------------------------------
name: 'General Behavior',
_should: {
ignore: {
'Page title should be updated if the `titleSelector` matches an element': disableXHR || !Y.config.doc || !html5,
'Host element content should be updated with page content when `contentSelector` is null': disableXHR || !html5,
'Host element content should be updated with partial content when `contentSelector` selects a node': disableXHR || !html5
}
},
setUp: function () {
},
tearDown: function () {
resetURL();
delete this.node;
delete this.pjax;
delete this.oldPath;
},
'Page title should be updated if the `titleSelector` matches an element': function () {
var test = this;
});
});
this.wait(1000);
},
'Host element content should be updated with page content when `contentSelector` is null': function () {
var test = this;
});
});
this.wait(1000);
},
'Host element content should be updated with partial content when `contentSelector` selects a node': function () {
var test = this;
});
});
this.wait(1000);
}
}));
}, '@VERSION@', {
});