Skip to content

Commit 8fb7eea

Browse files
committed
Unit test to cover correct application of multiple partials with differing style modifiers
1 parent 157a06e commit 8fb7eea

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

builder/pattern_assembler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207

208208
//do something with the regular old partials
209209
for(i = 0; i < foundPatternPartials.length; i++){
210-
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
210+
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
211211

212212
var partialPath;
213213

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<span class="test_base {{styleModifier}}">
2+
{{message}}
3+
</span>
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:test_1 }}
3+
{{> test-styled-atom:test_2 }}
4+
{{> test-styled-atom:test_3 }}
5+
{{> test-styled-atom:test_4 }}
6+
</div>
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:test_1(message: "1" ) }}
3+
{{> test-styled-atom:test_2(message: "2" ) }}
4+
{{> test-styled-atom:test_3(message: "3" ) }}
5+
{{> test-styled-atom:test_4(message: "4" ) }}
6+
</div>

test/pattern_assembler_tests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33

44
var pa = require('../builder/pattern_assembler');
5+
var object_factory = require('../builder/object_factory');
56

67
exports['pattern_assembler'] = {
78
'find_pattern_partials finds partials' : function(test){
@@ -283,6 +284,38 @@
283284
//test that 00-foo.mustache included partial 01-bar.mustache
284285
test.equals(fooExtended, 'bar');
285286

287+
test.done();
288+
},
289+
'processPatternRecursive - correctly replaces all stylemodifiers when multiple duplicate patterns with different stylemodifiers found' : function(test){
290+
//arrange
291+
var fs = require('fs-extra');
292+
var pattern_assembler = new pa();
293+
294+
var pl = {};
295+
pl.config = {};
296+
pl.data = {};
297+
pl.data.link = {};
298+
pl.config.debug = false;
299+
pl.patterns = [];
300+
var patterns_dir = './test/files/_patterns';
301+
302+
var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache');
303+
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
304+
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
305+
306+
307+
var groupPattern = new object_factory.oPattern('test/files/_patterns/00-test/04-group.mustache', '00-test', '04-group.mustache');
308+
groupPattern.template = fs.readFileSync(patterns_dir + '/00-test/04-group.mustache', 'utf8');
309+
groupPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(groupPattern);
310+
311+
pl.patterns.push(atomPattern);
312+
pl.patterns.push(groupPattern);
313+
314+
//act
315+
pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/04-group.mustache', pl, {});
316+
//assert
317+
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>';
318+
test.equals(groupPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
286319
test.done();
287320
}
288321
};

0 commit comments

Comments
 (0)