Skip to content

Commit

Permalink
report: sort audits by weight (#13053)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Oct 27, 2021
1 parent 755ed09 commit cbdcab1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions report/renderer/category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ export class CategoryRenderer {
clumps.set(clumpId, clump);
}

// Sort audits by weight.
for (const auditRefs of clumps.values()) {
auditRefs.sort((a, b) => {
return b.weight - a.weight;
});
}

// Render each clump.
for (const [clumpId, auditRefs] of clumps) {
if (auditRefs.length === 0) continue;
Expand Down
41 changes: 41 additions & 0 deletions report/test/renderer/category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,45 @@ describe('CategoryRenderer', () => {
assert.ok(shouldBeWarning[0].textContent.includes(passingWarning));
});
});

it('renders audits by weight', () => {
const defaultAuditRef = {
title: '',
description: '',
scoreDisplayMode: 'numeric',
score: 0,
warnings: [],
};
const category = {
id: 'test',
title: 'Test',
score: 0,
auditRefs: [{
id: 'audit-1',
weight: 0,
result: {
id: 'audit-1',
...defaultAuditRef,
},
}, {
id: 'audit-2',
weight: 1,
result: {
id: 'audit-2',
...defaultAuditRef,
},
}, {
id: 'audit-3',
weight: 0.5,
result: {
id: 'audit-3',
...defaultAuditRef,
},
}],
};
const categoryDOM = renderer.render(category);

const auditEls = [...categoryDOM.querySelectorAll('.lh-audit')];
expect(auditEls.map(el => el.id)).toEqual(['audit-2', 'audit-3', 'audit-1']);
});
});

0 comments on commit cbdcab1

Please sign in to comment.