From 44c103bab75a26e787d0a2d7908bed5bf398dd02 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Thu, 11 Apr 2013 13:00:32 +0200 Subject: [PATCH] Basic build tests https://fedorahosted.org/freeipa/ticket/3235 --- install/ui/test/build_tests.js | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/install/ui/test/build_tests.js b/install/ui/test/build_tests.js index 11c5a03e5..fec8717b2 100644 --- a/install/ui/test/build_tests.js +++ b/install/ui/test/build_tests.js @@ -19,8 +19,12 @@ */ define([ - 'freeipa/_base/Spec_mod'], - function(Spec_mod) { return function() { + 'dojo/_base/declare', + 'freeipa/_base/Builder', + 'freeipa/_base/Spec_mod', + 'freeipa/spec_util' + ], + function(declare, Builder, Spec_mod, su) { return function() { module('build',{ @@ -32,6 +36,41 @@ module('build',{ }); 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() {