2010-01-06 00:36:58 +00:00
|
|
|
jstd = jstestdriver;
|
2010-03-30 03:25:42 +00:00
|
|
|
dump = bind(jstd.console, jstd.console.log);
|
2010-03-15 21:36:50 +00:00
|
|
|
|
|
|
|
|
function nakedExpect(obj) {
|
|
|
|
|
return expect(angular.fromJson(angular.toJson(obj)));
|
2010-04-04 00:04:36 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-03-30 21:55:04 +00:00
|
|
|
function childNode(element, index) {
|
|
|
|
|
return jqLite(element[0].childNodes[index]);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-05 21:09:25 +00:00
|
|
|
extend(angular, {
|
|
|
|
|
'element': jqLite,
|
|
|
|
|
'compile': compile,
|
|
|
|
|
'scope': createScope,
|
|
|
|
|
'copy': copy,
|
|
|
|
|
'extend': extend,
|
|
|
|
|
'foreach': foreach,
|
|
|
|
|
'noop':noop,
|
|
|
|
|
'identity':identity,
|
|
|
|
|
'isUndefined': isUndefined,
|
|
|
|
|
'isDefined': isDefined,
|
|
|
|
|
'isString': isString,
|
|
|
|
|
'isFunction': isFunction,
|
|
|
|
|
'isNumber': isNumber,
|
|
|
|
|
'isArray': isArray
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function sortedHtml(element) {
|
2010-01-06 00:36:58 +00:00
|
|
|
var html = "";
|
2010-04-12 21:28:15 +00:00
|
|
|
foreach(element, function toString(node) {
|
2010-01-06 00:36:58 +00:00
|
|
|
if (node.nodeName == "#text") {
|
2010-01-09 23:02:43 +00:00
|
|
|
html += escapeHtml(node.nodeValue);
|
2010-01-06 00:36:58 +00:00
|
|
|
} 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' &&
|
2010-04-12 21:28:15 +00:00
|
|
|
attr.name !='style' &&
|
2010-01-06 00:36:58 +00:00
|
|
|
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('');
|
2010-04-15 21:17:33 +00:00
|
|
|
if (node.style) {
|
|
|
|
|
var style = [];
|
|
|
|
|
if (node.style.cssText) {
|
|
|
|
|
foreach(node.style.cssText.split(';'), function(value){
|
|
|
|
|
value = trim(value);
|
|
|
|
|
if (value) {
|
|
|
|
|
style.push(value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
for(var css in node.style){
|
|
|
|
|
var value = node.style[css];
|
|
|
|
|
if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) {
|
2010-04-19 21:36:41 +00:00
|
|
|
var text = css + ': ' + value;
|
|
|
|
|
if (value != 'false' && indexOf(style, text) == -1) {
|
2010-04-15 21:17:33 +00:00
|
|
|
style.push(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-19 21:41:36 +00:00
|
|
|
}
|
2010-04-13 02:16:30 +00:00
|
|
|
style.sort();
|
2010-04-15 21:17:33 +00:00
|
|
|
if (style.length) {
|
|
|
|
|
html += ' style="' + style.join('; ') + ';"';
|
|
|
|
|
}
|
2010-04-12 21:28:15 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
html += '>';
|
|
|
|
|
var children = node.childNodes;
|
|
|
|
|
for(var j=0; j<children.length; j++) {
|
2010-03-30 03:25:42 +00:00
|
|
|
toString(children[j]);
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
html += '</' + node.nodeName.toLowerCase() + '>';
|
|
|
|
|
}
|
2010-04-12 21:28:15 +00:00
|
|
|
});
|
2010-01-06 00:36:58 +00:00
|
|
|
return html;
|
2010-04-04 00:04:36 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-04-08 20:43:40 +00:00
|
|
|
function isCssVisible(node) {
|
2010-03-31 20:57:25 +00:00
|
|
|
var display = node.css('display');
|
2010-02-04 21:27:56 +00:00
|
|
|
if (display == 'block') display = "";
|
|
|
|
|
return display != 'none';
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 00:36:58 +00:00
|
|
|
function assertHidden(node) {
|
2010-04-08 20:43:40 +00:00
|
|
|
assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isCssVisible(node));
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertVisible(node) {
|
2010-04-08 20:43:40 +00:00
|
|
|
assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isCssVisible(node));
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertJsonEquals(expected, actual) {
|
2010-01-09 23:02:43 +00:00
|
|
|
assertEquals(toJson(expected), toJson(actual));
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertUndefined(value) {
|
|
|
|
|
assertEquals('undefined', typeof value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertDefined(value) {
|
2010-01-09 23:02:43 +00:00
|
|
|
assertTrue(toJson(value), !!value);
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertThrows(error, fn){
|
|
|
|
|
var exception = null;
|
|
|
|
|
try {
|
|
|
|
|
fn();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
exception = e;
|
|
|
|
|
}
|
|
|
|
|
if (!exception) {
|
|
|
|
|
fail("Expecting exception, none thrown");
|
|
|
|
|
}
|
|
|
|
|
assertEquals(error, exception);
|
2010-01-09 00:04:35 +00:00
|
|
|
}
|
2010-02-04 23:04:28 +00:00
|
|
|
|
|
|
|
|
log = noop;
|
2010-03-15 21:36:50 +00:00
|
|
|
error = noop;
|