aboutsummaryrefslogtreecommitdiffstats
path: root/test/testabilityPatch.js
blob: 5fca3524b2d2e90e5b895979db794704b6c9b2a8 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
TestCase = function(name) { return jstestdriver.testCaseManager.TestCase(name); };

HIDDEN = jQuery.browser.msie ?
    '' :
    jQuery.browser.safari ?
         ' style="display: none; "' :
         ' style="display: none;"';

nglr.msie = jQuery.browser.msie;
nglr.alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);};

function noop(){}

jstd = jstestdriver;

function html(content) {
  return jQuery("<div></div>").html(content);
}

function report(reportTest){
  $("#tests").children().each(function(i){
    var success = this.className == "pass";
    var strong = this.firstChild;
    var msg = strong.firstChild.nodeValue;
    var parts = msg.split(" module: ");
    var module = parts[0];
    var name = parts[1].replace(/ *$/, "");
    reportTest(success, module, name, this.nodeValue);
  });
}

MockUrlWatcher = function() {
  this.url = "http://server";
};
MockUrlWatcher.prototype.getUrl = function(){
  return this.url;
};
MockUrlWatcher.prototype.setUrl = function(url){
  this.url = url;
};

jQuery.fn.sortedHtml = function() {
  var html = "";
  var toString = function(index, node) {
    node = node || this;
    if (node.nodeName == "#text") {
      html += nglr.escapeHtml(node.nodeValue);
    } else {
      html += '<' + node.nodeName.toLowerCase();
      var attributes = node.attributes || [];
      var attrs = [];
      for(var i=0; i<attributes.length; i++) {
        var attr = attributes[i];
        if(attr.name.match(/^ng-/) ||
            attr.value &&
            attr.value !='null' &&
            attr.value !='auto' &&
            attr.value !='false' &&
            attr.value !='inherit' &&
            attr.value !='0' &&
            attr.name !='loop' &&
            attr.name !='maxLength' &&
            attr.name !='size' &&
            attr.name !='start' &&
            attr.name !='tabIndex' &&
            attr.name.substr(0, 6) != 'jQuery') {
          // in IE we need to check for all of these.
          attrs.push(' ' + attr.name + '="' + attr.value + '"');
        }
      }
      attrs.sort();
      html += attrs.join('');
      html += '>';
      var children = node.childNodes;
      for(var j=0; j<children.length; j++) {
        toString(j, children[j]);
      }
      html += '</' + node.nodeName.toLowerCase() + '>';
    }
  };
  this.children().each(toString);
  return html;
};

function encode64(obj){
  return Base64.encode(nglr.toJson(obj));
}

function decode64(base64){
  return nglr.fromJson(Base64.decode(base64));
}

nglr.Loader.prototype.configureJQueryPlugins();

function assertHidden(node) {
  var display = node.css('display');
  assertEquals("Node should be hidden but vas visible: " + node.sortedHtml(), 'none', display);
}

function assertVisible(node) {
  var display = node.css('display');
  if (display == 'block') display = "";
  assertEquals("Node should be visible but vas hidden: " + node.sortedHtml(), '', display);
}

function assertJsonEquals(expected, actual) {
  assertEquals(nglr.toJson(expected), nglr.toJson(actual));
}

function assertUndefined(value) {
  assertEquals('undefined', typeof value);
}

function assertDefined(value) {
  assertTrue(nglr.toJson(value), !!value);
}

function assertThrows(error, fn){
  var exception = null;
  try {
    fn();
  } catch(e) {
    exception = e;
  }
  if (!exception) {
    fail("Expecting exception, none thrown");
  }
  assertEquals(error, exception);
}