Skip to content

Commit

Permalink
add test case for overridding mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphsmith80 committed Feb 7, 2013
1 parent b29ad85 commit 448d8b8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/widgets/boundwidgetgroup/test.js
Expand Up @@ -115,5 +115,48 @@ define([
}, 0);
});

asyncTest('override mappings', function() {
var testValue = 'volume_id value',
testObject = {volume_id: testValue},
bwg = BoundWidgetGroup(template(), {
widgetize: true,
modelClass: TargetVolumeProfile,
bindings: [
{widget: 'name', field: 'name'},
{widget: 'volume_id', field: 'volume_id'}
],
mappings: {
// mapping('toObject', name, value);
// mapping('getValue', model, name);
volume_id: function(evt, opts) {
if (evt === 'getValue') {
ok(opts.hasOwnProperty('name'), 'getValue options include name');
ok(opts.hasOwnProperty('model'), 'getValue options include model');
} else if (evt === 'toObject') {
ok(opts.hasOwnProperty('name'), 'toObject options include name');
ok(opts.hasOwnProperty('value'), 'toObject options include value');
}
return (evt === 'getValue')? testValue : testObject;
}
}
}),
model = bwg.getModel();

// mapping('getValue', {model: model, name: name});
var v = bwg.getModelValue('volume_id');
equal(v, testValue, 'volume_id is equal to the overridden value');
// mapping('toObject', {name: name, value: value});
var ov = bwg.toModelObject('volume_id');
equal(ov, testObject, 'volume_id is equal to the overridden value');

// getBoundValues honors mappings
// this is a bit of an awkward case if testObect did not contain a matching key
// i.e. {test: testvalue} instead of {volume_id: testValue}
// then `getBoundValues would return `bv['volume_id'] === undefined`
var bv = bwg.getBoundValues();
equal(bv['volume_id'], testObject['volume_id'], 'boundValue volume_id is equal to the overridden value');
start();
});

start();
});

0 comments on commit 448d8b8

Please sign in to comment.