Skip to content

Commit ffc80cb

Browse files
committed
a unit test to cover half of #190
1 parent 8fb7eea commit ffc80cb

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="test_group">
2+
{{> test-styled-atom }}
3+
{{> test-styled-atom:test_2 }}
4+
{{> test-styled-atom:test_3 }}
5+
{{> test-styled-atom:test_4 }}
6+
</div>

test/pattern_assembler_tests.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@
303303
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
304304
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
305305

306-
307306
var groupPattern = new object_factory.oPattern('test/files/_patterns/00-test/04-group.mustache', '00-test', '04-group.mustache');
308307
groupPattern.template = fs.readFileSync(patterns_dir + '/00-test/04-group.mustache', 'utf8');
309308
groupPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(groupPattern);
@@ -313,10 +312,43 @@
313312

314313
//act
315314
pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/04-group.mustache', pl, {});
315+
316316
//assert
317317
var expectedValue = '<div class="test_group"> <span class="test_base test_1"> {{message}} </span> <span class="test_base test_2"> {{message}} </span> <span class="test_base test_3"> {{message}} </span> <span class="test_base test_4"> {{message}} </span> </div>';
318318
test.equals(groupPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
319319
test.done();
320+
},
321+
'processPatternRecursive - correctly ignores a partial without a style modifier when the same partial later has a style modifier' : function(test){
322+
//arrange
323+
var fs = require('fs-extra');
324+
var pattern_assembler = new pa();
325+
326+
var pl = {};
327+
pl.config = {};
328+
pl.data = {};
329+
pl.data.link = {};
330+
pl.config.debug = false;
331+
pl.patterns = [];
332+
var patterns_dir = './test/files/_patterns';
333+
334+
var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache');
335+
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
336+
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
337+
338+
var mixedPattern = new object_factory.oPattern('test/files/_patterns/00-test/06-mixed.mustache', '00-test', '06-mixed.mustache');
339+
mixedPattern.template = fs.readFileSync(patterns_dir + '/00-test/06-mixed.mustache', 'utf8');
340+
mixedPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(mixedPattern);
341+
342+
pl.patterns.push(atomPattern);
343+
pl.patterns.push(mixedPattern);
344+
345+
//act
346+
pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/06-mixed.mustache', pl, {});
347+
348+
//assert. here we expect {{styleModifier}} to be in the first group, since it was not replaced by anything. rendering with data will then remove this (correctly)
349+
var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> {{message}} </span> <span class="test_base test_3"> {{message}} </span> <span class="test_base test_4"> {{message}} </span> </div>';
350+
test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
351+
test.done();
320352
}
321353
};
322354
}());

0 commit comments

Comments
 (0)