Passed
Push — master ( beba88...91d9d9 )
by Björn
02:26
created

test/test.00.patternlibrary.js (4 issues)

1
import Patternlibrary from '..';
2
3
var extend = require('deep-extend');
4
var expect = require('chai').expect;
5
6
describe('Patternlibrary instanciation and configuration:', function() {
7
8
	describe('Patternlibrary constructor', function() {
9
	    it('creates a new instance of Patternlibrary', function() {
10
		    var p = new Patternlibrary.Patternlibrary();
11
		    expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
12
	    });
13
	
14
	    it('sets blank defaults for config settings', function() {
15
		    var p = new Patternlibrary.Patternlibrary();
16
		
17
		    expect(p.options).to.be.an('object');
18
		    expect(p.searchOptions).to.be.an('object');
19
		    expect(p.searchOptions).to.have.all.keys(['extra', 'sort', 'pageTypes']);
20
		    expect(p.adapters).to.be.an('object');
21
		    expect(p.data).to.be.an('object');
22
		    expect(p.data.patterns).to.be.an('object');
23
		    expect(p.data.categories).to.be.an('object');
24
		    expect(p.template).to.be.null;
0 ignored issues
show
The result of the property access to expect(p.template).to.be.null is not used.
Loading history...
25
26
		    expect(p.handlebars).to.be.an('object');
27
28
		    expect(p.markdown).to.be.an('object');
29
		    
30
	    });
31
	
32
	    it('initalizes Handlebars instance', function() {
33
		    var p = new Patternlibrary.Patternlibrary();
34
		
35
36
	        expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
37
38
		    expect(p.handlebars).to.be.an('object');
39
		    
40
	    });
41
	
42
	    it('initalizes MarkdownIt instance', function() {
43
		    var p = new Patternlibrary.Patternlibrary();
44
45
	        expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
46
47
		    expect(p.markdown).to.be.an('object');
48
		    
49
	    });
50
	    
51
	});
52
	
53
	describe('Patternlibrary.config()', function() {
54
		var defaults = require('../lib/config/defaults');
55
		
56
	    it('merges default and user configuration objects', function() {
57
	        var p = new Patternlibrary.Patternlibrary();
58
	    	
59
	    	p.config({
60
	    		'my-key': 'my-value',
61
	    		somekey : 'some value'
62
	    	});
63
64
	    	expect(p.options).to.be.an('object');
65
	        expect(p.options).to.have.a.property('my-key');
66
	    	expect(p.options['my-key']).to.equal('my-value');
67
	        expect(p.options).to.have.a.property('somekey');
68
	    	expect(p.options.somekey).to.equal('some value');
69
	    	
70
	    });
71
		
72
	    it('throws error if the "partials" source path option is missing or empty', function() {
73
	        var p = new Patternlibrary.Patternlibrary();
74
	        var cfg = extend({}, defaults);
75
	        
76
	    	cfg.partials = null;
77
	        expect(function() { p.config(cfg); }).to.throw(Error);
78
	        
79
	    	cfg.partials = '';
80
	        expect(function() { p.config(cfg); }).to.throw(Error);
81
	    });
82
		
83
	    it('throws error if the destination directory "dest" option is missing or empty', function() {
84
	        var p = new Patternlibrary.Patternlibrary();
85
	        var cfg = extend({}, defaults);
86
	    	cfg.dest = null;
87
	    	
88
	        expect(function() {
89
	            p.config(cfg);
90
	        }).to.throw(Error);
91
	        
92
	    	cfg.dest = '';
93
	        expect(function() { p.config(cfg); }).to.throw(Error);
94
	    });
95
		
96
	    it('throws error if the URL "basepath" sub-path option is missing or empty', function() {
97
	        var p = new Patternlibrary.Patternlibrary();
98
	        var cfg = extend({}, defaults);
99
	    	cfg.basepath = null;
100
	    	
101
	        expect(function() {
102
	            p.config(cfg);
103
	        }).to.throw(Error);
104
	        
105
	    	cfg.basepath = '';
106
	        expect(function() { p.config(cfg); }).to.throw(Error);
107
	    });
108
		
109
	    it('throws error if the URL "patternspath" sub-path option is missing or empty', function() {
110
	        var p = new Patternlibrary.Patternlibrary();
111
	        var cfg = extend({}, defaults);
112
	    	cfg.patternspath = null;
113
	    	
114
	        expect(function() {
115
	            p.config(cfg);
116
	        }).to.throw(Error);
117
	        
118
	    	cfg.patternspath = '';
119
	        expect(function() { p.config(cfg); }).to.throw(Error);
120
	    });
121
		
122
	    it('throws error if the URL "categoriespath" sub-path option is missing or empty', function() {
123
	        var p = new Patternlibrary.Patternlibrary();
124
	        var cfg = extend({}, defaults);
125
	    	cfg.categoriespath = null;
126
	    	
127
	        expect(function() {
128
	            p.config(cfg);
129
	        }).to.throw(Error);
130
	        
131
	    	cfg.categoriespath = '';
132
	        expect(function() { p.config(cfg); }).to.throw(Error);
133
	    });
134
		
135
	    it('throws error if the pattern\'s "pattern" option is missing or empty', function() {
136
	        var p = new Patternlibrary.Patternlibrary();
137
	        var cfg = extend({}, defaults);
138
	    	cfg.pattern = null;
139
	    	
140
	        expect(function() {
141
	            p.config(cfg);
142
	        }).to.throw(Error);
143
	        
144
	    });
145
		
146
	    it('throws error if the pattern\'s "dirs" option is missing or empty', function() {
147
	        var p = new Patternlibrary.Patternlibrary();
148
	        var cfg = extend({}, defaults);
149
	    	cfg.pattern.dirs = null;
150
	    	
151
	        expect(function() {
152
	            p.config(cfg);
153
	        }).to.throw(Error);
154
	        
155
	    	cfg.pattern.dirs = '';
156
	        expect(function() { p.config(cfg); }).to.throw(Error);
157
	    });
158
		
159
	    it('throws error if the pattern\'s "atoms" sub-path option is missing or empty', function() {
160
	        var p = new Patternlibrary.Patternlibrary();
161
	        var cfg = extend({}, defaults);
162
	    	cfg.pattern.dirs.atoms = null;
163
	    	
164
	        expect(function() {
165
	            p.config(cfg);
166
	        }).to.throw(Error);
167
	        
168
	    	cfg.pattern.dirs.atoms = '';
169
	        expect(function() { p.config(cfg); }).to.throw(Error);
170
	    });
171
		
172
	    it('throws error if the pattern\'s "molecules" sub-path option is missing or empty', function() {
173
	        var p = new Patternlibrary.Patternlibrary();
174
	        var cfg = extend({}, defaults);
175
	    	cfg.pattern.dirs.molecules = null;
176
	    	
177
	        expect(function() {
178
	            p.config(cfg);
179
	        }).to.throw(Error);
180
	        
181
	    	cfg.pattern.dirs.molecules = '';
182
	        expect(function() { p.config(cfg); }).to.throw(Error);
183
	    });
184
		
185
	    it('throws error if the pattern\'s "organisms" sub-path option is missing or empty', function() {
186
	        var p = new Patternlibrary.Patternlibrary();
187
	        var cfg = extend({}, defaults);
188
	    	cfg.pattern.dirs.organisms = null;
189
	    	
190
	        expect(function() {
191
	            p.config(cfg);
192
	        }).to.throw(Error);
193
	        
194
	    	cfg.pattern.dirs.organisms = '';
195
	        expect(function() { p.config(cfg); }).to.throw(Error);
196
	    });
197
		
198
	    it('throws error if the pattern\'s "templates" sub-path option is missing or empty', function() {
199
	        var p = new Patternlibrary.Patternlibrary();
200
	        var cfg = extend({}, defaults);
201
	    	cfg.pattern.dirs.templates = null;
202
	    	
203
	        expect(function() {
204
	            p.config(cfg);
205
	        }).to.throw(Error);
206
	        
207
	    	cfg.pattern.dirs.templates = '';
208
	        expect(function() { p.config(cfg); }).to.throw(Error);
209
	    });
210
		
211
	    it('throws error if the pattern\'s "pages" sub-path option is missing or empty', function() {
212
	        var p = new Patternlibrary.Patternlibrary();
213
	        var cfg = extend({}, defaults);
214
	    	cfg.pattern.dirs.pages = null;
215
	    	
216
	        expect(function() {
217
	            p.config(cfg);
218
	        }).to.throw(Error);
219
	        
220
	    	cfg.pattern.dirs.pages = '';
221
	        expect(function() { p.config(cfg); }).to.throw(Error);
222
	    });
223
		
224
	    it('throws error if the pattern\'s "searchpath" sub-path pattern option is missing or empty', function() {
225
	        var p = new Patternlibrary.Patternlibrary();
226
	        var cfg = extend({}, defaults);
227
	    	cfg.pattern.searchpath = null;
228
	    	
229
	        expect(function() {
230
	            p.config(cfg);
231
	        }).to.throw(Error);
232
	        
233
	    	cfg.pattern.searchpath = '';
234
	        expect(function() { p.config(cfg); }).to.throw(Error);
235
	    });
236
		
237
	    it('throws error if the pattern\'s "target" filename option is missing or empty', function() {
238
	        var p = new Patternlibrary.Patternlibrary();
239
	        var cfg = extend({}, defaults);
240
	    	cfg.pattern.target = null;
241
	    	
242
	        expect(function() {
243
	            p.config(cfg);
244
	        }).to.throw(Error);
245
	        
246
	    	cfg.pattern.target = '';
247
	        expect(function() { p.config(cfg); }).to.throw(Error);
248
	    });
249
	    
250
	    
251
	});
252
	
253
	describe('Patternlibrary.adapter()', function() {
254
	    it('loads built-in adapters', function() {
255
	        var p = new Patternlibrary.Patternlibrary();
256
	        p = p.adapter('sass');
257
	    
258
	        expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
259
	        expect(p.adapters).to.have.a.property('sass');
260
	        expect(p.adapters.sass.config).to.exist;
0 ignored issues
show
The result of the property access to expect(p.adapters.sass.config).to.exist is not used.
Loading history...
261
	    
262
	    });
263
	
264
	    it('throws an error if you try to load a non-existant built-in adapter', function() {
265
	        var p = new Patternlibrary.Patternlibrary();
266
	    
267
	        expect(function() {
268
	            p.adapter('kitten');
269
	        }).to.throw(Error);
270
	    });
271
	
272
	    it('loads custom adapters', function() {
273
	    var p = new Patternlibrary.Patternlibrary();
274
	    p = p.adapter('custom', function() {});
275
	
276
	    expect(p.adapters).to.have.a.property('custom');
277
	        expect(p.adapters.custom).to.be.a('function');
278
	    });
279
	
280
	    it('throws an error if you use a reserved keyword as an adapter name', function() {
281
	        var p = new Patternlibrary.Patternlibrary();
282
	    
283
	        expect(function() {
284
	            p.adapter('docs', function() {});
285
	        }).to.throw(Error);
286
	    });
287
	
288
	    it('throws an error if you try to pass something other than a function as an adapter', function() {
289
	        var s = new Patternlibrary.Patternlibrary();
0 ignored issues
show
The variable s seems to be never used. Consider removing it.
Loading history...
290
	    
291
	        expect(function() {
292
	            p.adapter('docs', 'kittens');
0 ignored issues
show
The variable p seems to be never declared. If this is a global, consider adding a /** global: p */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
293
	        }).to.throw(Error);
294
	    });
295
	});
296
297
});
298