From a9c182764b5feeb2466c4bb32f7572762f7fab6d Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 28 Jan 2010 22:10:49 -0800
Subject: added formatters
---
test/BinderTest.js | 17 +++++++++++++++--
test/FormatersTest.js | 6 ------
test/FormattersTest.js | 28 ++++++++++++++++++++++++++++
test/WidgetsTest.js | 6 +++---
4 files changed, 46 insertions(+), 11 deletions(-)
delete mode 100644 test/FormatersTest.js
create mode 100644 test/FormattersTest.js
(limited to 'test')
diff --git a/test/BinderTest.js b/test/BinderTest.js
index cf2fa31a..450100e4 100644
--- a/test/BinderTest.js
+++ b/test/BinderTest.js
@@ -129,10 +129,10 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){
};
BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){
- var form = compile('');
+ var form = compile('');
form.scope.set('model', {});
form.binder.updateView();
- assertEquals('A', form.scope.get('model').price);
+ assertEquals(true, form.scope.get('model').price);
};
BinderTest.prototype.testBindUpdate = function() {
@@ -951,3 +951,16 @@ BinderTest.prototype.testItShouldRenderMultiRootHtmlInBinding = function() {
'
before acdafter
',
x.node.sortedHtml());
};
+
+BinderTest.prototype.testItShouldUseFormaterForText = function() {
+ var x = compile('');
+ x.binder.updateView();
+ 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.binder.updateView();
+ assertEquals('1, 2, 3', input[0].value);
+};
diff --git a/test/FormatersTest.js b/test/FormatersTest.js
deleted file mode 100644
index 0122b6ad..00000000
--- a/test/FormatersTest.js
+++ /dev/null
@@ -1,6 +0,0 @@
-TestCase("formaterTest", {
- testNoop: function(){
- assertEquals("abc", angular.formater.noop("abc"));
- assertEquals("xyz", angular.formater.noop("abc", "xyz"));
- }
-});
diff --git a/test/FormattersTest.js b/test/FormattersTest.js
new file mode 100644
index 00000000..b71e68dc
--- /dev/null
+++ b/test/FormattersTest.js
@@ -0,0 +1,28 @@
+TestCase("formatterTest", {
+ testNoop: function(){
+ assertEquals("abc", angular.formatter.noop.format("abc"));
+ assertEquals("xyz", angular.formatter.noop.parse("xyz"));
+ assertEquals(null, angular.formatter.noop.parse(null));
+ },
+
+ testList: function() {
+ assertEquals('a, b', angular.formatter.list.format(['a', 'b']));
+ assertEquals(['abc', 'c'], angular.formatter.list.parse(" , abc , c ,,"));
+ assertEquals(null, angular.formatter.list.parse(null));
+ },
+
+ testBoolean: function() {
+ assertEquals('true', angular.formatter.boolean.format(true));
+ assertEquals('false', angular.formatter.boolean.format(false));
+ assertEquals(true, angular.formatter.boolean.parse("true"));
+ assertEquals(false, angular.formatter.boolean.parse(""));
+ assertEquals(false, angular.formatter.boolean.parse("false"));
+ assertEquals(null, angular.formatter.boolean.parse(null));
+ },
+
+ testNumber: function() {
+ assertEquals('1', angular.formatter.number.format(1));
+ assertEquals(1, angular.formatter.number.format('1'));
+ }
+
+});
diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js
index c0a2d082..4e3852a5 100644
--- a/test/WidgetsTest.js
+++ b/test/WidgetsTest.js
@@ -3,7 +3,7 @@ WidgetTest = TestCase('WidgetTest');
WidgetTest.prototype.testRequired = function () {
var view = $('');
var scope = new Scope({$invalidWidgets:[]});
- var cntl = new TextController(view[0], 'a');
+ var cntl = new TextController(view[0], 'a', angularFormatter.noop);
cntl.updateView(scope);
assertTrue(view.hasClass('ng-validation-error'));
assertEquals("Required Value", view.attr('ng-error'));
@@ -16,7 +16,7 @@ WidgetTest.prototype.testRequired = function () {
WidgetTest.prototype.testValidator = function () {
var view = $('');
var scope = new Scope({$invalidWidgets:[]});
- var cntl = new TextController(view[0], 'a');
+ var cntl = new TextController(view[0], 'a', angularFormatter.noop);
angular.validator.testValidator = function(value, expect){
return value == expect ? null : "Error text";
};
@@ -44,7 +44,7 @@ WidgetTest.prototype.testValidator = function () {
WidgetTest.prototype.testRequiredValidator = function () {
var view = $('');
var scope = new Scope({$invalidWidgets:[]});
- var cntl = new TextController(view[0], 'a');
+ var cntl = new TextController(view[0], 'a', angularFormatter.noop);
angular.validator.testValidator = function(value, expect){
return value == expect ? null : "Error text";
};
--
cgit v1.2.3