Skip to content

Commit 5003a6a

Browse files
#1143: Add test and fix remaining errors
1 parent e72b8b4 commit 5003a6a

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

packages/core/src/lib/object_factory.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,16 @@ Pattern.prototype = {
168168
}
169169
},
170170

171-
// calculated path from the root of the public directory to the generated html
172-
// file for this pattern.
173-
// Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
171+
/**
172+
* calculated path from the root of the public directory to the generated html
173+
* file for this pattern.
174+
*
175+
* Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
176+
*
177+
* @param {Patternlab} patternlab Current patternlab instance
178+
* @param {String} suffixType File suffix
179+
* @param {String} customfileExtension Custom extension
180+
*/
174181
getPatternLink: function(patternlab, suffixType, customfileExtension) {
175182
// if no suffixType is provided, we default to rendered
176183
const suffixConfig = patternlab.config.outputFileSuffixes;
@@ -249,6 +256,7 @@ Pattern.prototype = {
249256
const p = new Pattern(this.relPath, this.jsonFileData, patternlab, true);
250257
// Only reset the specific fields, not everything
251258
Object.assign(this, {
259+
name: p.name,
252260
patternLink: p.patternLink,
253261
patternGroup: p.patternGroup,
254262
patternType: p.patternType,

packages/core/test/object_factory_tests.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,38 @@ tap.test('test Pattern with one-directory subdir works as expected', function(
149149
test.end();
150150
});
151151

152+
tap.test('test Pattern with own-directory gets resetted as expected', function(
153+
test
154+
) {
155+
var p = new Pattern('00-atoms/00-button/button.mustache', { d: 123 }, pl);
156+
p.resetSubbing(pl);
157+
158+
test.equals(p.relPath, path.join('00-atoms', '00-button', 'button.mustache'));
159+
test.equals(p.name, '00-atoms-00-button-button');
160+
test.equals(p.subdir, path.join('00-atoms', '00-button'));
161+
test.equals(p.fileName, 'button');
162+
test.equals(p.fileExtension, '.mustache');
163+
test.equals(p.jsonFileData.d, 123);
164+
test.equals(p.patternBaseName, 'button');
165+
test.equals(p.patternName, 'Button');
166+
test.equals(
167+
p.getPatternLink(pl),
168+
path.join(
169+
'00-atoms-00-button-button',
170+
'00-atoms-00-button-button.rendered.html'
171+
)
172+
);
173+
test.equals(p.patternGroup, 'atoms');
174+
test.equals(p.flatPatternPath, '00-atoms-00-button');
175+
test.equals(p.patternPartial, 'atoms-button');
176+
test.equals(p.template, '');
177+
test.equals(p.lineage.length, 0);
178+
test.equals(p.lineageIndex.length, 0);
179+
test.equals(p.lineageR.length, 0);
180+
test.equals(p.lineageRIndex.length, 0);
181+
test.end();
182+
});
183+
152184
tap.test(
153185
'test Pattern with no numbers in pattern group works as expected',
154186
function(test) {

0 commit comments

Comments
 (0)