@@ -527,7 +527,7 @@ tap.test('resetUIBuilderState - reset global objects', function(test) {
527527} ) ;
528528
529529tap . test (
530- 'buildViewAllPages - adds viewall page for each type and subtype' ,
530+ 'buildViewAllPages - adds viewall page for each type and subtype NOT! for flat patterns ' ,
531531 function ( test ) {
532532 //arrange
533533 const mainPageHeadHtml = '<head></head>' ;
@@ -554,6 +554,76 @@ tap.test(
554554
555555 const styleguidePatterns = ui . groupPatterns ( patternlab , uikit ) ;
556556
557+ //act
558+ ui . buildViewAllPages (
559+ mainPageHeadHtml ,
560+ patternlab ,
561+ styleguidePatterns ,
562+ uikit
563+ ) . then ( allPatterns => {
564+ // assert
565+ // this was a nuanced one. buildViewAllPages() had return false; statements
566+ // within _.forOwn(...) loops, causing premature termination of the entire loop
567+ // when what was intended was a continue
568+ // we expect 10 here because:
569+ // - foo.mustache is flat and therefore does not have a viewall page
570+ // - the colors.mustache files make 6
571+ // - patternSubType1 and patternSubType2 make 8
572+ // - the general view all page make 9
573+ // while most of that heavy lifting occurs inside groupPatterns and not buildViewAllPages,
574+ // it's important to ensure that this method does not get prematurely terminated
575+ // we choose to do that by checking it's return number of patterns
576+
577+ const uniquePatterns = ui . uniqueAllPatterns ( allPatterns , patternlab ) ;
578+
579+ /**
580+ * - view-patternType1-all
581+ * -- viewall-patternType1-patternSubType1
582+ * --- blue
583+ * --- red
584+ * --- yellow
585+ * -- viewall-patternType1-patternSubType2
586+ * --- black
587+ * --- grey
588+ * --- white
589+ */
590+ test . equals ( uniquePatterns . length , 9 , '3 viewall pages should be added' ) ;
591+
592+ test . end ( ) ;
593+ } ) ;
594+ }
595+ ) ;
596+
597+ tap . test (
598+ 'buildViewAllPages - adds viewall page for each type and subtype FOR! flat patterns' ,
599+ function ( test ) {
600+ //arrange
601+ const mainPageHeadHtml = '<head></head>' ;
602+ const patternlab = createFakePatternLab ( {
603+ patterns : [ ] ,
604+ patternGroups : { } ,
605+ subtypePatterns : { } ,
606+ footer : { } ,
607+ userFoot : { } ,
608+ cacheBuster : 1234 ,
609+ } ) ;
610+
611+ patternlab . config . renderFlatPatternsOnViewAllPages = true ;
612+
613+ patternlab . patterns . push (
614+ //this flat pattern is found and causes trouble for the rest of the crew
615+ new Pattern ( '00-test/foo.mustache' ) ,
616+ new Pattern ( 'patternType1/patternSubType1/blue.mustache' ) ,
617+ new Pattern ( 'patternType1/patternSubType1/red.mustache' ) ,
618+ new Pattern ( 'patternType1/patternSubType1/yellow.mustache' ) ,
619+ new Pattern ( 'patternType1/patternSubType2/black.mustache' ) ,
620+ new Pattern ( 'patternType1/patternSubType2/grey.mustache' ) ,
621+ new Pattern ( 'patternType1/patternSubType2/white.mustache' )
622+ ) ;
623+ ui . resetUIBuilderState ( patternlab ) ;
624+
625+ const styleguidePatterns = ui . groupPatterns ( patternlab , uikit ) ;
626+
557627 //act
558628 ui . buildViewAllPages (
559629 mainPageHeadHtml ,
@@ -569,6 +639,8 @@ tap.test(
569639 // - foo.mustache is flat and therefore does not have a viewall page
570640 // - the colors.mustache files make 6
571641 // - patternSubType1 and patternSubType2 make 8
642+ // - the general view all page make 9
643+ // - the view-all page of test and test-foo make 11
572644 // while most of that heavy lifting occurs inside groupPatterns and not buildViewAllPages,
573645 // it's important to ensure that this method does not get prematurely terminated
574646 // we choose to do that by checking it's return number of patterns
0 commit comments