Skip to content

Commit

Permalink
fix(apca-silver-plus): don't reverse in place (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPieroni authored Sep 3, 2024
1 parent 29e2e47 commit 90ca26a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-bats-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"apca-check": patch
---

fix: bug with array reversal
5 changes: 3 additions & 2 deletions src/apca-silver-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const APCASilverPlusConformanceThresholdFn: ConformanceThresholdFn = (
// Go over the table backwards to find the first matching font size and then the weight.
// The value null is returned when the combination of font size and weight does not have
// any elegible APCA luminosity silver compliant thresholds (represented by -1 in the table).
silverPlusAPCALookupTable.reverse();
for (const [rowSize, ...rowWeights] of silverPlusAPCALookupTable) {
const reversedTable = [...silverPlusAPCALookupTable].reverse();

for (const [rowSize, ...rowWeights] of reversedTable) {
if (size >= rowSize) {
for (const [idx, keywordWeight] of [
900, 800, 700, 600, 500, 400, 300, 200, 100,
Expand Down
17 changes: 17 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,22 @@ describe("apca-check", () => {

await expect(apcaViolations[0].nodes.length).to.equal(3);
});

it("should handle both valid code and violations", async () => {
const el: HTMLElement = await fixture(
html`<div style="background: white; color: black;">
<p style="font-size: 12px; font-weight: 400;">Some copy</p>
<p style="font-size: 16px; font-weight: 600;">Some copy</p>
</div>`,
);

const results = await runAxe(el);

const apcaViolations = results.violations.filter((violation) =>
violation.id.includes("color-contrast-apca-silver"),
);

await expect(apcaViolations[0].nodes.length).to.equal(1);
});
});
});

0 comments on commit 90ca26a

Please sign in to comment.