mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-17 11:11:05 +00:00
fix(scenario.dsl): Fix dsl for $location
New $location does not have hashSearch, hashPath. The old dsl was mixing $location / window.location so this solves the problem as well...
This commit is contained in:
parent
d7ba5bc83b
commit
dc8ffa51b7
3 changed files with 84 additions and 48 deletions
|
|
@ -187,7 +187,7 @@ angularTextMarkup('option', function(text, textNode, parentElement){
|
||||||
expect(element('#link-3').attr('href')).toBe("/123");
|
expect(element('#link-3').attr('href')).toBe("/123");
|
||||||
|
|
||||||
element('#link-3').click();
|
element('#link-3').click();
|
||||||
expect(browser().location().path()).toEqual('/123');
|
expect(browser().window().path()).toEqual('/123');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should execute ng:click but not reload when href empty string and name specified', function() {
|
it('should execute ng:click but not reload when href empty string and name specified', function() {
|
||||||
|
|
@ -207,7 +207,7 @@ angularTextMarkup('option', function(text, textNode, parentElement){
|
||||||
expect(element('#link-6').attr('href')).toBe("/6");
|
expect(element('#link-6').attr('href')).toBe("/6");
|
||||||
|
|
||||||
element('#link-6').click();
|
element('#link-6').click();
|
||||||
expect(browser().location().path()).toEqual('/6');
|
expect(browser().window().path()).toEqual('/6');
|
||||||
});
|
});
|
||||||
</doc:scenario>
|
</doc:scenario>
|
||||||
</doc:example>
|
</doc:example>
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,14 @@ angular.scenario.dsl('sleep', function() {
|
||||||
* browser().navigateTo(url) Loads the url into the frame
|
* browser().navigateTo(url) Loads the url into the frame
|
||||||
* browser().navigateTo(url, fn) where fn(url) is called and returns the URL to navigate to
|
* browser().navigateTo(url, fn) where fn(url) is called and returns the URL to navigate to
|
||||||
* browser().reload() refresh the page (reload the same URL)
|
* browser().reload() refresh the page (reload the same URL)
|
||||||
* browser().location().href() the full URL of the page
|
* browser().window.href() window.location.href
|
||||||
* browser().location().hash() the full hash in the url
|
* browser().window.path() window.location.pathname
|
||||||
* browser().location().path() the full path in the url
|
* browser().window.search() window.location.search
|
||||||
* browser().location().hashSearch() the hashSearch Object from angular
|
* browser().window.hash() window.location.hash without # prefix
|
||||||
* browser().location().hashPath() the hashPath string from angular
|
* browser().location().url() see angular.service.$location#url
|
||||||
|
* browser().location().path() see angular.service.$location#path
|
||||||
|
* browser().location().search() see angular.service.$location#search
|
||||||
|
* browser().location().hash() see angular.service.$location#hash
|
||||||
*/
|
*/
|
||||||
angular.scenario.dsl('browser', function() {
|
angular.scenario.dsl('browser', function() {
|
||||||
var chain = {};
|
var chain = {};
|
||||||
|
|
@ -65,42 +68,60 @@ angular.scenario.dsl('browser', function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
chain.location = function() {
|
chain.window = function() {
|
||||||
var api = {};
|
var api = {};
|
||||||
|
|
||||||
api.href = function() {
|
api.href = function() {
|
||||||
return this.addFutureAction('browser url', function($window, $document, done) {
|
return this.addFutureAction('window.location.href', function($window, $document, done) {
|
||||||
done(null, $window.location.href);
|
done(null, $window.location.href);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
api.hash = function() {
|
|
||||||
return this.addFutureAction('browser url hash', function($window, $document, done) {
|
|
||||||
done(null, $window.location.hash.replace('#', ''));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
api.path = function() {
|
api.path = function() {
|
||||||
return this.addFutureAction('browser url path', function($window, $document, done) {
|
return this.addFutureAction('window.location.path', function($window, $document, done) {
|
||||||
done(null, $window.location.pathname);
|
done(null, $window.location.pathname);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
api.search = function() {
|
api.search = function() {
|
||||||
return this.addFutureAction('browser url search', function($window, $document, done) {
|
return this.addFutureAction('window.location.search', function($window, $document, done) {
|
||||||
done(null, $window.angular.scope().$service('$location').search);
|
done(null, $window.location.search);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
api.hashSearch = function() {
|
api.hash = function() {
|
||||||
return this.addFutureAction('browser url hash search', function($window, $document, done) {
|
return this.addFutureAction('window.location.hash', function($window, $document, done) {
|
||||||
done(null, $window.angular.scope().$service('$location').hashSearch);
|
done(null, $window.location.hash.replace('#', ''));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
api.hashPath = function() {
|
return api;
|
||||||
return this.addFutureAction('browser url hash path', function($window, $document, done) {
|
};
|
||||||
done(null, $window.angular.scope().$service('$location').hashPath);
|
|
||||||
|
chain.location = function() {
|
||||||
|
var api = {};
|
||||||
|
|
||||||
|
api.url = function() {
|
||||||
|
return this.addFutureAction('$location.url()', function($window, $document, done) {
|
||||||
|
done(null, $window.angular.scope().$service('$location').url());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
api.path = function() {
|
||||||
|
return this.addFutureAction('$location.path()', function($window, $document, done) {
|
||||||
|
done(null, $window.angular.scope().$service('$location').path());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
api.search = function() {
|
||||||
|
return this.addFutureAction('$location.search()', function($window, $document, done) {
|
||||||
|
done(null, $window.angular.scope().$service('$location').search());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
api.hash = function() {
|
||||||
|
return this.addFutureAction('$location.hash()', function($window, $document, done) {
|
||||||
|
done(null, $window.angular.scope().$service('$location').hash());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ describe("angular.scenario.dsl", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Location', function() {
|
describe('window', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
$window.location = {
|
$window.location = {
|
||||||
href: 'http://myurl/some/path?foo=10#/bar?x=2',
|
href: 'http://myurl/some/path?foo=10#/bar?x=2',
|
||||||
|
|
@ -131,51 +131,66 @@ describe("angular.scenario.dsl", function() {
|
||||||
search: '?foo=10',
|
search: '?foo=10',
|
||||||
hash: '#bar?x=2'
|
hash: '#bar?x=2'
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return full URL for href', function() {
|
||||||
|
$root.dsl.browser().window().href();
|
||||||
|
expect($root.futureResult).toEqual($window.location.href);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the pathname', function() {
|
||||||
|
$root.dsl.browser().window().path();
|
||||||
|
expect($root.futureResult).toEqual($window.location.pathname);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the search part', function() {
|
||||||
|
$root.dsl.browser().window().search();
|
||||||
|
expect($root.futureResult).toEqual($window.location.search);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the hash without the #', function() {
|
||||||
|
$root.dsl.browser().window().hash();
|
||||||
|
expect($root.futureResult).toEqual('bar?x=2');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('location', function() {
|
||||||
|
beforeEach(function() {
|
||||||
$window.angular.scope = function() {
|
$window.angular.scope = function() {
|
||||||
return {
|
return {
|
||||||
$service: function(serviceId) {
|
$service: function(serviceId) {
|
||||||
if (serviceId == '$location') {
|
if (serviceId == '$location') {
|
||||||
return {
|
return {
|
||||||
hashSearch: {x: 2},
|
url: function() {return '/path?search=a#hhh';},
|
||||||
hashPath: '/bar',
|
path: function() {return '/path';},
|
||||||
search: {foo: 10}
|
search: function() {return {search: 'a'};},
|
||||||
|
hash: function() {return 'hhh';}
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
throw new Error('unknown service id ' + serviceId);
|
|
||||||
}
|
}
|
||||||
|
throw new Error('unknown service id ' + serviceId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return full URL for href', function() {
|
it('should return full url', function() {
|
||||||
$root.dsl.browser().location().href();
|
$root.dsl.browser().location().url();
|
||||||
expect($root.futureResult).toEqual($window.location.href);
|
expect($root.futureResult).toEqual('/path?search=a#hhh');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the pathname', function() {
|
it('should return the pathname', function() {
|
||||||
$root.dsl.browser().location().path();
|
$root.dsl.browser().location().path();
|
||||||
expect($root.futureResult).toEqual($window.location.pathname);
|
expect($root.futureResult).toEqual('/path');
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the hash without the #', function() {
|
|
||||||
$root.dsl.browser().location().hash();
|
|
||||||
expect($root.futureResult).toEqual('bar?x=2');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the query string as an object', function() {
|
it('should return the query string as an object', function() {
|
||||||
$root.dsl.browser().location().search();
|
$root.dsl.browser().location().search();
|
||||||
expect($root.futureResult).toEqual({foo: 10});
|
expect($root.futureResult).toEqual({search: 'a'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the hashSearch as an object', function() {
|
it('should return the hash without the #', function() {
|
||||||
$root.dsl.browser().location().hashSearch();
|
$root.dsl.browser().location().hash();
|
||||||
expect($root.futureResult).toEqual({x: 2});
|
expect($root.futureResult).toEqual('hhh');
|
||||||
});
|
|
||||||
|
|
||||||
it('should return the hashPath', function() {
|
|
||||||
$root.dsl.browser().location().hashPath();
|
|
||||||
expect($root.futureResult).toEqual('/bar');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue