Skip to content

Commit 98b2b4b

Browse files
committed
unit tests to confirm correct functioning of hidden mustache templates; unit test to confirm bug in hbs engine; factor out fakePatternLab() into a new module, test_utils.js
1 parent a8542fd commit 98b2b4b

File tree

7 files changed

+79
-2
lines changed

7 files changed

+79
-2
lines changed

test/engine_handlebars_tests.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ exports['engine_handlebars'] = {
181181
testFindPartials(test, [
182182
'{{#> myPartial }}'
183183
]);
184+
},
185+
'hidden handlebars patterns can be called by their nice names' : function(test){
186+
const util = require('./util/test_utils.js');
187+
188+
//arrange
189+
const testPatternsPath = path.resolve(__dirname, 'files', '_handlebars-test-patterns');
190+
const pl = util.fakePatternLab(testPatternsPath);
191+
var pattern_assembler = new pa();
192+
193+
var hiddenPatternPath = path.join('00-atoms', '00-global', '_00-hidden.hbs');
194+
var hiddenPattern = pattern_assembler.process_pattern_iterative(hiddenPatternPath, pl);
195+
pattern_assembler.process_pattern_recursive(hiddenPatternPath, pl);
196+
197+
var testPatternPath = path.join('00-molecules', '00-global', '00-hidden-pattern-tester.hbs');
198+
var testPattern = pattern_assembler.process_pattern_iterative(testPatternPath, pl);
199+
pattern_assembler.process_pattern_recursive(testPatternPath, pl);
200+
201+
//act
202+
test.equals(testPattern.render(), 'Hello there!\nHere\'s the hidden atom: [This is the hidden atom]\n');
203+
204+
//assert
205+
// test.equals(patternlab.patterns.length, 1);
206+
// test.equals(patternlab.partials['test-bar'] != undefined, true);
207+
// test.equals(patternlab.partials['test-bar'], 'bar');
208+
test.done();
184209
}
185210
};
186211

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I'm the hidden atom
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Here's the hidden atom: [{{> atoms-hidden}}]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Hello there!
2-
Here's the hidden atom: [{{> test-_00-hidden-pattern}}]
2+
Here's the hidden atom: [{{> test-hidden-pattern}}]

test/pattern_assembler_tests.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,27 @@
636636
test.equals(patternlab.partials['test-bar'] != undefined, true);
637637
test.equals(patternlab.partials['test-bar'], 'bar');
638638
test.done();
639-
}
639+
},
640+
'hidden patterns can be called by their nice names' : function(test){
641+
const util = require('./util/test_utils.js');
642+
643+
//arrange
644+
const testPatternsPath = path.resolve(__dirname, 'files', '_patterns');
645+
const pl = util.fakePatternLab(testPatternsPath);
646+
var pattern_assembler = new pa();
647+
648+
//act
649+
var hiddenPatternPath = path.join('00-test', '_00-hidden-pattern.mustache');
650+
var hiddenPattern = pattern_assembler.process_pattern_iterative(hiddenPatternPath, pl);
651+
pattern_assembler.process_pattern_recursive(hiddenPatternPath, pl);
652+
653+
var testPatternPath = path.join('00-test', '15-hidden-pattern-tester.mustache');
654+
var testPattern = pattern_assembler.process_pattern_iterative(testPatternPath, pl);
655+
pattern_assembler.process_pattern_recursive(testPatternPath, pl);
656+
657+
//assert
658+
test.equals(testPattern.render(), 'Hello there!\nHere\'s the hidden atom: [This is the hidden atom]\n');
659+
test.done();
660+
}
640661
};
641662
})();

test/util/test_utils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
module.exports = {
4+
5+
// fake pattern lab constructor:
6+
// sets up a fake patternlab object, which is needed by the pattern processing
7+
// apparatus.
8+
fakePatternLab: (testPatternsPath) => {
9+
var fpl = {
10+
partials: {},
11+
patterns: [],
12+
footer: '',
13+
header: '',
14+
listitems: {},
15+
listItemArray: [],
16+
data: {
17+
link: {}
18+
},
19+
config: require('../../patternlab-config.json'),
20+
package: {}
21+
};
22+
23+
// patch the pattern source so the pattern assembler can correctly determine
24+
// the "subdir"
25+
fpl.config.paths.source.patterns = testPatternsPath;
26+
27+
return fpl;
28+
}
29+
};

0 commit comments

Comments
 (0)