BinderTest = TestCase('BinderTest'); BinderTest.prototype.setUp = function(){ var self = this; this.compile = function(html, initialScope, config) { var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); var element = self.element = jqLite(html); var scope = compiler.compile(element)(element); extend(scope, initialScope); scope.$init(); return {node:element, scope:scope}; }; this.compileToHtml = function (content) { return sortedHtml(this.compile(content).node); }; }; BinderTest.prototype.tearDown = function(){ if (this.element && this.element.dealoc) this.element.dealoc(); }; BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ var state = this.compile('', {model:{}}); state.scope.$eval(); assertEquals('abc', state.scope.model.price); }; BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ var c = this.compile(''); c.scope.$eval(); assertEquals(c.scope.model.note, 'abc'); }; BinderTest.prototype.testChangingRadioUpdatesModel = function(){ var c = this.compile('' + ''); c.scope.$eval(); assertEquals(c.scope.model.price, 'A'); }; BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ var form = this.compile(''); assertEquals(true, form.scope.model.price); }; BinderTest.prototype.testBindUpdate = function() { var c = this.compile('
'); assertEquals(123, c.scope.$get('a')); }; BinderTest.prototype.testChangingSelectNonSelectedUpdatesModel = function(){ var form = this.compile(''); assertEquals('A', form.scope.model.price); }; BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ var form = this.compile(''); assertJsonEquals(["A", "B"], form.scope.$get('Invoice').options); }; BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ var form = this.compile(''); assertEquals(form.scope.model.price, 'b'); }; BinderTest.prototype.testExecuteInitialization = 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.testFillInOptionValueWhenMissing = function() { var c = this.compile( ''); c.scope.$set('a', 'A'); c.scope.$set('b', 'B'); c.scope.$eval(); var optionA = childNode(c.node, 0); var optionB = childNode(c.node, 1); var optionC = childNode(c.node, 2); expect(optionA.attr('value')).toEqual('A'); expect(optionA.text()).toEqual('A'); expect(optionB.attr('value')).toEqual(''); expect(optionB.text()).toEqual('B'); expect(optionC.attr('value')).toEqual('C'); expect(optionC.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.testDeleteAttributeIfEvaluatesFalse = function() { var c = this.compile('