aboutsummaryrefslogtreecommitdiffstats
path: root/src/scenario/DSL.js
diff options
context:
space:
mode:
authorElliott Sprehn2010-10-18 14:02:18 -0700
committerElliott Sprehn2010-10-19 00:45:38 -0700
commite7e894a2e36e042be6d62af56b0f3126f4e4fc77 (patch)
tree5b9c8b94bf3e3935a3acd6a3c0ecb142c82f4b17 /src/scenario/DSL.js
parenta1fa23397f12e0b52838530a993f14491ad50869 (diff)
downloadangular.js-e7e894a2e36e042be6d62af56b0f3126f4e4fc77.tar.bz2
Significantly clean up the way the scenario DSL works and implement many more DSL statements.
- "this" always means the current chain scope inside a DSL - addFutureAction callbacks now take ($window, $document, done) - $document has a special method elements() that uses the currently selected nodes in the document as defined by using() statements. - $document.elements() allows placeholder insertion into selectors to make them more readable. ex. $document.elements('input[name="$1"]', myVar) will substitute the value of myVar for $1 in the selector. Subsequent arguments are $2 and so on. - $document.elements() results have a special method trigger(event) which should be used to events. This method implements some hacks to make sure browser UI controls update and the correct angular events fire. - futures now allow custom formatting. By default any chain that results in a future can use toJson() or fromJson() to convert the future value to and from json. A custom parser can be provided with parsedWith(fn) where fn is a callback(value) that must return the parsed result. Note: The entire widgets.html UI is now able to be controlled and asserted through DSL statements!!! Victory! :)
Diffstat (limited to 'src/scenario/DSL.js')
-rw-r--r--src/scenario/DSL.js134
1 files changed, 0 insertions, 134 deletions
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
deleted file mode 100644
index a7571afe..00000000
--- a/src/scenario/DSL.js
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * Shared DSL statements that are useful to all scenarios.
- */
-
-/**
-* 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.setTimeout(function() { done(null, time * 1000); }, time * 1000);
- });
- };
-});
-
-/**
- * Usage:
- * expect(future).{matcher} where matcher is one of the matchers defined
- * with angular.scenario.matcher
- *
- * ex. expect(binding("name")).toEqual("Elliott")
- */
-angular.scenario.dsl('expect', function() {
- var chain = angular.extend({}, angular.scenario.matcher);
-
- chain.not = function() {
- this.inverse = true;
- return chain;
- };
-
- return function(future) {
- this.future = future;
- return chain;
- };
-});
-
-/**
- * Usage:
- * navigateTo(future|string) where url a string or future with a value
- * of a URL to navigate to
- */
-angular.scenario.dsl('navigateTo', function() {
- return function(url) {
- var application = this.application;
- var name = url;
- if (url.name) {
- name = ' value of ' + url.name;
- }
- return this.addFuture('navigate to ' + name, function(done) {
- application.navigateTo(url.value || url, function() {
- application.executeAction(function() {
- if (this.angular) {
- var $browser = this.angular.service.$browser();
- $browser.poll();
- $browser.notifyWhenNoOutstandingRequests(function() {
- done(null, url.value || url);
- });
- } else {
- done(null, url.value || url);
- }
- });
- });
- });
- };
-});
-
-/**
- * Usage:
- * input(name).enter(value) enters value in input with specified name
- * input(name).check() checks checkbox
- * input(name).select(value) selects the readio button with specified name/value
- */
-angular.scenario.dsl('input', function() {
- var chain = {};
-
- chain.enter = function(value) {
- var spec = this;
- return this.addFutureAction("input '" + this.name + "' enter '" + value + "'", function(done) {
- var input = _jQuery(this.document).find('input[name=' + spec.name + ']');
- if (!input.length)
- return done("Input named '" + spec.name + "' does not exist.");
- input.val(value);
- this.angular.element(input[0]).trigger('change');
- done();
- });
- };
-
- chain.check = function() {
- var spec = this;
- return this.addFutureAction("checkbox '" + this.name + "' toggle", function(done) {
- var input = _jQuery(this.document).
- find('input:checkbox[name=' + spec.name + ']');
- if (!input.length)
- return done("Input named '" + spec.name + "' does not exist.");
- this.angular.element(input[0]).trigger('click');
- input.attr('checked', !input.attr('checked'));
- done();
- });
- };
-
- chain.select = function(value) {
- var spec = this;
- return this.addFutureAction("radio button '" + this.name + "' toggle '" + value + "'", function(done) {
- var input = _jQuery(this.document).
- find('input:radio[name$="@' + spec.name + '"][value="' + value + '"]');
- if (!input.length)
- return done("Input named '" + spec.name + "' does not exist.");
- this.angular.element(input[0]).trigger('click');
- input.attr('checked', !input.attr('checked'));
- done();
- });
- };
-
- return function(name) {
- this.name = name;
- return chain;
- };
-});
-
-/**
- * Usage:
- * binding(name) returns the value of a binding
- */
-angular.scenario.dsl('binding', function() {
- return function(name) {
- return this.addFutureAction("select binding '" + name + "'", function(done) {
- var element = _jQuery(this.document).find('[ng\\:bind="' + name + '"]');
- if (!element.length)
- return done("Binding named '" + name + "' does not exist.");
- done(null, element.text());
- });
- };
-});