forked from YahooArchive/mojito
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-view-renderer.client.js
106 lines (86 loc) · 3.22 KB
/
test-view-renderer.client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*jslint anon:true, sloppy:true, nomen:true, node:true*/
/*global YUI*/
YUI.add('mojito-view-renderer-client-tests', function(Y, NAME) {
var suite = new Y.Test.Suite(NAME),
A = Y.Assert,
AA = Y.ArrayAssert,
OA = Y.ObjectAssert,
cases;
suite.add(new Y.Test.Case({
name: 'mojito-view-renderer',
setUp: function() {
Y.namespace('mojito.addons.viewEngines');
// resetting engines
Y.mojito.addons.viewEngines = {};
},
tearDown: function() {},
'test instantiating a renderer engine': function () {
var vr;
vr = new Y.mojito.ViewRenderer('foo', {z:99});
A.isObject(vr);
// less restrictive initialization
vr = new Y.mojito.ViewRenderer('bar');
A.isObject(vr);
},
'test render method with valid engine': function () {
var args;
var ve = Y.namespace('mojito.addons.viewEngines');
ve.foo = function(options) {
A.areSame(99, options.z);
};
ve.foo.prototype.render = function(data, mojitType, tmpl, adapter, meta, more) {
args = arguments;
};
var vr = new Y.mojito.ViewRenderer('foo', {z:99});
vr.render(1,2,3,4,5,6);
A.areSame(6, args.length);
A.areSame(1, args[0]);
A.areSame(2, args[1]);
A.areSame(3, args[2]);
A.areSame(4, args[3]);
A.areSame(5, args[4]);
A.areSame(6, args[5]);
},
'test render method with ondemand engine': function () {
var args;
YUI.add('mojito-fakebarengine', function (Y) {
var ve = Y.namespace('mojito.addons.viewEngines');
ve.fakebarengine = function(options) {
A.areSame(99, options.z);
};
ve.fakebarengine.prototype.render = function(data, mojitType, tmpl, adapter, meta, more) {
args = arguments;
};
});
var vr = new Y.mojito.ViewRenderer('fakebarengine', {z:99});
vr.render(1,2,3,4,5,6);
this.wait(function () {
A.areSame(6, args.length);
A.areSame(1, args[0]);
A.areSame(2, args[1]);
A.areSame(3, args[2]);
A.areSame(4, args[3]);
A.areSame(5, args[4]);
A.areSame(6, args[5]);
}, 300);
},
'test render method with invalid ondemand engine': function () {
var err;
var vr = new Y.mojito.ViewRenderer('fakebazengine', {z:99});
vr.render(1,2,3, {
error: function () {
err = true;
}
},5,6);
this.wait(function () {
A.isTrue(err, 'an error should occurr when the engine is invalid');
}, 300);
}
}));
Y.Test.Runner.add(suite);
}, '0.0.1', {requires: ['mojito-view-renderer']});