From 5d1793d121dfbb6abefccd0d13d8a0280865de6f Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Mon, 14 Jan 2019 12:56:31 -0800 Subject: [PATCH 1/2] report: restore old, disabled failed grouping test --- .../html/renderer/category-renderer-test.js | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lighthouse-core/test/report/html/renderer/category-renderer-test.js b/lighthouse-core/test/report/html/renderer/category-renderer-test.js index bbb5547544e2..7daa0f8bf568 100644 --- a/lighthouse-core/test/report/html/renderer/category-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/category-renderer-test.js @@ -215,16 +215,36 @@ describe('CategoryRenderer', () => { assert.ok(description.querySelector('a'), 'description contains converted markdown links'); }); - // TODO waiting for decision regarding this header - it.skip('renders the failed audits grouped by group', () => { - const categoryDOM = renderer.render(category, sampleResults.categoryGroups); - const failedAudits = category.auditRefs.filter(audit => { - return audit.result.score !== 1 && !audit.result.scoreDisplayMode === 'notApplicable'; + it('renders the failed audits grouped by group', () => { + // Fail all the audits. + const categoryClone = JSON.parse(JSON.stringify(category)); + const auditRefs = categoryClone.auditRefs; + auditRefs.forEach(ref => { + ref.result.score = 0; + ref.result.scoreDisplayMode = 'binary'; }); - const failedAuditTags = new Set(failedAudits.map(audit => audit.group)); + const categoryDOM = renderer.render(categoryClone, sampleResults.categoryGroups); + + // All the group names in the config. + const groupNames = Array.from(new Set(auditRefs.map(ref => ref.group))).filter(Boolean); + assert.ok(groupNames.length > 5); // Make sure there are groups to test. - const failedAuditGroups = categoryDOM.querySelectorAll('.lh-category > div.lh-audit-group'); - assert.equal(failedAuditGroups.length, failedAuditTags.size); + // All the group roots in the DOM. + const failedGroupElems = Array.from( + categoryDOM.querySelectorAll('.lh-clump--failed > .lh-audit-group')); + + assert.strictEqual(failedGroupElems.length, groupNames.length); + + for (const groupName of groupNames) { + const groupAuditRefs = auditRefs.filter(ref => ref.group === groupName); + assert.ok(groupAuditRefs.length > 0); // Make sure there are audits to find. + + const className = `lh-audit-group--${groupName}`; + const groupElem = failedGroupElems.find(el => el.classList.contains(className)); + const groupAuditElems = groupElem.querySelectorAll('.lh-audit'); + + assert.strictEqual(groupAuditElems.length, groupAuditRefs.length); + } }); it('renders the passed audits ungrouped', () => { From f87bb3e6f5161b2eae1de00cf9bf181eb338376f Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Mon, 14 Jan 2019 13:43:54 -0800 Subject: [PATCH 2/2] assert messages --- .../test/report/html/renderer/category-renderer-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lighthouse-core/test/report/html/renderer/category-renderer-test.js b/lighthouse-core/test/report/html/renderer/category-renderer-test.js index 7daa0f8bf568..bab66007708f 100644 --- a/lighthouse-core/test/report/html/renderer/category-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/category-renderer-test.js @@ -227,7 +227,7 @@ describe('CategoryRenderer', () => { // All the group names in the config. const groupNames = Array.from(new Set(auditRefs.map(ref => ref.group))).filter(Boolean); - assert.ok(groupNames.length > 5); // Make sure there are groups to test. + assert.ok(groupNames.length > 5, `not enough groups found in category for test`); // All the group roots in the DOM. const failedGroupElems = Array.from( @@ -237,7 +237,7 @@ describe('CategoryRenderer', () => { for (const groupName of groupNames) { const groupAuditRefs = auditRefs.filter(ref => ref.group === groupName); - assert.ok(groupAuditRefs.length > 0); // Make sure there are audits to find. + assert.ok(groupAuditRefs.length > 0, `no auditRefs found with group '${groupName}'`); const className = `lh-audit-group--${groupName}`; const groupElem = failedGroupElems.find(el => el.classList.contains(className));