c4e53ec5 by Adam Heath

More testing on full-object returns through the adapter.

1 parent e4adb2bb
...@@ -49,8 +49,25 @@ define(function(require) { ...@@ -49,8 +49,25 @@ define(function(require) {
49 function buildTest(path, options) { 49 function buildTest(path, options) {
50 it(path, function() { 50 it(path, function() {
51 var inputElement = document.createElement('input'); 51 var inputElement = document.createElement('input');
52 inputElement.setAttribute('rv-value', path); 52 var binderName = options.bb ? 'bb-model' : 'value';
53 inputElement.setAttribute('rv-' + binderName, path);
54 var pojoObjects = [];
53 var view = rivets.bind(inputElement, model, { 55 var view = rivets.bind(inputElement, model, {
56 binders: {
57 'bb-model': {
58 bind: function(el) {
59 console.log('bb-model:bind', el);
60 },
61 routine: function(el, value) {
62 var pojoObject = options.parse(value);
63 console.log('bb-model:routine', el, JSON.stringify(pojoObject));
64 pojoObjects.push(pojoObject);
65 },
66 unbind: function(el) {
67 console.log('bb-model:unbind', el);
68 },
69 },
70 },
54 formatters: { 71 formatters: {
55 toJSON: function(value) { 72 toJSON: function(value) {
56 return value.toJSON(); 73 return value.toJSON();
...@@ -80,7 +97,11 @@ define(function(require) { ...@@ -80,7 +97,11 @@ define(function(require) {
80 } 97 }
81 } 98 }
82 var value = convertValue(options.value); 99 var value = convertValue(options.value);
100 if (options.bb) {
101 expect(pojoObjects[0]).toEqual(value);
102 } else {
83 expect(getInputElementValue()).toEqual(value); 103 expect(getInputElementValue()).toEqual(value);
104 }
84 if (options.get) { 105 if (options.get) {
85 var newValue = convertValue(options.newValue); 106 var newValue = convertValue(options.newValue);
86 inputElement.value = newValue; 107 inputElement.value = newValue;
...@@ -118,13 +139,40 @@ define(function(require) { ...@@ -118,13 +139,40 @@ define(function(require) {
118 value: '', 139 value: '',
119 }); 140 });
120 //buildTest(':contactMechs:*.length', '2'); 141 //buildTest(':contactMechs:*.length', '2');
121 buildTest(':contactMechs:PRIMARY_EMAIL | toJSON | jsonStringify', { 142 buildTest(':contactMechs:PRIMARY_EMAIL', {
143 bb: true,
122 value: function() { 144 value: function() {
123 var primaryEmail = contactMechs.get('PRIMARY_EMAIL'); 145 return contactMechs.get('PRIMARY_EMAIL').toJSON();
124 return primaryEmail.toJSON();
125 }, 146 },
126 parse: function(rawValue) { 147 parse: function(rawValue) {
127 return JSON.parse(rawValue); 148 return rawValue.toJSON();
149 },
150 });
151 buildTest(':contactMechs:PRIMARY_EMAIL:*', {
152 bb: true,
153 value: function() {
154 return contactMechs.get('PRIMARY_EMAIL').toJSON();
155 },
156 parse: function(rawValue) {
157 return rawValue;
158 },
159 });
160 buildTest(':contactMechs', {
161 bb: true,
162 value: function() {
163 return contactMechs.toJSON();
164 },
165 parse: function(rawValue) {
166 return rawValue.toJSON();
167 },
168 });
169 buildTest(':contactMechs:*', {
170 bb: true,
171 value: function() {
172 return contactMechs.models;
173 },
174 parse: function(rawValue) {
175 return rawValue;
128 }, 176 },
129 }); 177 });
130 /* 178 /*
......