aboutsummaryrefslogtreecommitdiffstats
path: root/scenario/widgets-scenario2.js
blob: e24cabad38232158045ba5619304e16272c23e2d (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
browser = {
  navigateTo: function(url){
    $scenario.addStep('Navigate to: ' + url, function(done){
      var self = this;
      self.testFrame.load(function(){
        self.testFrame.unbind();
        self.testDocument = self.testWindow.angular.element(self.testWindow.document);
        done();
      });
      if (this.testFrame.attr('src') == url) {
        this.testWindow.location.reload();
      } else {
        this.testFrame.attr('src', url);
      }
    });
  }
};

function input(selector) {
  return {
    enter: function(value){
      $scenario.addStep("Set input text of '" + selector + "' to value '" + value + "'", function(done){
        var input = this.testDocument.find('input[name=' + selector + ']');
        input.val(value);
        input.trigger('change');
        done();
      });
    }
  };
}

function expect(selector) {
  return {
    toEqual: function(expected) {
      $scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){
        var attrName = selector.substring(2, selector.length - 2);
        var binding = this.testDocument.find('span[ng-bind=' + attrName + ']');
        if (binding.text() != expected) {
          this.result.fail("Expected '" + expected + "' but was '" + binding.text() + "'");
        }
        done();
      });
    }
  };
}

describe('widgets', function(){
  it('should verify that basic widgets work', function(){
    browser.navigateTo('widgets.html');
    expect('{{text.basic}}').toEqual('');
    input('text.basic').enter('John');
    expect('{{text.basic}}').toEqual('JohnXX');
  });
});