Provide browser DSL with location() to expect the iframe URL parts. Also move navigateTo() under the browser DSL.

This commit is contained in:
Elliott Sprehn 2010-10-29 16:02:57 -07:00
parent 2d61040fb0
commit 6bb2cd6ee2
5 changed files with 165 additions and 48 deletions

View file

@ -1,5 +1,16 @@
# <angular/> 0.9.2 faunal-mimicry (in-progress) #
### Testability
- binding DSL in Scenario can now match bindings without specifying filters
- dsl statements now accept a label argument to make test output more readable (issue #94)
- dsl element() statement now implements most of the jQuery API (issue #106)
- file:// URLs are no longer supported for running a scenario. You must use a web server that implements HEAD
- new browser() dsl statement for getting info about the emulated browser running the app (issue #109)
- navigateTo() is now browser().navigateTo(). Old code must be updated
- navigating to about:blank is no longer supported. It results in a sandbox error
- scenario runner is now compatible with IE8 (issue #93)
- scenarior runner checks if URL would return a non-success status code (issue #100)
# <angular/> 0.9.1 repulsion-field (2010-10-26) #

View file

@ -1,7 +1,7 @@
describe('personal log', function() {
beforeEach(function() {
navigateTo('../personalLog.html');
browser().navigateTo('../personalLog.html');
});
@ -64,8 +64,8 @@ describe('personal log', function() {
element('form input[type="submit"]').click();
expect(repeater('ul li').count()).toEqual(1);
navigateTo('about:blank');
navigateTo('../personalLog.html');
browser().navigateTo('about:blank');
browser().navigateTo('../personalLog.html');
expect(repeater('ul li').column('log.msg')).toEqual('my persistent message');
expect(repeater('ul li').count()).toEqual(1);

View file

@ -1,6 +1,6 @@
describe('widgets', function() {
it('should verify that basic widgets work', function(){
navigateTo('widgets.html');
browser().navigateTo('widgets.html');
using('#text-basic-box').input('text.basic').enter('Carlos');
expect(binding('text.basic')).toEqual('Carlos');
@ -48,6 +48,7 @@ describe('widgets', function() {
element('#navigate a', "'Go to #route' link").click();
expect(binding('$location.hash')).toEqual('route');
expect(browser().location().hash()).toEqual('route');
/**
* Custom value parser for futures.

View file

@ -16,15 +16,87 @@ angular.scenario.dsl('wait', function() {
});
/**
* Usage:
* pause(seconds) pauses the test for specified number of seconds
*/
* Usage:
* pause(seconds) pauses the test for specified number of seconds
*/
angular.scenario.dsl('pause', function() {
return function(time) {
return this.addFuture('pause for ' + time + ' seconds', function(done) {
this.$window.setTimeout(function() { done(null, time * 1000); }, time * 1000);
});
};
return function(time) {
return this.addFuture('pause for ' + time + ' seconds', function(done) {
this.$window.setTimeout(function() { done(null, time * 1000); }, time * 1000);
});
};
});
/**
* Usage:
* 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().location().href() the full URL of the page
* browser().location().hash() the full hash in the url
* browser().location().path() the full path in the url
* browser().location().hashSearch() the hashSearch Object from angular
* browser().location().hashPath() the hashPath string from angular
*/
angular.scenario.dsl('browser', function() {
var chain = {};
chain.navigateTo = function(url, delegate) {
var application = this.application;
return this.addFuture('browser navigate to ' + url, function(done) {
if (delegate) {
url = delegate.call(this, url);
}
application.navigateTo(url, function() {
done(null, url);
}, done);
});
};
chain.location = function() {
var api = {};
api.href = function() {
return this.addFutureAction('browser url', function($window, $document, done) {
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() {
return this.addFutureAction('browser url path', function($window, $document, done) {
done(null, $window.location.pathname);
});
};
api.search = function() {
return this.addFutureAction('browser url search', function($window, $document, done) {
done(null, $window.angular.scope().$location.search);
});
};
api.hashSearch = function() {
return this.addFutureAction('browser url hash search', function($window, $document, done) {
done(null, $window.angular.scope().$location.hashSearch);
});
};
api.hashPath = function() {
return this.addFutureAction('browser url hash path', function($window, $document, done) {
done(null, $window.angular.scope().$location.hashPath);
});
};
return api;
};
return function(time) {
return chain;
};
});
/**
@ -48,25 +120,6 @@ angular.scenario.dsl('expect', function() {
};
});
/**
* Usage:
* navigateTo(url) Loads the url into the frame
* navigateTo(url, fn) where fn(url) is called and returns the URL to navigate to
*/
angular.scenario.dsl('navigateTo', function() {
return function(url, delegate) {
var application = this.application;
return this.addFuture('navigate to ' + url, function(done) {
if (delegate) {
url = delegate.call(this, url);
}
application.navigateTo(url, function() {
done(null, url);
}, done);
});
};
});
/**
* Usage:
* using(selector, label) scopes the next DSL element selection

View file

@ -87,26 +87,78 @@ describe("angular.scenario.dsl", function() {
});
});
describe('NavigateTo', function() {
it('should allow a string url', function() {
$root.dsl.navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
it('should allow a future url', function() {
$root.dsl.navigateTo('http://myurl', function() {
return 'http://futureUrl/';
describe('Browser', function() {
describe('NavigateTo', function() {
it('should allow a string url', function() {
$root.dsl.browser().navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
it('should allow a future url', function() {
$root.dsl.browser().navigateTo('http://myurl', function() {
return 'http://futureUrl/';
});
expect($window.location).toEqual('http://futureUrl/');
expect($root.futureResult).toEqual('http://futureUrl/');
});
it('should complete if angular is missing from app frame', function() {
delete $window.angular;
$root.dsl.browser().navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
expect($window.location).toEqual('http://futureUrl/');
expect($root.futureResult).toEqual('http://futureUrl/');
});
it('should complete if angular is missing from app frame', function() {
delete $window.angular;
$root.dsl.navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
describe('Location', function() {
beforeEach(function() {
$window.location = {
href: 'http://myurl/some/path?foo=10#/bar?x=2',
pathname: '/some/path',
search: '?foo=10',
hash: '#bar?x=2'
};
$window.angular.scope = function() {
return {
$location: {
hashSearch: {x: 2},
hashPath: '/bar',
search: {foo: 10}
}
};
};
});
it('should return full URL for href', function() {
$root.dsl.browser().location().href();
expect($root.futureResult).toEqual($window.location.href);
});
it('should return the pathname', function() {
$root.dsl.browser().location().path();
expect($root.futureResult).toEqual($window.location.pathname);
});
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() {
$root.dsl.browser().location().search();
expect($root.futureResult).toEqual({foo: 10});
});
it('should return the hashSearch as an object', function() {
$root.dsl.browser().location().hashSearch();
expect($root.futureResult).toEqual({x: 2});
});
it('should return the hashPath', function() {
$root.dsl.browser().location().hashPath();
expect($root.futureResult).toEqual('/bar');
});
});
});