From 9cd187b607f9a474f022d6ddeb5d330e004682f8 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 25 Nov 2015 00:40:35 -0600 Subject: [PATCH] additional tests to cover styleModifier / pattern Parameter relationship fixes #190 --- CHANGELOG | 1 + builder/parameter_hunter.js | 14 +-- .../00-test/07-mixed-params.mustache | 6 ++ .../00-test/08-bookend-params.mustache | 6 ++ .../_patterns/00-test/09-bookend.mustache | 6 ++ test/pattern_assembler_tests.js | 100 ++++++++++++++++++ 6 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 test/files/_patterns/00-test/07-mixed-params.mustache create mode 100644 test/files/_patterns/00-test/08-bookend-params.mustache create mode 100644 test/files/_patterns/00-test/09-bookend.mustache diff --git a/CHANGELOG b/CHANGELOG index 1a65bc614..6e29f56f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT. PL-node-v0.15.1 - FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it. - ADD: Support multiple styleModifier classes using the | pipe syntax +- FIX: Resolve issue with styleModifiers not being applied correctly when mixed with pattern parameters - THX: Thanks @theorise for the issue reports! PL-node-v0.15.0 diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 5b21008a4..4732ad0a5 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.1 - 2015 - * +/* + * patternlab-node - v0.15.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -28,6 +28,8 @@ //find the partial's name and retrieve it var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0]; var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); + //if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190 + partialPattern.extendedTemplate = partialPattern.template; if(patternlab.config.debug){ console.log('found patternParameters for ' + partialName); diff --git a/test/files/_patterns/00-test/07-mixed-params.mustache b/test/files/_patterns/00-test/07-mixed-params.mustache new file mode 100644 index 000000000..408b3f1e4 --- /dev/null +++ b/test/files/_patterns/00-test/07-mixed-params.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2(message: '2') }} + {{> test-styled-atom:test_3(message: '3') }} + {{> test-styled-atom:test_4(message: '4') }} +
diff --git a/test/files/_patterns/00-test/08-bookend-params.mustache b/test/files/_patterns/00-test/08-bookend-params.mustache new file mode 100644 index 000000000..d2d0b4081 --- /dev/null +++ b/test/files/_patterns/00-test/08-bookend-params.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2(message: '2') }} + {{> test-styled-atom:test_3(message: '3') }} + {{> test-styled-atom }} +
diff --git a/test/files/_patterns/00-test/09-bookend.mustache b/test/files/_patterns/00-test/09-bookend.mustache new file mode 100644 index 000000000..74fc3451b --- /dev/null +++ b/test/files/_patterns/00-test/09-bookend.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2 }} + {{> test-styled-atom:test_3 }} + {{> test-styled-atom}} +
diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index af082fda5..87a149c24 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -349,6 +349,106 @@ var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); test.done(); + }, + 'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier between' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/09-bookend.mustache', '00-test', '09-bookend.mustache'); + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/09-bookend.mustache', 'utf8'); + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(bookendPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/09-bookend.mustache', pl, {}); + + //assert. here we expect {{styleModifier}} to be in the first and last group, since it was not replaced by anything. rendering with data will then remove this (correctly) + var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, + 'processPatternRecursive - correctly ignores a partial without a style modifier when the same partial later has a style modifier and pattern parameters' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); + + var mixedPattern = new object_factory.oPattern('test/files/_patterns/00-test/07-mixed-params.mustache', '00-test', '07-mixed-params.mustache'); + mixedPattern.template = fs.readFileSync(patterns_dir + '/00-test/07-mixed-params.mustache', 'utf8'); + mixedPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(mixedPattern); + mixedPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(mixedPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(mixedPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/07-mixed-params.mustache', pl, {}); + + //assert. here we expect {{styleModifier}} to be in the first span, since it was not replaced by anything. rendering with data will then remove this (correctly) + var expectedValue = '
{{message}} 2 3 4
'; + test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, + 'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier and pattern parameters between' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); + + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/08-bookend-params.mustache', '00-test', '08-bookend-params.mustache'); + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/08-bookend-params.mustache', 'utf8'); + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); + bookendPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(bookendPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(bookendPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/08-bookend-params.mustache', pl, {}); + + //assert. here we expect {{styleModifier}} to be in the first and last span, since it was not replaced by anything. rendering with data will then remove this (correctly) + var expectedValue = '
{{message}} 2 3 {{message}}
'; + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); + test.done(); } }; }());