');
assertEquals(c.scope.$get('a'), 123);
assertEquals(c.scope.$get('b'), 345);
};
BinderTest.prototype.testApplyTextBindings = function(){
var form = this.compile('
');
form.scope.$set('model', {a:123});
form.scope.$eval();
assertEquals('123', form.node.text());
};
BinderTest.prototype.testReplaceBindingInTextWithSpan = function() {
assertEquals(this.compileToHtml("
');
};
BinderTest.prototype.XtestBindingSpaceConfusesIE = function() {
//if (!msie) return;
var span = document.createElement("span");
span.innerHTML = ' ';
var nbsp = span.firstChild.nodeValue;
assertEquals(
'
',
this.compileToHtml("{{A}} x {{B}} ({{C}})"));
};
BinderTest.prototype.testBindingOfAttributes = function() {
var c = this.compile("
");
var attrbinding = c.node.attr("ng-bind-attr");
var bindings = fromJson(attrbinding);
assertEquals("http://s/a{{b}}c", decodeURI(bindings.href));
assertTrue(!bindings.foo);
};
BinderTest.prototype.testMarkMultipleAttributes = function() {
var c = this.compile('
');
var attrbinding = c.node.attr("ng-bind-attr");
var bindings = fromJson(attrbinding);
assertEquals(bindings.foo, "{{d}}");
assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c");
};
BinderTest.prototype.testAttributesNoneBound = function() {
var c = this.compile("
");
var a = c.node;
assertEquals(a[0].nodeName, "A");
assertTrue(!a.attr("ng-bind-attr"));
};
BinderTest.prototype.testExistingAttrbindingIsAppended = function() {
var c = this.compile("
");
var a = c.node;
assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng-bind-attr'));
};
BinderTest.prototype.testAttributesAreEvaluated = function(){
var c = this.compile('
');
var binder = c.binder, form = c.node;
c.scope.$eval('a=1;b=2');
c.scope.$eval();
var a = c.node;
assertEquals(a.attr('a'), 'a');
assertEquals(a.attr('b'), 'a+b=3');
};
BinderTest.prototype.XtestInputsAreUpdated = function(){
var a =
this.compile('
');
var form = a.node;
a.scope.$set('A', {text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"});
a.scope.$eval();
assertEquals(form.find("input[type=text]").attr('value'), 't1');
assertEquals(form.find("textarea").attr('value'), 't2');
assertTrue(form.find("input[name=A.radio]").attr('checked'));
assertTrue(!form.find("input[name=A.radioOff]").attr('checked'));
assertTrue(form.find("input[name=A.checkbox]").attr('checked'));
assertTrue(!form.find("input[name=A.checkboxOff]").attr('checked'));
assertEquals(form.find("select").attr('value'), 'S');
assertEquals(form.find("option[selected]").text(), 'b');
};
BinderTest.prototype.xtestInputTypeButtonActionExecutesInScope = function(){
var savedCalled = false;
var c = this.compile('
');
c.scope.$set("person.save", function(){
savedCalled = true;
});
c.node.click();
assertTrue(savedCalled);
};
BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){
expectAsserts(1);
var c = this.compile('
');
c.scope.$set("action", function(){
assertTrue(true);
});
c.node.click();
};
BinderTest.prototype.testButtonElementActionExecutesInScope = function(){
var savedCalled = false;
var c = this.compile('
');
c.scope.$set("person.save", function(){
savedCalled = true;
});
c.node.click();
assertTrue(savedCalled);
};
BinderTest.prototype.XtestParseEmptyAnchor = function(){
var binder = this.compile("
").binder;
var location = binder.location;
var anchor = binder.anchor;
location.url = "a#x=1";
binder.parseAnchor();
assertEquals(1, binder.anchor.x);
location.url = "a#";
binder.parseAnchor();
assertTrue("old values did not get removed", !binder.anchor.x);
assertTrue("anchor gor replaced", anchor === binder.anchor);
assertEquals('undefined', typeof (anchor[""]));
};
BinderTest.prototype.XtestParseAnchor = function(){
var binder = this.compile("
").binder;
var location = binder.location;
location.url = "a#x=1";
binder.parseAnchor();
assertEquals(binder.anchor.x, "1");
location.url = "a#a=b&c=%20&d";
binder.parseAnchor();
assertEquals(binder.anchor.a, 'b');
assertEquals(binder.anchor.c, ' ');
assertTrue(binder.anchor.d !== null);
assertTrue(!binder.anchor.x);
};
BinderTest.prototype.XtestWriteAnchor = function(){
var binder = this.compile("
").binder;
binder.location.set('a');
binder.anchor.a = 'b';
binder.anchor.c = ' ';
binder.anchor.d = true;
binder.updateAnchor();
assertEquals(binder.location.get(), "a#a=b&c=%20&d");
};
BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){
var binder = this.compile("
").binder;
binder.location.set('a');
binder.anchor.a = 'b';
binder.updateView();
assertEquals(binder.location.get(), "a#a=b");
};
BinderTest.prototype.XtestRepeaterUpdateBindings = function(){
var a = this.compile('
');
var form = a.node;
var items = [{a:"A"}, {a:"B"}];
var initialDataCount = _(jQuery.cache).size();
assertTrue("" + initialDataCount, initialDataCount > 0);
a.scope.$set('model', {items:items});
a.scope.$eval();
assertEquals('
', sortedHtml(form));
items.unshift({a:'C'});
a.scope.$eval();
assertEquals('
', sortedHtml(form));
items.shift();
items.shift();
a.scope.$eval();
var currentDataCount = _(jQuery.cache).size();
assertEquals("I have leaked " + (currentDataCount - initialDataCount), initialDataCount, currentDataCount);
};
BinderTest.prototype.XtestRepeaterContentDoesNotBind = function(){
var a = this.compile('
');
a.scope.$set('model', {items:[{a:"A"}]});
a.scope.$eval();
assertEquals('
', sortedHtml(a.node));
};
BinderTest.prototype.XtestShouldBindActionsOnRepeaterClone = function(){
var c = this.compile('
');
jQuery(c).die();
c.scope.$set('result.value', false);
c.scope.$set('items', ['abc', 'xyz']);
c.scope.updateView();
assertEquals(2, c.node.find("a").size());
c.node.find("a:last").click();
assertEquals('xyz', c.scope.$get('result.value'));
};
BinderTest.prototype.XtestRepeaterInputContentDoesNotBind = function(){
var c = compil('
');
c.scope.items = [{a:"A"}];
assertEquals(c.node.find(":input").attr("value"), "OLD");
};
BinderTest.prototype.XtestExpandEntityTag = function(){
assertEquals(
'
'));
};
BinderTest.prototype.XtestExpandEntityTagWithDefaults = function(){
assertEquals(
'
'));
};
BinderTest.prototype.XtestExpandEntityTagWithName = function(){
var c = this.compile('
');
assertEquals(
'
',
sortedHtml(c.node));
assertEquals("Person", c.scope.$get("friend.$entity"));
assertEquals("friend", c.scope.$get("friend.$$anchor"));
};
BinderTest.prototype.XtestExpandSubmitButtonToAction = function(){
var html = this.compileToHtml('
');
assertTrue(html, html.indexOf('ng-action="$save()"') > 0 );
assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 );
};
BinderTest.prototype.XtestDoNotOverwriteCustomAction = function(){
var html = this.compileToHtml('
');
assertTrue(html.indexOf('action="foo();"') > 0 );
};
BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){
expectAsserts(1);
var form = jQuery("body").append('
');
form.data('scope', new Scope());
var factory = {};
var binder = new Binder(form.get(0), factory, new MockLocation());
factory.createController = function(node){
assertEquals(node.attr('type'), 'file');
return {updateModel:function(){}};
};
binder.compile();
jQuery("#testTag").remove();
};
BinderTest.prototype.XtestRepeaterAdd = function(){
var c = this.compile('
');
var doc = c.node;
c.scope.$set('items', [{x:'a'}, {x:'b'}]);
c.binder.compile();
c.scope.$eval();
assertEquals('a', doc.find(':input')[0].value);
assertEquals('b', doc.find(':input')[1].value);
var first = doc.find('[ng-repeat-index="0"]');
first[0].value = 'ABC';
first.trigger('keyup');
assertEquals(doc.scope().get('items')[0].x, 'ABC');
};
BinderTest.prototype.XtestItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){
var c = this.compile('
{{i}}
');
var items = {};
c.scope.$set("items", items);
c.scope.$eval();
expect(c.node.find("div").size()).toEqual(0);
items.name = "misko";
c.scope.$eval();
expect(c.node.find("div").size()).toEqual(1);
delete items.name;
c.scope.$eval();
expect(c.node.find("div").size()).toEqual(0);
};
BinderTest.prototype.XtestIfTextBindingThrowsErrorDecorateTheSpan = function(){
var a = this.compile('
{{error.throw()}}
');
var doc = a.node.find('div');
a.scope.$set('error.throw', function(){throw "ErrorMsg1";});
a.scope.$eval();
var span = doc.find('span');
assertTrue(span.hasClass('ng-exception'));
assertEquals('ErrorMsg1', fromJson(span.text()));
assertEquals('"ErrorMsg1"', span.attr('ng-error'));
a.scope.$set('error.throw', function(){throw "MyError";});
a.scope.$eval();
span = doc.find('span');
assertTrue(span.hasClass('ng-exception'));
assertTrue(span.text(), span.text().match('MyError') !== null);
assertEquals('"MyError"', span.attr('ng-error'));
a.scope.$set('error.throw', function(){return "ok";});
a.scope.$eval();
assertFalse(span.hasClass('ng-exception'));
assertEquals('ok', span.text());
assertEquals(null, span.attr('ng-error'));
};
BinderTest.prototype.XtestIfAttrBindingThrowsErrorDecorateTheSpan = function(){
var a = this.compile('
');
var doc = a.node.find("div");
a.scope.$set('error.throw', function(){throw "ErrorMsg";});
a.scope.$eval();
assertTrue('ng-exception', doc.hasClass('ng-exception'));
assertEquals('before ["ErrorMsg"] after', doc.attr('attr'));
assertEquals('"ErrorMsg"', doc.attr('ng-error'));
a.scope.$set('error.throw', function(){ return 'X';});
a.scope.$eval();
assertFalse('!ng-exception', doc.hasClass('ng-exception'));
assertEquals('before X after', doc.attr('attr'));
assertEquals(null, doc.attr('ng-error'));
};
BinderTest.prototype.XtestNestedRepeater = function() {
var a = this.compile('
');
a.scope.$set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]);
a.scope.$eval();
assertEquals(
//'<#comment>#comment>'+
'
'+
'<#comment>#comment>'+
'
'+
'
'+
'
'+
'
'+
'<#comment>#comment>'+
'
'+
'
'+
'
', sortedHtml(a.node));
};
BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () {
var a = this.compile('
');
a.scope.$set('model', ['a1', 'a2']);
a.scope.$eval();
assertEquals(
//'<#comment>#comment>'+
'
'+
'
',
sortedHtml(a.node));
};
BinderTest.prototype.XtestHideBindingExpression = function() {
var a = this.compile('
');
a.scope.$set('hidden', 3);
a.scope.$eval();
assertHidden(a.node.children());
a.scope.$set('hidden', 2);
a.scope.$eval();
assertVisible(a.node.children());
};
BinderTest.prototype.XtestHideBinding = function() {
var c = this.compile('
');
c.scope.$set('hidden', 'true');
c.scope.$eval();
assertHidden(c.node.children());
c.scope.$set('hidden', 'false');
c.scope.$eval();
assertVisible(c.node.children());
c.scope.$set('hidden', '');
c.scope.$eval();
assertVisible(c.node.children());
};
BinderTest.prototype.XtestShowBinding = function() {
var c = this.compile('
');
c.scope.$set('show', 'true');
c.scope.$eval();
assertVisible(c.node.children());
c.scope.$set('show', 'false');
c.scope.$eval();
assertHidden(c.node.children());
c.scope.$set('show', '');
c.scope.$eval();
assertHidden(c.node.children());
};
BinderTest.prototype.XtestBindClassUndefined = function() {
var doc = this.compile('
');
doc.scope.$eval();
assertEquals(
'
',
sortedHtml(doc.node));
};
BinderTest.prototype.XtestBindClass = function() {
var c = this.compile('
');
c.scope.$set('class', 'testClass');
c.scope.$eval();
assertEquals(sortedHtml(c.node),
'
');
c.scope.$set('class', ['a', 'b']);
c.scope.$eval();
assertEquals(sortedHtml(c.node),
'
');
};
BinderTest.prototype.XtestBindClassEvenOdd = function() {
var x = this.compile('
');
x.scope.$eval();
assertEquals(
'
' +
'
',
sortedHtml(x.node));
};
BinderTest.prototype.XtestBindStyle = function() {
var c = this.compile('
');
c.scope.eval('style={color:"red"}');
c.scope.$eval();
assertEquals("red", c.node.find('div').css('color'));
c.scope.eval('style={}');
c.scope.$eval();
assertEquals(sortedHtml(c.node), '
');
};
BinderTest.prototype.XtestActionOnAHrefThrowsError = function(){
var model = {books:[]};
var state = this.compile('
Add Phone', model);
var input = state.node.find('a');
input.click();
assertEquals('abc', fromJson(input.attr('ng-error')).a);
assertTrue("should have an error class", input.hasClass('ng-exception'));
input.attr('ng-action', '0');
input.click();
assertFalse('error class should be cleared', input.hasClass('ng-exception'));
};
BinderTest.prototype.XtestShoulIgnoreVbNonBindable = function(){
var c = this.compile("{{a}}" +
"
{{a}}
" +
"
{{b}}
" +
"
{{c}}
");
c.scope.$set('a', 123);
c.scope.updateView();
assertEquals('123{{a}}{{b}}{{c}}', c.node.text());
};
BinderTest.prototype.XtestOptionShouldUpdateParentToGetProperBinding = function() {
var c = this.compile('
');
c.scope.$set('s', 1);
c.scope.$eval();
assertEquals(1, c.node.find('select')[0].selectedIndex);
};
BinderTest.prototype.XtestRepeaterShouldBindInputsDefaults = function () {
var c = this.compile('
');
c.scope.$set('items', [{}, {name:'misko'}]);
c.scope.$eval();
assertEquals("123", c.scope.eval('items[0].name'));
assertEquals("misko", c.scope.eval('items[1].name'));
};
BinderTest.prototype.XtestRepeaterShouldCreateArray = function () {
var c = this.compile('
');
c.scope.$eval();
assertEquals(0, c.scope.$get('items').length);
};
BinderTest.prototype.XtestShouldTemplateBindPreElements = function () {
var c = this.compile('
Hello {{name}}!');
c.scope.$set("name", "World");
c.scope.$eval();
assertEquals('
Hello World!
', sortedHtml(c.node));
};
BinderTest.prototype.XtestDissableAutoSubmit = function() {
var c = this.compile('
', null, {autoSubmit:true});
assertEquals(
'
',
sortedHtml(c.node));
c = this.compile('
', null, {autoSubmit:false});
assertEquals(
'
',
sortedHtml(c.node));
};
BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() {
var c = this.compile('');
c.binder.location.set("http://server/#a=1&b=2");
c.binder.parseAnchor();
assertEquals('1', c.binder.anchor.a);
assertEquals('2', c.binder.anchor.b);
c.binder.anchor.a = null;
c.binder.anchor.b = null;
c.binder.updateAnchor();
assertEquals('http://server/#', c.binder.location.get());
};
BinderTest.prototype.XtestFillInOptionValueWhenMissing = function() {
var c = this.compile(
'
');
c.scope.$set('a', 'A');
c.scope.$set('b', 'B');
c.scope.$eval();
expect(c.node.find("option:first").attr('value')).toEqual('A');
expect(c.node.find("option:first").text()).toEqual('A');
expect(c.node.find("option:nth-child(2)").attr('value')).toEqual('');
expect(c.node.find("option:nth-child(2)").text()).toEqual('B');
expect(c.node.find("option:last").attr('value')).toEqual('C');
expect(c.node.find("option:last").text()).toEqual('C');
};
BinderTest.prototype.XtestValidateForm = function() {
var c = this.compile('
' +
'
');
var items = [{}, {}];
c.scope.$set("items", items);
c.scope.$eval();
assertEquals(3, c.scope.$get("$invalidWidgets.length"));
c.scope.$set('name', '');
c.scope.$eval();
assertEquals(3, c.scope.$get("$invalidWidgets.length"));
c.scope.$set('name', ' ');
c.scope.$eval();
assertEquals(3, c.scope.$get("$invalidWidgets.length"));
c.scope.$set('name', 'abc');
c.scope.$eval();
assertEquals(2, c.scope.$get("$invalidWidgets.length"));
items[0].name = 'abc';
c.scope.$eval();
assertEquals(1, c.scope.$get("$invalidWidgets.length"));
items[1].name = 'abc';
c.scope.$eval();
assertEquals(0, c.scope.$get("$invalidWidgets.length"));
};
BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){
var c = this.compile('
');
c.scope.$set("show", true);
c.scope.$eval();
assertEquals(2, c.scope.$get("$invalidWidgets.length"));
c.scope.$set("show", false);
c.scope.$eval();
assertEquals(1, c.scope.$get("$invalidWidgets.length"));
};
BinderTest.prototype.XtestDeleteAttributeIfEvaluatesFalse = function() {
var c = this.compile(
'
' +
'
' +
'
');
c.scope.$eval();
var html = c.node.html();
assertEquals(html + 0, 1, c.node.find("input[name='a0']:disabled").size());
assertEquals(html + 1, 1, c.node.find("input[name='b0']:disabled").size());
assertEquals(html + 2, 1, c.node.find("input[name='c0']:disabled").size());
assertEquals(html + 3, 0, c.node.find("input[name='a1']:disabled").size());
assertEquals(html + 4, 0, c.node.find("input[name='b1']:disabled").size());
assertEquals(html + 5, 0, c.node.find("input[name='c1']:disabled").size());
};
BinderTest.prototype.XtestRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () {
var c = this.compile(
'
');
c.scope.$eval();
assertTrue(c.node.find("input").hasClass("ng-exception"));
};
BinderTest.prototype.XtestItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized = function() {
var c = this.compile(
'
');
c.scope.$set('person', {a:'misko', b:'adam'});
c.scope.$eval();
assertEquals("", c.node.html());
};
BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() {
var log = "";
var c = this.compile('
');
c.scope.$set("count", 0);
c.scope.addWatchListener("$anchor.counter", function(newValue, oldValue){
log += oldValue + "->" + newValue + ";";
});
assertEquals(0, c.scope.$get("count"));
c.binder.location.url = "#counter=1";
c.binder.onUrlChange();
assertEquals(1, c.scope.$get("count"));
c.binder.location.url = "#counter=1";
c.binder.onUrlChange();
assertEquals(1, c.scope.$get("count"));
c.binder.location.url = "#counter=2";
c.binder.onUrlChange();
assertEquals(2, c.scope.$get("count"));
c.binder.location.url = "#counter=2";
c.binder.onUrlChange();
assertEquals(2, c.scope.$get("count"));
c.binder.location.url = "#";
c.binder.onUrlChange();
assertEquals("undefined->1;1->2;2->undefined;", log);
assertEquals(3, c.scope.$get("count"));
};
BinderTest.prototype.XtestParseQueryString = function(){
var binder = new Binder();
assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1"));
assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two"));
assertJsonEquals({}, binder.parseQueryString(""));
assertJsonEquals({"a":"1", "b":""}, binder.parseQueryString("a=1&b="));
assertJsonEquals({"a":"1", "b":""}, binder.parseQueryString("a=1&b"));
assertJsonEquals({"a":"1", "b":" 2 "}, binder.parseQueryString("a=1&b=%202%20"));
assertJsonEquals({"a a":"1", "b":"2"}, binder.parseQueryString("a%20a=1&b=2"));
};
BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){
expectAsserts(2);
var doc = this.compile("
");
doc.scope.addWatchListener("$anchor.name", function(newVal, oldVal) {
assertEquals("new", newVal);
assertEquals(undefined, oldVal);
});
doc.binder.anchor.name = "new";
doc.binder.onUrlChange("http://base#name=new");
};
BinderTest.prototype.XtestItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){
var c = this.compile(
'
' +
'
');
c.node.find("input").click();
assertEquals("ABC", c.scope.$get('greeting'));
assertTrue(c.node.find(":input:last").hasClass("ng-exception"));
};
BinderTest.prototype.XtestItShouldSelectTheCorrectRadioBox = function() {
var c = this.compile(
'
' +
'
');
c.node.find("input[value=female]").click();
assertEquals("female", c.scope.$get("sex"));
assertEquals(1, c.node.find("input:checked").size());
assertEquals("female", c.node.find("input:checked").attr("value"));
c.node.find("input[value=male]").click();
assertEquals("male", c.scope.$get("sex"));
assertEquals(1, c.node.find("input:checked").size());
assertEquals("male", c.node.find("input:checked").attr("value"));
};
BinderTest.prototype.XtestItShouldListenOnRightScope = function() {
var c = this.compile(
'
' +
'
');
c.binder.executeInit();
c.scope.$eval();
assertEquals(0, c.scope.$get("counter"));
assertEquals(0, c.scope.$get("gCounter"));
c.scope.$set("w", "something");
c.scope.$eval();
assertEquals(1, c.scope.$get("counter"));
assertEquals(7, c.scope.$get("gCounter"));
};
BinderTest.prototype.XtestItShouldRepeatOnHashes = function() {
var x = this.compile('
');
x.scope.$eval();
assertEquals(
'
a0
' +
'
b1
',
sortedHtml(x.node));
};
BinderTest.prototype.XtestItShouldFireChangeListenersBeforeUpdate = function(){
var x = this.compile('
');
x.scope.$set("name", "");
x.scope.$set("watched", "change");
x.scope.watch("watched:name=123");
x.scope.updateView();
assertEquals(123, x.scope.$get("name"));
assertEquals(
'
123
',
sortedHtml(x.node));
};
BinderTest.prototype.XtestItShouldHandleMultilineBindings = function(){
var x = this.compile('
{{\n 1 \n + \n 2 \n}}
');
x.scope.updateView();
assertEquals("3", x.node.text());
};
BinderTest.prototype.XtestItBindHiddenInputFields = function(){
var x = this.compile('
');
x.scope.updateView();
assertEquals("abc", x.scope.$get("myName"));
};
BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() {
var x = this.compile('
before {{a|html}}after
');
x.scope.$set("a", "a
cd");
x.scope.$eval();
assertEquals(
'
before acdafter
',
sortedHtml(x.node));
};
BinderTest.prototype.XtestItShouldUseFormaterForText = function() {
var x = this.compile('
');
x.scope.$eval();
assertEquals(['a','b'], x.scope.$get('a'));
var input = x.node.find('input');
input[0].value = ' x,,yz';
input.change();
assertEquals(['x','yz'], x.scope.$get('a'));
x.scope.$set('a', [1 ,2, 3]);
x.scope.$eval();
assertEquals('1, 2, 3', input[0].value);
};