aboutsummaryrefslogtreecommitdiffstats
path: root/src/scenario/DSL.js
blob: 194a28d6f5c465fab1c20175914f0bf70d54b8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
angular.scenario.dsl.browser = {
  navigateTo: function(url){
    $scenario.addStep('Navigate to: ' + url, function(done){
      var self = this;
      this.testFrame.load(function(){
        self.testFrame.unbind();
        self.testWindow = self.testFrame[0].contentWindow;
        self.testDocument = jQuery(self.testWindow.document);
        self.$browser = self.testWindow.angular.service.$browser();
        self.notifyWhenNoOutstandingRequests = bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
        self.notifyWhenNoOutstandingRequests(done);
      });
      if (this.testFrame.attr('src') == url) {
        this.testFrame[0].contentWindow.location.reload();
      } else {
        this.testFrame.attr('src', url);
      }
    });
  }
};

angular.scenario.dsl.input = function(selector) {
  return {
    enter: function(value){
      $scenario.addStep("Set input text of '" + selector + "' to '" +
        value + "'", function(done){
          var input = this.testDocument.find('input[name=' + selector + ']');
          input.val(value);
          this.testWindow.angular.element(input[0]).trigger('change');
          done();
      });
    },
    select: function(value){
      $scenario.addStep("Select radio '" + selector + "' to '" +
              value + "'", function(done){
        var input = this.testDocument.
          find(':radio[name$=@' + selector + '][value=' + value + ']');
        var event = this.testWindow.document.createEvent('MouseEvent');
        event.initMouseEvent('click', true, true, this.testWindow, 0,0,0,0,0, false, false, false, false, 0, null);
        input[0].dispatchEvent(event);
        done();
      });
    }
  };
};

angular.scenario.dsl.expect = {
  repeater: function(selector) {
    return {
      count: {
        toEqual: function(number) {
          $scenario.addStep("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
            var items = this.testDocument.find(selector);
            if (items.length != number) {
              this.result.fail("Expected " + number + " but was " + items.length);
            }
            done();
          });
        }
      }
    };
  }
};