forked from assemble/assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.js
172 lines (151 loc) · 4.15 KB
/
group.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'use strict';
require('mocha');
require('should');
var assert = require('assert');
var support = require('./support/');
assert.containEql = support.containEql;
var support = require('./support');
var App = support.resolve();
var List = App.List;
var Group = App.Group;
var group;
describe('group', function() {
describe('constructor', function() {
it('should create an instance of Group:', function() {
var group = new Group();
assert(group instanceof Group);
});
it('should create an instance of Group with default List:', function() {
var group = new Group();
assert.deepEqual(group.List, List);
});
it('should create an instance of Group with custom List:', function() {
function CustomList() {
List.apply(this, arguments);
}
List.extend(CustomList);
var group = new Group({
List: CustomList
});
assert.deepEqual(group.List, CustomList);
});
});
describe('static methods', function() {
it('should expose `extend`:', function() {
assert(typeof Group.extend === 'function');
});
});
describe('prototype methods', function() {
beforeEach(function() {
group = new Group();
});
it('should expose `use`', function() {
assert(typeof group.use === 'function');
});
it('should expose `set`', function() {
assert(typeof group.set === 'function');
});
it('should expose `get`', function() {
assert(typeof group.get === 'function');
});
it('should expose `visit`', function() {
assert(typeof group.visit === 'function');
});
it('should expose `define`', function() {
assert(typeof group.define === 'function');
});
});
describe('instance', function() {
beforeEach(function() {
group = new Group();
});
it('should expose options:', function() {
assert(typeof group.options === 'object');
});
it('should set a value on the instance:', function() {
group.set('a', 'b');
assert(group.a === 'b');
});
it('should get a value from the instance:', function() {
group.set('a', 'b');
assert(group.get('a') === 'b');
});
});
describe('get', function() {
it('should get a normal value when not an array', function() {
var group = new Group({
'foo': {
items: [1, 2, 3]
}
});
assert.deepEqual(group.get('foo'), {
items: [1, 2, 3]
});
});
it('should get an instance of List when value is an array', function() {
var group = new Group({
'foo': {
items: [{
path: 'one.hbs'
}, {
path: 'two.hbs'
}, {
path: 'three.hbs'
}]
}
});
var list = group.get('foo.items');
assert(list instanceof List);
assert.deepEqual(list.items.length, 3);
});
it('should throw an error when trying to use a List method on a non List value', function() {
(function() {
var group = new Group({
'foo': {
items: [1, 2, 3]
}
});
var foo = group.get('foo');
foo.paginate();
}).should.throw('paginate can only be used with an array of `List` items.');
});
it('should not override properties already existing on non List values', function(cb) {
var group = new Group({
'foo': {
items: [1, 2, 3],
paginate: function() {
assert(true);
cb();
}
}
});
var foo = group.get('foo');
foo.paginate();
});
});
describe('use', function() {
beforeEach(function() {
group = new Group();
});
it('should use plugins on a group:', function() {
group.set('one', {
contents: new Buffer('aaa')
});
group.set('two', {
contents: new Buffer('zzz')
});
group
.use(function(group) {
group.options = {};
})
.use(function(group) {
group.options.foo = 'bar';
})
.use(function() {
this.set('one', 'two');
});
assert(group.one === 'two');
assert(group.options.foo === 'bar');
});
});
});