can-route
Advanced tools
Comparing version 4.3.9 to 4.3.10
{ | ||
"name": "can-route", | ||
"version": "4.3.9", | ||
"version": "4.3.10", | ||
"description": "Observable front-end application routing for CanJS.", | ||
@@ -66,3 +66,3 @@ "homepage": "https://canjs.com/doc/can-route.html", | ||
"jshint": "^2.9.1", | ||
"steal": "^1.2.9", | ||
"steal": "^2.0.0", | ||
"steal-qunit": "^1.0.1", | ||
@@ -69,0 +69,0 @@ "steal-tools": "^1.1.2", |
@@ -7,2 +7,4 @@ /* jshint asi:true */ | ||
var canReflect = require('can-reflect'); | ||
var stacheKey = require("can-stache-key"); | ||
var Observation = require("can-observation"); | ||
@@ -99,21 +101,23 @@ var mockRoute = require("./mock-route-binding"); | ||
test("canRoute.map: conflicting route values, hash should win (canjs/canjs#979)", function(){ | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
iCanRoute.register("{type}/{id}"); | ||
var AppState = DefineMap.extend({seal: false},{}); | ||
var appState = new AppState({type: "dog", id: '4'}); | ||
QUnit.asyncTest("canRoute.map: conflicting route values, hash should win (canjs/canjs#979)", function(){ | ||
mockRoute.start(); | ||
iCanRoute.data = appState; | ||
iCanRoute._onStartComplete = function () { | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!cat/5", "same URL"); | ||
equal(appState.get("type"), "cat", "conflicts should be won by the URL"); | ||
equal(appState.get("id"), "5", "conflicts should be won by the URL"); | ||
teardownRouteTest(); | ||
}; | ||
canRoute.register("{type}/{id}"); | ||
var AppState = DefineMap.extend({seal: false},{}); | ||
var appState = new AppState({type: "dog", id: '4'}); | ||
loc.hash = "#!cat/5"; | ||
iCanRoute.start(); | ||
}); | ||
canRoute.data = appState; | ||
canRoute._onStartComplete = function () { | ||
var after = mockRoute.hash.get(); | ||
equal(after, "cat/5", "same URL"); | ||
equal(appState.get("type"), "cat", "conflicts should be won by the URL"); | ||
equal(appState.get("id"), "5", "conflicts should be won by the URL"); | ||
QUnit.start(); | ||
mockRoute.stop(); | ||
}; | ||
mockRoute.hash.value = "#!cat/5"; | ||
canRoute.start(); | ||
}); | ||
@@ -221,92 +225,93 @@ | ||
test("canRoute.current is live-bindable (#1156)", function () { | ||
setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
iCanRoute.start(); | ||
var isOnTestPage = new win.Observation(function(){ | ||
return iCanRoute.isCurrent({page: "test"}); | ||
}); | ||
QUnit.asyncTest("canRoute.current is live-bindable (#1156)", function () { | ||
mockRoute.start(); | ||
win.canReflect.onValue(isOnTestPage, function(){ | ||
teardownRouteTest(); | ||
}); | ||
equal(iCanRoute.isCurrent({page: "test"}), false, "initially not on test page") | ||
setTimeout(function(){ | ||
iCanRoute.attr("page","test"); | ||
},20); | ||
canRoute.start(); | ||
var isOnTestPage = new Observation(function(){ | ||
return canRoute.isCurrent({page: "test"}); | ||
}); | ||
canReflect.onValue(isOnTestPage, function(){ | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
}); | ||
equal(canRoute.isCurrent({page: "test"}), false, "initially not on test page") | ||
setTimeout(function(){ | ||
canRoute.attr("page","test"); | ||
},20); | ||
}); | ||
test("can.compute.read should not call canRoute (#1154)", function () { | ||
setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
iCanRoute.attr("page","test"); | ||
iCanRoute.start(); | ||
QUnit.asyncTest("can.compute.read should not call canRoute (#1154)", function () { | ||
mockRoute.start(); | ||
canRoute.attr("page","test"); | ||
canRoute.start(); | ||
var val = win.observeReader.read({route: iCanRoute},win.observeReader.reads("route")).value; | ||
var val = stacheKey.read({route: canRoute},stacheKey.reads("route")).value; | ||
setTimeout(function(){ | ||
equal(val,iCanRoute,"read correctly"); | ||
teardownRouteTest(); | ||
},1); | ||
}); | ||
setTimeout(function(){ | ||
equal(val,canRoute,"read correctly"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
},1); | ||
}); | ||
test("routes should deep clean", function() { | ||
QUnit.asyncTest("routes should deep clean", function() { | ||
expect(2); | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
var hash1 = canRoute.url({ | ||
panelA: { | ||
name: "fruit", | ||
id: 15, | ||
show: true | ||
} | ||
}); | ||
var hash2 = canRoute.url({ | ||
panelA: { | ||
name: "fruit", | ||
id: 20, | ||
read: false | ||
} | ||
}); | ||
mockRoute.start(); | ||
loc.hash = hash1; | ||
var hash1 = canRoute.url({ | ||
panelA: { | ||
name: "fruit", | ||
id: 15, | ||
show: true | ||
} | ||
}); | ||
var hash2 = canRoute.url({ | ||
panelA: { | ||
name: "fruit", | ||
id: 20, | ||
read: false | ||
} | ||
}); | ||
mockRoute.hash.value = hash1; | ||
mockRoute.hash.value = hash2; | ||
loc.hash = hash2; | ||
iCanRoute._onStartComplete = function() { | ||
equal(iCanRoute.data.get('panelA').id, 20, "id should change"); | ||
equal(iCanRoute.data.get('panelA').show, undefined, "show should be removed"); | ||
canRoute._onStartComplete = function() { | ||
equal(canRoute.data.get('panelA').id, 20, "id should change"); | ||
equal(canRoute.data.get('panelA').show, undefined, "show should be removed"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
}; | ||
teardownRouteTest(); | ||
}; | ||
iCanRoute.start(); | ||
}); | ||
canRoute.start(); | ||
}); | ||
test("updating bound DefineMap causes single update with a coerced string value", function() { | ||
QUnit.asyncTest("updating bound DefineMap causes single update with a coerced string value", function() { | ||
expect(1); | ||
setupRouteTest(function (iframe, route) { | ||
var MyMap = DefineMap.extend({seal: false},{'*': "stringOrObservable"}); | ||
var appVM = new MyMap(); | ||
canRoute.start(); | ||
var MyMap = DefineMap.extend({seal: false},{'*': "stringOrObservable"}); | ||
var appVM = new MyMap(); | ||
route.data = appVM; | ||
canRoute.data = appVM; | ||
route._onStartComplete = function(){ | ||
appVM.bind('action', function(ev, newVal) { | ||
strictEqual(newVal, '10'); | ||
}); | ||
canRoute._onStartComplete = function(){ | ||
appVM.on('action', function(ev, newVal) { | ||
strictEqual(newVal, '10'); | ||
}); | ||
appVM.set('action', 10); | ||
appVM.set('action', 10); | ||
// check after 30ms to see that we only have a single call | ||
setTimeout(function() { | ||
teardownRouteTest(); | ||
}, 5); | ||
}; | ||
route.start(); | ||
}); | ||
// check after 30ms to see that we only have a single call | ||
setTimeout(function() { | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
}, 5); | ||
}; | ||
canRoute.start(); | ||
}); | ||
@@ -396,74 +401,63 @@ | ||
if (typeof require === 'undefined') { | ||
if (typeof require !== 'undefined') { | ||
test("correct stringing", function () { | ||
setupRouteTest(function(iframe, route) { | ||
route.routes = {}; | ||
mockRoute.start(); | ||
route.attr('number', 1); | ||
propEqual(route.attr(), { | ||
'number': "1" | ||
}); | ||
canRoute.routes = {}; | ||
route.attr({ | ||
bool: true | ||
}, true); | ||
canRoute.attr({ | ||
number: 1, | ||
bool: true, | ||
string: "hello", | ||
array: [1, true, "hello"] | ||
}); | ||
propEqual(route.attr(), { | ||
'bool': "true" | ||
}); | ||
QUnit.deepEqual(canRoute.attr(),{ | ||
number: "1", | ||
bool: "true", | ||
string: "hello", | ||
array: ["1", "true", "hello"] | ||
}); | ||
canReflect.update(canRoute.data, {}); | ||
route.attr({ | ||
string: "hello" | ||
}, true); | ||
propEqual(route.attr(), { | ||
'string': "hello" | ||
}); | ||
canRoute.attr({ | ||
number: 1, | ||
bool: true, | ||
string: "hello", | ||
array: [2, false, "world"], | ||
obj: { | ||
number: 3, | ||
array: [4, true] | ||
} | ||
}); | ||
route.attr({ | ||
array: [1, true, "hello"] | ||
}, true); | ||
propEqual(route.attr(), { | ||
'array': ["1", "true", "hello"] | ||
}); | ||
QUnit.deepEqual(canRoute.attr(), { | ||
number: "1", | ||
bool: "true", | ||
string: "hello", | ||
array: ["2", "false", "world"], | ||
obj: { | ||
number: "3", | ||
array: ["4", "true"] | ||
} | ||
}, "nested object"); | ||
route.attr({ | ||
number: 1, | ||
bool: true, | ||
string: "hello", | ||
array: [2, false, "world"], | ||
obj: { | ||
number: 3, | ||
array: [4, true] | ||
} | ||
}, true); | ||
canRoute.routes = {}; | ||
canRoute.register("{type}/{id}"); | ||
propEqual(route.attr(), { | ||
number: "1", | ||
bool: "true", | ||
string: "hello", | ||
array: ["2", "false", "world"], | ||
obj: { | ||
number: "3", | ||
array: ["4", "true"] | ||
} | ||
}); | ||
canReflect.update(canRoute.data, {}); | ||
route.routes = {}; | ||
route.register("{type}/{id}"); | ||
canRoute.attr({ | ||
type: 'page', | ||
id: 10, | ||
sort_by_name: true | ||
}); | ||
route.attr({ | ||
type: 'page', | ||
id: 10, | ||
sort_by_name: true | ||
}, true); | ||
propEqual(canRoute.attr(), { | ||
type: "page", | ||
id: "10", | ||
sort_by_name: "true" | ||
}); | ||
propEqual(route.attr(), { | ||
type: "page", | ||
id: "10", | ||
sort_by_name: "true" | ||
}); | ||
teardownRouteTest(); | ||
}); | ||
}); | ||
@@ -470,0 +464,0 @@ |
@@ -127,24 +127,2 @@ /* jshint asi:true */ | ||
test("canRoute.map: conflicting route values, hash should win", function(){ | ||
setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
iCanRoute.register("{type}/{id}"); | ||
var AppState = win.CanMap.extend(); | ||
var appState = new AppState({type: "dog", id: '4'}); | ||
iCanRoute.data = appState; | ||
iCanRoute._onStartComplete = function () { | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!cat/5", "same URL"); | ||
equal(appState.attr("type"), "cat", "conflicts should be won by the URL"); | ||
equal(appState.attr("id"), "5", "conflicts should be won by the URL"); | ||
teardownRouteTest(); | ||
}; | ||
loc.hash = "#!cat/5"; | ||
iCanRoute.start(); | ||
}); | ||
}); | ||
test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data", function(){ | ||
@@ -255,34 +233,2 @@ setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
test("routes should deep clean", function() { | ||
expect(2); | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
iCanRoute._onStartComplete = function() { | ||
equal(iCanRoute.attr("panelA.id"), 20, "id should change"); | ||
equal(iCanRoute.attr("panelA.show"), undefined, "show should be removed"); | ||
teardownRouteTest(); | ||
}; | ||
iCanRoute.start(); | ||
var hash1 = canRoute.url({ | ||
panelA: { | ||
name: "fruit", | ||
id: 15, | ||
show: true | ||
} | ||
}); | ||
var hash2 = canRoute.url({ | ||
panelA: { | ||
name: "fruit", | ||
id: 20, | ||
read: false | ||
} | ||
}); | ||
loc.hash = hash1; | ||
loc.hash = hash2; | ||
}); | ||
}); | ||
test("updating bound SimpleMap causes single update with a coerced string value", function() { | ||
@@ -289,0 +235,0 @@ expect(1); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109818
2535