Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Fix various problems found when put into use
Browse files Browse the repository at this point in the history
Incorrectly detecting query params with no content
Incorrectly handling params update where all params are zero length
  • Loading branch information
akc42 committed Oct 5, 2016
1 parent 10f0cf4 commit 2845af0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion akc-location.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
} else {
newUrl = window.encodeURI(path).replace(/\#/g, '%23').replace(/\?/g, '%3F');
}
if (query) {
if (query && Object.keys(query).length > 0) {
this.__query = query;
newUrl += '?' + this.__queryString.replace(/\#/g, '%23');

Expand Down
8 changes: 4 additions & 4 deletions akc-route.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/
inRoute: {
type: Object,
value: function() {return {};},
value: function() {return {path: '', active: false, params: {}, query: {}};},
notify:true
},
/**
Expand Down Expand Up @@ -92,7 +92,7 @@
*/
outRoute: {
type: Object,
value: function() {return {};},
value: function() {return {path: '', active: false, params: {}, query: {}};},
notify: true
}
},
Expand Down Expand Up @@ -208,11 +208,11 @@
}
path += '/' + params[key].toString();
} else {
path += '/' + matchePieces[i];
path += '/' + matchedPieces[i];
}
}
}
if (this.outRoute.path.length > 1 && this.outRoute.active) {
if (path.length > 1 && this.outRoute.path.length > 1 && this.outRoute.active) {
path += this.outRoute.path; //only do this if the outpath was really there
}
if (path !== this.inRoute.path) {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akc-route",
"version": "0.0.4",
"version": "0.0.5",
"description": "A distributed router inspired by PolymerElements/app-route",
"authors": [
"Alan Chandler"
Expand Down
9 changes: 6 additions & 3 deletions test/akc-location_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@
expect(el.route.path).to.equal(window.location.pathname);
});
it('expect search string changes to reflect in route', function() {
console.log('just before setting query string to ?date=20160101&staff=2');
setLocation(window.location.pathname + '?date=20160101&staff=2');
console.log('query string set in test');
expect(el.route.query).to.deep.equal({date: '20160101', staff: '2'});
});
it('reflect changes to route path to url', function() {
Expand All @@ -91,7 +89,12 @@
it('reflect query string changes to route.query', function() {
el.set('route.query', {firstname: 'Joe', lastname: 'Bloggs'});
expect(window.location.search).to.equal('?firstname=Joe&lastname=Bloggs');
})
});
it('seting query to null object in route should clear qhery string', function() {
el.set('route.query', {firstname: 'Joe', lastname: 'Bloggs'});
el.set('route.query', {});
expect(window.location.search).to.equal('');
});

});
});
Expand Down
6 changes: 6 additions & 0 deletions test/akc-route_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
el.set('subSubRoute.path', '/20161231');
expect(el.route.path).to.equal('/reports/bydate/20160101');
});
it('zero length parameter change limits actuve', function() {
el.match = '/:page';
el.route = {path: '/reports/bydate/20160101', active: true, params: {}, query: {}};
el.set('subRoute.params', {page: ''});
expect(el.route.path).to.equal('/');
});

});

Expand Down

0 comments on commit 2845af0

Please sign in to comment.