Basic build tests

https://fedorahosted.org/freeipa/ticket/3235
This commit is contained in:
Petr Vobornik 2013-04-11 13:00:32 +02:00
parent d5b9c0d7d7
commit 44c103bab7

View File

@ -19,8 +19,12 @@
*/ */
define([ define([
'freeipa/_base/Spec_mod'], 'dojo/_base/declare',
function(Spec_mod) { return function() { 'freeipa/_base/Builder',
'freeipa/_base/Spec_mod',
'freeipa/spec_util'
],
function(declare, Builder, Spec_mod, su) { return function() {
module('build',{ module('build',{
@ -32,6 +36,41 @@ module('build',{
}); });
test('Testing builder', function() { test('Testing builder', function() {
var simple_factory = function(spec) {
var that = {};
su.set(that, spec, 'foo', 'bar');
return that;
};
var Simple_class = declare(null, {
foo: 'bar',
constructor: function(spec) {
su.set(this, spec, 'foo');
}
});
var b1 = new Builder({factory: simple_factory});
var b2 = new Builder({ctor: Simple_class});
var o1 = b1.build({});
var o11 = b1.build({ foo: 'baz'});
var o2 = b2.build({});
var o21 = b2.build({ foo: 'baz'});
var r1 = { foo: 'bar' };
var r11 = { foo: 'baz' };
var r2 = new Simple_class({});
var r21 = new Simple_class({ foo:'baz'});
deepEqual(o1, r1, 'Factory, default');
deepEqual(o11, r11, 'Factory, spec use');
deepEqual(o2, r2, 'Constructor, default');
deepEqual(o21, r21, 'Constructor, spec use');
}); });
test('Testing Spec_mod', function() { test('Testing Spec_mod', function() {