c4e53ec5 by Adam Heath

More testing on full-object returns through the adapter.

1 parent e4adb2bb
......@@ -49,8 +49,25 @@ define(function(require) {
function buildTest(path, options) {
it(path, function() {
var inputElement = document.createElement('input');
inputElement.setAttribute('rv-value', path);
var binderName = options.bb ? 'bb-model' : 'value';
inputElement.setAttribute('rv-' + binderName, path);
var pojoObjects = [];
var view = rivets.bind(inputElement, model, {
binders: {
'bb-model': {
bind: function(el) {
console.log('bb-model:bind', el);
},
routine: function(el, value) {
var pojoObject = options.parse(value);
console.log('bb-model:routine', el, JSON.stringify(pojoObject));
pojoObjects.push(pojoObject);
},
unbind: function(el) {
console.log('bb-model:unbind', el);
},
},
},
formatters: {
toJSON: function(value) {
return value.toJSON();
......@@ -80,7 +97,11 @@ define(function(require) {
}
}
var value = convertValue(options.value);
expect(getInputElementValue()).toEqual(value);
if (options.bb) {
expect(pojoObjects[0]).toEqual(value);
} else {
expect(getInputElementValue()).toEqual(value);
}
if (options.get) {
var newValue = convertValue(options.newValue);
inputElement.value = newValue;
......@@ -118,13 +139,40 @@ define(function(require) {
value: '',
});
//buildTest(':contactMechs:*.length', '2');
buildTest(':contactMechs:PRIMARY_EMAIL | toJSON | jsonStringify', {
buildTest(':contactMechs:PRIMARY_EMAIL', {
bb: true,
value: function() {
var primaryEmail = contactMechs.get('PRIMARY_EMAIL');
return primaryEmail.toJSON();
return contactMechs.get('PRIMARY_EMAIL').toJSON();
},
parse: function(rawValue) {
return JSON.parse(rawValue);
return rawValue.toJSON();
},
});
buildTest(':contactMechs:PRIMARY_EMAIL:*', {
bb: true,
value: function() {
return contactMechs.get('PRIMARY_EMAIL').toJSON();
},
parse: function(rawValue) {
return rawValue;
},
});
buildTest(':contactMechs', {
bb: true,
value: function() {
return contactMechs.toJSON();
},
parse: function(rawValue) {
return rawValue.toJSON();
},
});
buildTest(':contactMechs:*', {
bb: true,
value: function() {
return contactMechs.models;
},
parse: function(rawValue) {
return rawValue;
},
});
/*
......