|
349 | 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 | 350 | test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
|
351 | 351 | test.done();
|
| 352 | + }, |
| 353 | + 'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier between' : function(test){ |
| 354 | + //arrange |
| 355 | + var fs = require('fs-extra'); |
| 356 | + var pattern_assembler = new pa(); |
| 357 | + |
| 358 | + var pl = {}; |
| 359 | + pl.config = {}; |
| 360 | + pl.data = {}; |
| 361 | + pl.data.link = {}; |
| 362 | + pl.config.debug = false; |
| 363 | + pl.patterns = []; |
| 364 | + var patterns_dir = './test/files/_patterns'; |
| 365 | + |
| 366 | + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); |
| 367 | + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); |
| 368 | + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
| 369 | + |
| 370 | + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/09-bookend.mustache', '00-test', '09-bookend.mustache'); |
| 371 | + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/09-bookend.mustache', 'utf8'); |
| 372 | + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); |
| 373 | + |
| 374 | + pl.patterns.push(atomPattern); |
| 375 | + pl.patterns.push(bookendPattern); |
| 376 | + |
| 377 | + //act |
| 378 | + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/09-bookend.mustache', pl, {}); |
| 379 | + |
| 380 | + //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) |
| 381 | + 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 {{styleModifier}}"> {{message}} </span> </div>'; |
| 382 | + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); |
| 383 | + test.done(); |
| 384 | + }, |
| 385 | + 'processPatternRecursive - correctly ignores a partial without a style modifier when the same partial later has a style modifier and pattern parameters' : function(test){ |
| 386 | + //arrange |
| 387 | + var fs = require('fs-extra'); |
| 388 | + var pattern_assembler = new pa(); |
| 389 | + |
| 390 | + var pl = {}; |
| 391 | + pl.config = {}; |
| 392 | + pl.data = {}; |
| 393 | + pl.data.link = {}; |
| 394 | + pl.config.debug = false; |
| 395 | + pl.patterns = []; |
| 396 | + var patterns_dir = './test/files/_patterns'; |
| 397 | + |
| 398 | + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); |
| 399 | + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); |
| 400 | + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
| 401 | + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); |
| 402 | + |
| 403 | + var mixedPattern = new object_factory.oPattern('test/files/_patterns/00-test/07-mixed-params.mustache', '00-test', '07-mixed-params.mustache'); |
| 404 | + mixedPattern.template = fs.readFileSync(patterns_dir + '/00-test/07-mixed-params.mustache', 'utf8'); |
| 405 | + mixedPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(mixedPattern); |
| 406 | + mixedPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(mixedPattern); |
| 407 | + |
| 408 | + pl.patterns.push(atomPattern); |
| 409 | + pl.patterns.push(mixedPattern); |
| 410 | + |
| 411 | + //act |
| 412 | + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/07-mixed-params.mustache', pl, {}); |
| 413 | + |
| 414 | + //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) |
| 415 | + var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> 2 </span> <span class="test_base test_3"> 3 </span> <span class="test_base test_4"> 4 </span> </div>'; |
| 416 | + test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); |
| 417 | + test.done(); |
| 418 | + }, |
| 419 | + 'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier and pattern parameters between' : function(test){ |
| 420 | + //arrange |
| 421 | + var fs = require('fs-extra'); |
| 422 | + var pattern_assembler = new pa(); |
| 423 | + |
| 424 | + var pl = {}; |
| 425 | + pl.config = {}; |
| 426 | + pl.data = {}; |
| 427 | + pl.data.link = {}; |
| 428 | + pl.config.debug = false; |
| 429 | + pl.patterns = []; |
| 430 | + var patterns_dir = './test/files/_patterns'; |
| 431 | + |
| 432 | + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); |
| 433 | + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); |
| 434 | + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
| 435 | + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); |
| 436 | + |
| 437 | + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/08-bookend-params.mustache', '00-test', '08-bookend-params.mustache'); |
| 438 | + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/08-bookend-params.mustache', 'utf8'); |
| 439 | + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); |
| 440 | + bookendPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(bookendPattern); |
| 441 | + |
| 442 | + pl.patterns.push(atomPattern); |
| 443 | + pl.patterns.push(bookendPattern); |
| 444 | + |
| 445 | + //act |
| 446 | + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/08-bookend-params.mustache', pl, {}); |
| 447 | + |
| 448 | + //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) |
| 449 | + var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> 2 </span> <span class="test_base test_3"> 3 </span> <span class="test_base {{styleModifier}}"> {{message}} </span> </div>'; |
| 450 | + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); |
| 451 | + test.done(); |
352 | 452 | }
|
353 | 453 | };
|
354 | 454 | }());
|
0 commit comments