Skip to content

Commit

Permalink
report: fix hidden audit handling for non-perf categories
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Apr 18, 2024
1 parent 52bc008 commit 70973bc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion report/renderer/category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ export class CategoryRenderer {

for (const auditRef of auditRefs) {
const groupId = auditRef.group || notAGroup;
if (groupId === 'hidden') continue;
const groupAuditRefs = grouped.get(groupId) || [];
groupAuditRefs.push(auditRef);
grouped.set(groupId, groupAuditRefs);
Expand Down Expand Up @@ -531,6 +530,7 @@ export class CategoryRenderer {

// Sort audits into clumps.
for (const auditRef of category.auditRefs) {
if (auditRef.group === 'hidden') continue;
const clumpId = this._getClumpIdForAuditRef(auditRef);
const clump = /** @type {Array<LH.ReportResult.AuditRef>} */ (clumps.get(clumpId)); // already defined
clump.push(auditRef);
Expand Down
15 changes: 9 additions & 6 deletions report/test/renderer/category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ describe('CategoryRenderer', () => {
assert.ok(categoryDOM.querySelector(
'.lh-clump--notapplicable .lh-audit-group__summary'));

const notApplicableCount = a11yCategory.auditRefs.reduce((sum, audit) =>
sum += audit.result.scoreDisplayMode === 'notApplicable' ? 1 : 0, 0);
const notApplicableAudits = a11yCategory.auditRefs.filter(audit => {
return audit.result.scoreDisplayMode === 'notApplicable' && audit.group !== 'hidden';
});
assert.equal(
categoryDOM.querySelectorAll('.lh-clump--notapplicable .lh-audit').length,
notApplicableCount,
'score shows informative and dash icon'
notApplicableAudits.length
);
});

Expand Down Expand Up @@ -351,7 +351,9 @@ describe('CategoryRenderer', () => {
it('renders the passed audits ungrouped', () => {
const categoryDOM = renderer.render(category, sampleResults.categoryGroups);
const passedAudits = category.auditRefs.filter(audit =>
audit.result.scoreDisplayMode !== 'notApplicable' && audit.result.score === 1);
audit.result.scoreDisplayMode !== 'notApplicable' &&
audit.group !== 'hidden' &&
audit.result.score === 1);

const passedAuditGroups = categoryDOM.querySelectorAll('.lh-clump--passed .lh-audit-group');
const passedAuditsElems = categoryDOM.querySelectorAll('.lh-clump--passed .lh-audit');
Expand All @@ -363,7 +365,8 @@ describe('CategoryRenderer', () => {
it('renders all the audits', () => {
const categoryDOM = renderer.render(category, sampleResults.categoryGroups);
const auditsElements = categoryDOM.querySelectorAll('.lh-audit');
assert.equal(auditsElements.length, category.auditRefs.length);
const visibleAudits = category.auditRefs.filter(a => a.group !== 'hidden');
assert.equal(auditsElements.length, visibleAudits.length);
});

it('renders audits without a group before grouped ones', () => {
Expand Down
12 changes: 10 additions & 2 deletions report/test/renderer/report-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ describe('ReportRenderer', () => {
.filter(url => DOCS_ORIGINS.includes(url.origin))
.map(url => url.searchParams.get('utm_medium'));

console.log(utmChannels.length);
assert.ok(utmChannels.length >= 75);
for (const utmChannel of utmChannels) {
assert.strictEqual(utmChannel, lhrChannel);
Expand All @@ -290,9 +289,18 @@ describe('ReportRenderer', () => {
it('renders `not_applicable` audits as `notApplicable`', () => {
const clonedSampleResult = JSON.parse(JSON.stringify(sampleResultsOrig));

const hiddenAuditIds = new Set();
for (const category of Object.values(clonedSampleResult.categories)) {
for (const auditRef of category.auditRefs) {
if (auditRef.group === 'hidden') {
hiddenAuditIds.add(auditRef.id);
}
}
}

let notApplicableCount = 0;
Object.values(clonedSampleResult.audits).forEach(audit => {
if (audit.scoreDisplayMode === 'notApplicable') {
if (audit.scoreDisplayMode === 'notApplicable' && !hiddenAuditIds.has(audit.id)) {
notApplicableCount++;
// Switch to old-style `not_applicable` to test fallback behavior.
audit.scoreDisplayMode = 'not_applicable';
Expand Down
11 changes: 4 additions & 7 deletions viewer/test/viewer-test-pptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,14 @@ describe('Lighthouse Viewer', () => {
'work-during-interaction',
];
for (const category of lighthouseCategories) {
let expected = getAuditsOfCategory(category);
if (category === 'performance') {
expected = getAuditsOfCategory(category)
.filter(a => a.group !== 'hidden' && !nonNavigationAudits.includes(a.id));
}
expected = expected.map(audit => audit.id);
const expectedAuditIds = getAuditsOfCategory(category)
.filter(a => a.group !== 'hidden' && !nonNavigationAudits.includes(a.id))
.map(a => a.id);
const elementIds = await getAuditElementsIds({category, selector: selectors.audits});

assert.deepStrictEqual(
elementIds.sort(),
expected.sort(),
expectedAuditIds.sort(),
`${category} does not have the identical audits`
);
}
Expand Down

0 comments on commit 70973bc

Please sign in to comment.