Skip to content

Commit

Permalink
adds can.route tests, some are breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Apr 18, 2012
1 parent efef399 commit 7fe391f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
4 changes: 2 additions & 2 deletions route/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h2>Events</h2>
routesEl.empty();

// draw routes
routes.each(function(i, route){
routes.each(function(route){
// setup an Observer
// <a href='javascript://' class='destroy'>X</a>
var pre = $("<li><pre></pre>")
Expand Down Expand Up @@ -164,7 +164,7 @@ <h2>Events</h2>

var change = function(){
can.route.routes = {};
routes.each(function(i, route){
routes.each(function(route){
var r = route.attr()
can.route(r.route, r.def )
})
Expand Down
1 change: 1 addition & 0 deletions route/qunit.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ <h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-test-area"></div>
<script type='text/javascript' src='../../steal/steal.js'></script>
<script type='text/javascript'>
steal('can/route','funcunit/qunit').then('can/route/route_test.js')
Expand Down
11 changes: 7 additions & 4 deletions route/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ steal('can/observe', 'can/util/string/deparam', function() {
// Converts a JS Object into a list of parameters that can be
// inserted into an html element tag.
makeProps = function( props ) {
return can.map(props, function( val, name ) {
return ( name === 'className' ? 'class' : name )+ '="' + can.esc(val) + '"';
}).join(" ");
var tags = [];
can.each(props, function(val, name){
tags.push( ( name === 'className' ? 'class' : name )+ '="' +
(name === "href" ? val : can.esc(val) ) + '"');
});
return tags.join(" ");
},
// Checks if a route matches the data provided. If any route variable
// is not present in the data, the route does not match. If all route
Expand Down Expand Up @@ -376,7 +379,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
// Deparameterizes the portion of the hash of interest and assign the
// values to the `can.route.data` removing existing values no longer in the hash.
setState = function() {
curParams = can.route.deparam( location.hash.split(/#!?/).pop() || "" );
curParams = can.route.deparam( location.href.split(/#!?/)[1] || "" );
can.route.attr(curParams, true);
};

Expand Down
33 changes: 30 additions & 3 deletions route/route_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ test("linkTo", function(){
can.route.routes = {};
can.route(":foo");
var res = can.route.link("Hello",{foo: "bar", baz: 'foo'});
equal( res, '<a href="#!bar&baz=foo" >Hello</a>');
equal( res, '<a href="#!bar&baz=foo">Hello</a>');
})

/*
test("param with route defined", function(){
can.route.routes = {};
can.route("holler")
Expand All @@ -250,7 +250,7 @@ test("param with route defined", function(){
var res = can.route.param({foo: "abc",route: "foo"});
equal(res, "foo&foo=abc")
})
})*/

test("route endings", function(){
can.route.routes = {};
Expand All @@ -262,4 +262,31 @@ test("route endings", function(){

})

test("strange characters", function(){
can.route.routes = {};
can.route(":type/:id");
var res = can.route.deparam("foo/"+encodeURIComponent("\/"))
equal(res.id, "\/")
res = can.route.param({type: "bar", id: "\/"});
equal(res, "bar/"+encodeURIComponent("\/"))
});

test("updating the hash", function(){
stop();
window.routeTestReady = function(iCanRoute, loc){
iCanRoute(":type/:id")
iCanRoute.attr({type: "bar", id: "\/"})

setTimeout(function(){
var after = loc.href.substr(loc.href.indexOf("#"));
equal(after,"#!bar/"+encodeURIComponent("\/"))
start();

},30)
}
var iframe = document.createElement('iframe');
iframe.src = steal.root.join("can/route/testing.html")
can.$("#qunit-test-area")[0].appendChild(iframe)
})


3 changes: 2 additions & 1 deletion test/can_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ steal('./setup.js')
.then('can/view/view_test.js')
.then('can/control/control_test.js')
.then('can/model/model_test.js')
.then('can/view/ejs/ejs_test.js')
.then('can/view/ejs/ejs_test.js')
.then('can/route/route_test.js')
2 changes: 1 addition & 1 deletion util/demos/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function(){


var children = $()
value.each(function(name, val){
value.each(function(val, name){
var section = self.draw(indent+1, /*isList ? undefined :*/ name, val);
children.push(section);
})
Expand Down
2 changes: 1 addition & 1 deletion util/zepto/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ can.$ = Zepto
can.isEmptyObject = function(object){
var name;
for(name in object){};
return name !== undefined;
return name === undefined;
}

// Make extend handle `true` for deep.
Expand Down

0 comments on commit 7fe391f

Please sign in to comment.