Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apca-silver-plus): don't reverse in place #132

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});
Loading