|
32 | 32 | } |
33 | 33 |
|
34 | 34 |
|
| 35 | + // function for testing sets of partials |
| 36 | + function testFindPartials(test, partialTests) { |
| 37 | + test.expect(partialTests.length + 1); |
| 38 | + |
| 39 | + // setup current pattern from what we would have during execution |
| 40 | + // docs on partial syntax are here: |
| 41 | + // http://patternlab.io/docs/pattern-including.html |
| 42 | + var currentPattern = object_factory.oPattern.create( |
| 43 | + '/home/fakeuser/pl/source/_patterns/01-molecules/00-testing/00-test-mol.hbs', // abspath |
| 44 | + '01-molecules\\00-testing', // subdir |
| 45 | + '00-test-mol.hbs', // filename, |
| 46 | + null, // data |
| 47 | + { |
| 48 | + template: partialTests.join() |
| 49 | + } |
| 50 | + ); |
| 51 | + |
| 52 | + // act |
| 53 | + var results = currentPattern.findPartials(); |
| 54 | + |
| 55 | + // assert |
| 56 | + test.equals(results.length, partialTests.length); |
| 57 | + partialTests.forEach(function(testString, index) { |
| 58 | + test.equals(results[index], testString); |
| 59 | + }); |
| 60 | + |
| 61 | + test.done(); |
| 62 | + } |
| 63 | + |
35 | 64 | exports['engine_handlebars'] = { |
36 | 65 | 'hello world handlebars pattern renders': function (test) { |
37 | 66 | test.expect(1); |
|
83 | 112 | test.equals(helloWorldsPattern.render(), 'Hello world!\n and Hello world!\n\n'); |
84 | 113 | test.done(); |
85 | 114 | }, |
86 | | - // GTP warning: unchanged copypasta from mustache engine |
87 | 115 | 'find_pattern_partials finds partials': function(test){ |
88 | | - // NOTES from GTP: |
89 | | - // it's nice to have so much test coverage, but it retrospect, I'm not |
90 | | - // happy with the structure I wound up with in this test; it's too |
91 | | - // difficult to add test cases and test failure reporting is not very |
92 | | - // granular. |
93 | | - |
94 | | - test.expect(16); |
95 | | - |
96 | | - // setup current pattern from what we would have during execution |
97 | | - // docs on partial syntax are here: |
98 | | - // http://patternlab.io/docs/pattern-including.html |
99 | | - var currentPattern = object_factory.oPattern.create( |
100 | | - '/home/fakeuser/pl/source/_patterns/01-molecules/00-testing/00-test-mol.hbs', // abspath |
101 | | - '01-molecules\\00-testing', // subdir |
102 | | - '00-test-mol.hbs', // filename, |
103 | | - null, // data |
104 | | - { |
105 | | - template: "{{> molecules-comment-header}}asdfasdf" + |
106 | | - "{{> molecules-comment-header}}" + |
107 | | - "{{> \n molecules-comment-header\n}}" + |
108 | | - "{{> }}" + |
109 | | - "{{> molecules-weird-spacing }}" + |
110 | | - "{{> molecules-ba_d-cha*rs }}" + |
111 | | - "{{> molecules-single-comment(description: 'A life isn\\'t like a garden. Perfect moments can be had, but not preserved, except in memory.') }}" + |
112 | | - '{{> molecules-single-comment(description: "A life is like a \\"garden\\". Perfect moments can be had, but not preserved, except in memory.") }}' + |
113 | | - "{{> molecules-single-comment:foo }}" + |
114 | | - // verbose partial syntax, introduced in v0.12.0, with file extension |
115 | | - "{{> 01-molecules/06-components/03-comment-header.hbs }}" + |
116 | | - "{{> 01-molecules/06-components/02-single-comment.hbs(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}" + |
117 | | - "{{> molecules-single-comment:foo }}" + |
118 | | - "{{>atoms-error(message: 'That\\'s no moon...')}}" + |
119 | | - '{{>atoms-error(message: \'That\\\'s no moon...\')}}' + |
120 | | - "{{> 00-atoms/00-global/ }}" + |
121 | | - // verbose partial syntax, introduced in v0.12.0, no file extension |
122 | | - "{{> 00-atoms/00-global/06-test }}" + |
123 | | - "{{> molecules-single-comment:foo_1 }}" + |
124 | | - "{{> molecules-single-comment:foo-1 }}" |
125 | | - } |
126 | | - ); |
127 | | - |
128 | | - var results = currentPattern.findPartials(); |
129 | | - console.log(results); |
130 | | - test.equals(results.length, 15); |
131 | | - test.equals(results[0], "{{> molecules-comment-header}}"); |
132 | | - test.equals(results[1], "{{> molecules-comment-header}}"); |
133 | | - test.equals(results[2], "{{> \n molecules-comment-header\n}}"); |
134 | | - test.equals(results[3], "{{> molecules-weird-spacing }}"); |
135 | | - test.equals(results[4], "{{> molecules-single-comment(description: 'A life isn\\'t like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"); |
136 | | - test.equals(results[5], '{{> molecules-single-comment(description: "A life is like a \\"garden\\". Perfect moments can be had, but not preserved, except in memory.") }}'); |
137 | | - test.equals(results[6], "{{> molecules-single-comment:foo }}"); |
138 | | - test.equals(results[7], "{{> 01-molecules/06-components/03-comment-header.hbs }}"); |
139 | | - test.equals(results[8], "{{> 01-molecules/06-components/02-single-comment.hbs(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"); |
140 | | - test.equals(results[9], "{{> molecules-single-comment:foo }}"); |
141 | | - test.equals(results[10], "{{>atoms-error(message: 'That\\'s no moon...')}}"); |
142 | | - test.equals(results[11], "{{>atoms-error(message: 'That\\'s no moon...')}}"); |
143 | | - test.equals(results[12], "{{> 00-atoms/00-global/06-test }}"); |
144 | | - test.equals(results[13], '{{> molecules-single-comment:foo_1 }}'); |
145 | | - test.equals(results[14], '{{> molecules-single-comment:foo-1 }}'); |
146 | | - test.done(); |
| 116 | + testFindPartials(test, [ |
| 117 | + "{{> molecules-comment-header}}", |
| 118 | + "{{> molecules-comment-header}}", |
| 119 | + "{{> \n molecules-comment-header\n}}", |
| 120 | + "{{> molecules-weird-spacing }}", |
| 121 | + "{{> molecules-ba_d-cha*rs }}" |
| 122 | + ]); |
147 | 123 | }, |
148 | | - // GTP warning: unchanged copypasta from mustache engine |
149 | 124 | 'find_pattern_partials finds verbose partials': function(test){ |
150 | | - test.expect(3); |
151 | | - |
152 | | - //setup current pattern from what we would have during execution |
153 | | - var currentPattern = new object_factory.oPattern( |
154 | | - '/home/fakeuser/pl/source/_patterns/01-molecules/00-testing/00-test-mol.hbs', // abspath |
155 | | - '01-molecules\\00-testing', // subdir |
156 | | - '00-test-mol.hbs', // filename, |
157 | | - null // data |
158 | | - ); |
159 | | - currentPattern.template = "<h1>{{> 01-molecules/06-components/03-comment-header.hbs }}</h1><div>{{> 01-molecules/06-components/02-single-comment.hbs(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}</div>"; |
160 | | - |
161 | | - var results = currentPattern.findPartials(); |
162 | | - test.equals(results.length, 2); |
163 | | - test.equals(results[0], '{{> 01-molecules/06-components/03-comment-header.hbs }}'); |
164 | | - test.equals(results[1], '{{> 01-molecules/06-components/02-single-comment.hbs(description: \'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.\') }}'); |
165 | | - test.done(); |
| 125 | + testFindPartials(test, [ |
| 126 | + '{{> 01-molecules/06-components/03-comment-header.hbs }}', |
| 127 | + "{{> 01-molecules/06-components/02-single-comment.hbs(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", |
| 128 | + '{{> molecules-single-comment:foo }}', |
| 129 | + "{{>atoms-error(message: 'That\'s no moon...')}}", |
| 130 | + "{{> atoms-error(message: 'That\'s no moon...') }}", |
| 131 | + '{{> 00-atoms/00-global/06-test }}' |
| 132 | + ]); |
166 | 133 | }, |
167 | | - // GTP warning: unchanged copypasta from mustache engine |
168 | | - 'find_pattern_partials_with_parameters finds parameters with verbose partials': function(test){ |
169 | | - test.expect(2); |
170 | | - |
171 | | - //setup current pattern from what we would have during execution |
172 | | - var currentPattern = new object_factory.oPattern( |
173 | | - '/home/fakeuser/pl/source/_patterns/01-molecules/00-testing/00-test-mol.hbs', // abspath |
174 | | - '01-molecules\\00-testing', // subdir |
175 | | - '00-test-mol.hbs', // filename, |
176 | | - null // data |
177 | | - ); |
178 | | - currentPattern.template = "<h1>{{> 01-molecules/06-components/molecules-comment-header}}</h1><div>{{> 01-molecules/06-components/molecules-single-comment(bar:'baz') }}</div>"; |
179 | | - |
180 | | - var results = currentPattern.findPartialsWithPatternParameters(); |
181 | | - test.equals(results.length, 1); |
182 | | - test.equals(results[0], "{{> 01-molecules/06-components/molecules-single-comment(bar:'baz') }}"); |
183 | | - |
184 | | - test.done(); |
| 134 | + 'find_pattern_partials finds simple partials with parameters': function(test){ |
| 135 | + testFindPartials(test, [ |
| 136 | + "{{> molecules-single-comment(description: 'A life isn\'t like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", |
| 137 | + '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}' |
| 138 | + ]); |
185 | 139 | }, |
186 | | - // GTP warning: unchanged copypasta from mustache engine |
187 | | - 'find_pattern_partials_with_parameters finds no style modifiers when only partials present': function(test){ |
188 | | - test.expect(1); |
189 | | - |
190 | | - //setup current pattern from what we would have during execution |
191 | | - var currentPattern = new object_factory.oPattern( |
192 | | - '/home/fakeuser/pl/source/_patterns/01-molecules/00-testing/00-test-mol.hbs', // abspath |
193 | | - '01-molecules\\00-testing', // subdir |
194 | | - '00-test-mol.hbs', // filename, |
195 | | - null // data |
196 | | - ); |
197 | | - currentPattern.template = "<h1>{{> molecules-comment-header}}</h1><div>{{> molecules-single-comment }}</div>"; |
198 | | - |
199 | | - var results = currentPattern.findPartialsWithPatternParameters(); |
200 | | - test.equals(results, null); |
201 | | - |
202 | | - test.done(); |
| 140 | + 'find_pattern_partials finds simple partials with style modifiers': function(test){ |
| 141 | + testFindPartials(test, [ |
| 142 | + '{{> molecules-single-comment:foo }}' |
| 143 | + ]); |
| 144 | + }, |
| 145 | + 'find_pattern_partials finds partials with handlebars parameters': function(test){ |
| 146 | + testFindPartials(test, [ |
| 147 | + '{{> atoms-title title="bravo" headingLevel="2" headingSize="bravo" position="left"}}', |
| 148 | + '{{> atoms-title title="bravo"\n headingLevel="2"\n headingSize="bravo"\n position="left"}}', |
| 149 | + '{{> atoms-title title="color <span style=\'font-weight:normal\'>midnight blue</span>" headingSize="charlie"}}', |
| 150 | + '{{> atoms-input label="city" required=true}}', |
| 151 | + '{{> organisms-product-filter filterData}}', |
| 152 | + '{{> atoms-input email required=true}}', |
| 153 | + '{{> molecules-storycard variants.flex }}', |
| 154 | + '{{> myPartial name=../name }}' |
| 155 | + ]); |
| 156 | + }, |
| 157 | + |
| 158 | + 'find_pattern_partials finds handlebars block partials': function(test){ |
| 159 | + testFindPartials(test, [ |
| 160 | + '{{#> myPartial }}' |
| 161 | + ]); |
203 | 162 | } |
204 | 163 | }; |
205 | 164 | })(); |
0 commit comments