Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit dc8ffa5

Browse files
committed
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...
1 parent d7ba5bc commit dc8ffa5

File tree

3 files changed

+82
-46
lines changed

3 files changed

+82
-46
lines changed

src/markups.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ angularTextMarkup('option', function(text, textNode, parentElement){
187187
expect(element('#link-3').attr('href')).toBe("/123");
188188
189189
element('#link-3').click();
190-
expect(browser().location().path()).toEqual('/123');
190+
expect(browser().window().path()).toEqual('/123');
191191
});
192192
193193
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){
207207
expect(element('#link-6').attr('href')).toBe("/6");
208208
209209
element('#link-6').click();
210-
expect(browser().location().path()).toEqual('/6');
210+
expect(browser().window().path()).toEqual('/6');
211211
});
212212
</doc:scenario>
213213
</doc:example>

src/scenario/dsl.js

+41-20
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ angular.scenario.dsl('sleep', function() {
3434
* browser().navigateTo(url) Loads the url into the frame
3535
* browser().navigateTo(url, fn) where fn(url) is called and returns the URL to navigate to
3636
* browser().reload() refresh the page (reload the same URL)
37-
* browser().location().href() the full URL of the page
38-
* browser().location().hash() the full hash in the url
39-
* browser().location().path() the full path in the url
40-
* browser().location().hashSearch() the hashSearch Object from angular
41-
* browser().location().hashPath() the hashPath string from angular
37+
* browser().window.href() window.location.href
38+
* browser().window.path() window.location.pathname
39+
* browser().window.search() window.location.search
40+
* browser().window.hash() window.location.hash without # prefix
41+
* browser().location().url() see angular.service.$location#url
42+
* browser().location().path() see angular.service.$location#path
43+
* browser().location().search() see angular.service.$location#search
44+
* browser().location().hash() see angular.service.$location#hash
4245
*/
4346
angular.scenario.dsl('browser', function() {
4447
var chain = {};
@@ -65,42 +68,60 @@ angular.scenario.dsl('browser', function() {
6568
});
6669
};
6770

68-
chain.location = function() {
71+
chain.window = function() {
6972
var api = {};
7073

7174
api.href = function() {
72-
return this.addFutureAction('browser url', function($window, $document, done) {
75+
return this.addFutureAction('window.location.href', function($window, $document, done) {
7376
done(null, $window.location.href);
7477
});
7578
};
7679

80+
api.path = function() {
81+
return this.addFutureAction('window.location.path', function($window, $document, done) {
82+
done(null, $window.location.pathname);
83+
});
84+
};
85+
86+
api.search = function() {
87+
return this.addFutureAction('window.location.search', function($window, $document, done) {
88+
done(null, $window.location.search);
89+
});
90+
};
91+
7792
api.hash = function() {
78-
return this.addFutureAction('browser url hash', function($window, $document, done) {
93+
return this.addFutureAction('window.location.hash', function($window, $document, done) {
7994
done(null, $window.location.hash.replace('#', ''));
8095
});
8196
};
8297

83-
api.path = function() {
84-
return this.addFutureAction('browser url path', function($window, $document, done) {
85-
done(null, $window.location.pathname);
98+
return api;
99+
};
100+
101+
chain.location = function() {
102+
var api = {};
103+
104+
api.url = function() {
105+
return this.addFutureAction('$location.url()', function($window, $document, done) {
106+
done(null, $window.angular.scope().$service('$location').url());
86107
});
87108
};
88109

89-
api.search = function() {
90-
return this.addFutureAction('browser url search', function($window, $document, done) {
91-
done(null, $window.angular.scope().$service('$location').search);
110+
api.path = function() {
111+
return this.addFutureAction('$location.path()', function($window, $document, done) {
112+
done(null, $window.angular.scope().$service('$location').path());
92113
});
93114
};
94115

95-
api.hashSearch = function() {
96-
return this.addFutureAction('browser url hash search', function($window, $document, done) {
97-
done(null, $window.angular.scope().$service('$location').hashSearch);
116+
api.search = function() {
117+
return this.addFutureAction('$location.search()', function($window, $document, done) {
118+
done(null, $window.angular.scope().$service('$location').search());
98119
});
99120
};
100121

101-
api.hashPath = function() {
102-
return this.addFutureAction('browser url hash path', function($window, $document, done) {
103-
done(null, $window.angular.scope().$service('$location').hashPath);
122+
api.hash = function() {
123+
return this.addFutureAction('$location.hash()', function($window, $document, done) {
124+
done(null, $window.angular.scope().$service('$location').hash());
104125
});
105126
};
106127

test/scenario/dslSpec.js

+39-24
Original file line numberDiff line numberDiff line change
@@ -123,59 +123,74 @@ describe("angular.scenario.dsl", function() {
123123
});
124124
});
125125

126-
describe('Location', function() {
126+
describe('window', function() {
127127
beforeEach(function() {
128128
$window.location = {
129129
href: 'http://myurl/some/path?foo=10#/bar?x=2',
130130
pathname: '/some/path',
131131
search: '?foo=10',
132132
hash: '#bar?x=2'
133133
};
134+
});
135+
136+
it('should return full URL for href', function() {
137+
$root.dsl.browser().window().href();
138+
expect($root.futureResult).toEqual($window.location.href);
139+
});
140+
141+
it('should return the pathname', function() {
142+
$root.dsl.browser().window().path();
143+
expect($root.futureResult).toEqual($window.location.pathname);
144+
});
145+
146+
it('should return the search part', function() {
147+
$root.dsl.browser().window().search();
148+
expect($root.futureResult).toEqual($window.location.search);
149+
});
150+
151+
it('should return the hash without the #', function() {
152+
$root.dsl.browser().window().hash();
153+
expect($root.futureResult).toEqual('bar?x=2');
154+
});
155+
});
156+
157+
describe('location', function() {
158+
beforeEach(function() {
134159
$window.angular.scope = function() {
135160
return {
136161
$service: function(serviceId) {
137162
if (serviceId == '$location') {
138163
return {
139-
hashSearch: {x: 2},
140-
hashPath: '/bar',
141-
search: {foo: 10}
164+
url: function() {return '/path?search=a#hhh';},
165+
path: function() {return '/path';},
166+
search: function() {return {search: 'a'};},
167+
hash: function() {return 'hhh';}
142168
};
143-
} else {
144-
throw new Error('unknown service id ' + serviceId);
145169
}
170+
throw new Error('unknown service id ' + serviceId);
146171
}
147172
};
148173
};
149174
});
150175

151-
it('should return full URL for href', function() {
152-
$root.dsl.browser().location().href();
153-
expect($root.futureResult).toEqual($window.location.href);
176+
it('should return full url', function() {
177+
$root.dsl.browser().location().url();
178+
expect($root.futureResult).toEqual('/path?search=a#hhh');
154179
});
155180

156181
it('should return the pathname', function() {
157182
$root.dsl.browser().location().path();
158-
expect($root.futureResult).toEqual($window.location.pathname);
159-
});
160-
161-
it('should return the hash without the #', function() {
162-
$root.dsl.browser().location().hash();
163-
expect($root.futureResult).toEqual('bar?x=2');
183+
expect($root.futureResult).toEqual('/path');
164184
});
165185

166186
it('should return the query string as an object', function() {
167187
$root.dsl.browser().location().search();
168-
expect($root.futureResult).toEqual({foo: 10});
188+
expect($root.futureResult).toEqual({search: 'a'});
169189
});
170190

171-
it('should return the hashSearch as an object', function() {
172-
$root.dsl.browser().location().hashSearch();
173-
expect($root.futureResult).toEqual({x: 2});
174-
});
175-
176-
it('should return the hashPath', function() {
177-
$root.dsl.browser().location().hashPath();
178-
expect($root.futureResult).toEqual('/bar');
191+
it('should return the hash without the #', function() {
192+
$root.dsl.browser().location().hash();
193+
expect($root.futureResult).toEqual('hhh');
179194
});
180195
});
181196
});

0 commit comments

Comments
 (0)