Update of multiple frontend libs.
This commit is contained in:
parent
de261dbde5
commit
a9c6ddc03b
276 changed files with 41257 additions and 19300 deletions
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function(QUnit) {
|
||||
|
||||
var router = null;
|
||||
var location = null;
|
||||
|
@ -28,7 +28,8 @@
|
|||
'fragment',
|
||||
'pathname',
|
||||
'protocol'
|
||||
));
|
||||
));
|
||||
|
||||
// In IE, anchor.pathname does not contain a leading slash though
|
||||
// window.location.pathname does.
|
||||
if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
|
||||
|
@ -42,7 +43,7 @@
|
|||
|
||||
QUnit.module('Backbone.Router', {
|
||||
|
||||
setup: function() {
|
||||
beforeEach: function() {
|
||||
location = new Location('http://example.com');
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
router = new Router({testing: 101});
|
||||
|
@ -53,7 +54,7 @@
|
|||
Backbone.history.on('route', onRoute);
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
Backbone.history.stop();
|
||||
Backbone.history.off('route', onRoute);
|
||||
}
|
||||
|
@ -95,6 +96,10 @@
|
|||
'*anything': 'anything'
|
||||
},
|
||||
|
||||
preinitialize: function(options) {
|
||||
this.testpreinit = 'foo';
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
this.testing = options.testing;
|
||||
this.route('implicit', 'implicit');
|
||||
|
@ -121,19 +126,19 @@
|
|||
this.charType = 'escaped';
|
||||
},
|
||||
|
||||
contacts: function(){
|
||||
contacts: function() {
|
||||
this.contact = 'index';
|
||||
},
|
||||
|
||||
newContact: function(){
|
||||
newContact: function() {
|
||||
this.contact = 'new';
|
||||
},
|
||||
|
||||
loadContact: function(){
|
||||
loadContact: function() {
|
||||
this.contact = 'load';
|
||||
},
|
||||
|
||||
optionalItem: function(arg){
|
||||
optionalItem: function(arg) {
|
||||
this.arg = arg !== void 0 ? arg : null;
|
||||
},
|
||||
|
||||
|
@ -181,6 +186,11 @@
|
|||
assert.equal(router.testing, 101);
|
||||
});
|
||||
|
||||
QUnit.test('preinitialize', function(assert) {
|
||||
assert.expect(1);
|
||||
assert.equal(router.testpreinit, 'foo');
|
||||
});
|
||||
|
||||
QUnit.test('routes (simple)', function(assert) {
|
||||
assert.expect(4);
|
||||
location.replace('http://example.com#search/news');
|
||||
|
@ -234,10 +244,11 @@
|
|||
assert.ok(Backbone.history.navigate('search/manhattan/p20', true));
|
||||
});
|
||||
|
||||
QUnit.test('route precedence via navigate', function(assert){
|
||||
QUnit.test('route precedence via navigate', function(assert) {
|
||||
assert.expect(6);
|
||||
// check both 0.9.x and backwards-compatibility options
|
||||
_.each([{trigger: true}, true], function( options ){
|
||||
|
||||
// Check both 0.9.x and backwards-compatibility options
|
||||
_.each([{trigger: true}, true], function(options) {
|
||||
Backbone.history.navigate('contacts', options);
|
||||
assert.equal(router.contact, 'index');
|
||||
Backbone.history.navigate('contacts/new', options);
|
||||
|
@ -249,7 +260,7 @@
|
|||
|
||||
QUnit.test('loadUrl is not called for identical routes.', function(assert) {
|
||||
assert.expect(0);
|
||||
Backbone.history.loadUrl = function(){ assert.ok(false); };
|
||||
Backbone.history.loadUrl = function() { assert.ok(false); };
|
||||
location.replace('http://example.com#route');
|
||||
Backbone.history.navigate('route');
|
||||
Backbone.history.navigate('/route');
|
||||
|
@ -345,9 +356,9 @@
|
|||
assert.strictEqual(router.path, 'c/d/e');
|
||||
});
|
||||
|
||||
QUnit.test("fires event when router doesn't have callback on it", function(assert) {
|
||||
QUnit.test('fires event when router doesn\'t have callback on it', function(assert) {
|
||||
assert.expect(1);
|
||||
router.on('route:noCallback', function(){ assert.ok(true); });
|
||||
router.on('route:noCallback', function() { assert.ok(true); });
|
||||
location.replace('http://example.com#noCallback');
|
||||
Backbone.history.checkUrl();
|
||||
});
|
||||
|
@ -536,8 +547,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
pushState: function() {},
|
||||
replaceState: function() {}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({root: 'root'});
|
||||
|
@ -551,8 +562,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(state, title, url){
|
||||
pushState: function() {},
|
||||
replaceState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root/x/y');
|
||||
}
|
||||
}
|
||||
|
@ -570,8 +581,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
pushState: function() {},
|
||||
replaceState: function() {}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({root: ''});
|
||||
|
@ -625,8 +636,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(state, title, url){
|
||||
pushState: function() {},
|
||||
replaceState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root/x/y?a=b');
|
||||
}
|
||||
}
|
||||
|
@ -641,8 +652,8 @@
|
|||
assert.expect(1);
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {'': 'empty'},
|
||||
empty: function(){},
|
||||
route: function(route){
|
||||
empty: function() {},
|
||||
route: function(route) {
|
||||
assert.strictEqual(route, '');
|
||||
}
|
||||
});
|
||||
|
@ -655,7 +666,8 @@
|
|||
assert.strictEqual(history.getFragment('fragment '), 'fragment');
|
||||
});
|
||||
|
||||
QUnit.test('#1820 - Leading slash and trailing space.', 1, function(assert) {
|
||||
QUnit.test('#1820 - Leading slash and trailing space.', function(assert) {
|
||||
assert.expect(1);
|
||||
var history = new Backbone.History;
|
||||
assert.strictEqual(history.getFragment('/fragment '), 'fragment');
|
||||
});
|
||||
|
@ -670,7 +682,7 @@
|
|||
assert.strictEqual(router.z, '123');
|
||||
});
|
||||
|
||||
QUnit.test("#2062 - Trigger 'route' event on router instance.", function(assert) {
|
||||
QUnit.test('#2062 - Trigger "route" event on router instance.', function(assert) {
|
||||
assert.expect(2);
|
||||
router.on('route', function(name, args) {
|
||||
assert.strictEqual(name, 'routeEvent');
|
||||
|
@ -709,8 +721,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){ assert.ok(false); }
|
||||
pushState: function() {},
|
||||
replaceState: function() { assert.ok(false); }
|
||||
}
|
||||
});
|
||||
Backbone.history.start({
|
||||
|
@ -726,8 +738,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
pushState: function() {},
|
||||
replaceState: function() {}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -753,7 +765,7 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(state, title, url){
|
||||
pushState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root');
|
||||
}
|
||||
}
|
||||
|
@ -785,7 +797,7 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(state, title, url){
|
||||
pushState: function(state, title, url) {
|
||||
assert.strictEqual(url, '/root?x=1');
|
||||
}
|
||||
}
|
||||
|
@ -823,7 +835,7 @@
|
|||
assert.expect(1);
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
path: function(params){
|
||||
path: function(params) {
|
||||
assert.strictEqual(params, 'x=y%3Fz');
|
||||
}
|
||||
}
|
||||
|
@ -921,7 +933,7 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {'foo/:id/bar': 'foo'},
|
||||
foo: function(){},
|
||||
foo: function() {},
|
||||
execute: function(callback, args, name) {
|
||||
assert.strictEqual(callback, this.foo);
|
||||
assert.deepEqual(args, ['123', 'x=y']);
|
||||
|
@ -953,8 +965,8 @@
|
|||
Backbone.history = _.extend(new Backbone.History, {
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){ assert.ok(false); },
|
||||
replaceState: function(){ assert.ok(false); }
|
||||
pushState: function() { assert.ok(false); },
|
||||
replaceState: function() { assert.ok(false); }
|
||||
}
|
||||
});
|
||||
Backbone.history.start({pushState: true});
|
||||
|
@ -991,14 +1003,14 @@
|
|||
Backbone.history.start({root: '/root', pushState: true});
|
||||
});
|
||||
|
||||
QUnit.test("Paths that don't match the root should not match no root", function(assert) {
|
||||
QUnit.test('Paths that don\'t match the root should not match no root', function(assert) {
|
||||
assert.expect(0);
|
||||
location.replace('http://example.com/foo');
|
||||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
foo: function(){
|
||||
foo: function() {
|
||||
assert.ok(false, 'should not match unless root matches');
|
||||
}
|
||||
}
|
||||
|
@ -1007,14 +1019,14 @@
|
|||
Backbone.history.start({root: 'root', pushState: true});
|
||||
});
|
||||
|
||||
QUnit.test("Paths that don't match the root should not match roots of the same length", function(assert) {
|
||||
QUnit.test('Paths that don\'t match the root should not match roots of the same length', function(assert) {
|
||||
assert.expect(0);
|
||||
location.replace('http://example.com/xxxx/foo');
|
||||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
foo: function(){
|
||||
foo: function() {
|
||||
assert.ok(false, 'should not match unless root matches');
|
||||
}
|
||||
}
|
||||
|
@ -1029,7 +1041,7 @@
|
|||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {foo: function(){ assert.ok(true); }}
|
||||
routes: {foo: function() { assert.ok(true); }}
|
||||
});
|
||||
var myRouter = new MyRouter;
|
||||
Backbone.history.start({root: 'x+y.z', pushState: true});
|
||||
|
@ -1041,7 +1053,7 @@
|
|||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {foo: function(){ assert.ok(true); }}
|
||||
routes: {foo: function() { assert.ok(true); }}
|
||||
});
|
||||
var myRouter = new MyRouter;
|
||||
Backbone.history.start({root: '®ooτ', pushState: true});
|
||||
|
@ -1053,10 +1065,17 @@
|
|||
Backbone.history.stop();
|
||||
Backbone.history = _.extend(new Backbone.History, {location: location});
|
||||
var MyRouter = Backbone.Router.extend({
|
||||
routes: {'': function(){ assert.ok(true); }}
|
||||
routes: {'': function() { assert.ok(true); }}
|
||||
});
|
||||
var myRouter = new MyRouter;
|
||||
Backbone.history.start({root: '®ooτ', pushState: true});
|
||||
});
|
||||
|
||||
})();
|
||||
QUnit.test('#4025 - navigate updates URL hash as is', function(assert) {
|
||||
assert.expect(1);
|
||||
var route = 'search/has%20space';
|
||||
Backbone.history.navigate(route);
|
||||
assert.strictEqual(location.hash, '#' + route);
|
||||
});
|
||||
|
||||
})(QUnit);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue