Skip to content

Commit cf0aaa5

Browse files
committed
fix(unit tests): Fix tests
1 parent 32a13e1 commit cf0aaa5

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

test/ui_builder_tests.js

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ var fsMock = {
1818
outputFileSync: function (path, data, cb) { }
1919
};
2020

21-
var renderSyncMock = function (template, data, partials) { return ''; };
21+
var renderMock = function (template, data, partials) { return Promise.resolve(''); };
22+
var buildFooterMock = function (patternlab, patternPartial) { return Promise.resolve(''); };
2223

2324
//set our mocks in place of usual require()
2425
uiModule.__set__({
2526
'fs': fsMock,
26-
'renderSync': renderSyncMock
27+
'render': renderMock,
28+
'buildFooter': buildFooterMock
2729
});
2830

2931
var ui = uiModule();
@@ -368,11 +370,14 @@ tap.test('resetUIBuilderState - reset global objects', function (test) {
368370

369371
tap.test('buildViewAllPages - adds viewall page for each type and subtype', function (test) {
370372
//arrange
371-
let mainPageHeadHtml = '<head></head>';
372-
let patternlab = createFakePatternLab({
373+
const mainPageHeadHtml = '<head></head>';
374+
const patternlab = createFakePatternLab({
373375
patterns: [],
374376
patternGroups: {},
375-
subtypePatterns: {}
377+
subtypePatterns: {},
378+
footer: {},
379+
userFoot: {},
380+
cacheBuster: 1234
376381
});
377382

378383
patternlab.patterns.push(
@@ -387,23 +392,32 @@ tap.test('buildViewAllPages - adds viewall page for each type and subtype', func
387392
);
388393
ui.resetUIBuilderState(patternlab);
389394

390-
let styleguidePatterns = ui.groupPatterns(patternlab);
395+
const styleguidePatterns = ui.groupPatterns(patternlab);
391396

392397
//act
393-
var patterns = ui.buildViewAllPages(mainPageHeadHtml, patternlab, styleguidePatterns);
394-
395-
//assert
396-
//this was a nuanced one. buildViewAllPages() had return false; statements
397-
//within _.forOwn(...) loops, causing premature termination of the entire loop
398-
//when what was intended was a continue
399-
//we expect 8 here because:
400-
// - foo.mustache is flat and therefore does not have a viewall page
401-
// - the colors.mustache files make 6
402-
// - patternSubType1 and patternSubType2 make 8
403-
//while most of that heavy lifting occurs inside groupPatterns and not buildViewAllPages,
404-
//it's important to ensure that this method does not get prematurely terminated
405-
//we choose to do that by checking it's return number of patterns
406-
test.equals(patterns.length, 8, '2 viewall pages should be added');
398+
ui.buildViewAllPages(mainPageHeadHtml, patternlab, styleguidePatterns).then(allPatterns => {
399+
//assert
400+
//this was a nuanced one. buildViewAllPages() had return false; statements
401+
//within _.forOwn(...) loops, causing premature termination of the entire loop
402+
//when what was intended was a continue
403+
//we expect 8 here because:
404+
// - foo.mustache is flat and therefore does not have a viewall page
405+
// - the colors.mustache files make 6
406+
// - patternSubType1 and patternSubType2 make 8
407+
//while most of that heavy lifting occurs inside groupPatterns and not buildViewAllPages,
408+
//it's important to ensure that this method does not get prematurely terminated
409+
//we choose to do that by checking it's return number of patterns
410+
411+
//todo: this workaround matches the code at the moment
412+
const uniquePatterns = _.uniq(
413+
_.flatMapDeep(allPatterns, (pattern) => {
414+
return pattern;
415+
})
416+
);
417+
418+
test.equals(uniquePatterns.length, 8, '2 viewall pages should be added');
419+
420+
test.end();
421+
});
407422

408-
test.end();
409423
});

0 commit comments

Comments
 (0)