Skip to content

Commit

Permalink
fix: missing accessibility labels and tests
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Jul 26, 2024
1 parent a27bccf commit b4c7642
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
25 changes: 25 additions & 0 deletions e2e/accessibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, test } from "@playwright/test";
import { AxeBuilder } from "@axe-core/playwright";

test("should not have any automatically detectable accessibility issues on landing page", async ({
page,
}) => {
await page.goto("/");
const accessibilityScanResults = await new AxeBuilder({ page })
.disableRules("color-contrast")
.analyze();

expect(accessibilityScanResults.violations).toStrictEqual([]);
});

test("should not have any automatically detectable accessibility issues", async ({
page,
}) => {
await page.goto("/");
await page.getByText("get started").click();
const accessibilityScanResults = await new AxeBuilder({ page })
.disableRules("color-contrast")
.analyze();

expect(accessibilityScanResults.violations).toStrictEqual([]);
});
16 changes: 11 additions & 5 deletions src/components/Budget/BudgetPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suspense, lazy, useEffect, useState } from "react";
import { lazy, Suspense, useEffect, useState } from "react";
import { Col, Container, Row, ToastContainer } from "react-bootstrap";
import { useHotkeys } from "react-hotkeys-hook";
import { useParams } from "react-router-dom";
Expand Down Expand Up @@ -79,8 +79,8 @@ export function BudgetPage() {
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
try {
const shouldLoadBudgetsFromList =
budgetList && budgetList.length >= 1 && Array.isArray(budgetList);
const shouldLoadBudgetsFromList = budgetList && budgetList.length >= 1 &&
Array.isArray(budgetList);

if (shouldLoadBudgetsFromList) {
if (name.trim() !== "undefined") {
Expand All @@ -102,7 +102,12 @@ export function BudgetPage() {
}, [name, loadingFromDB]);

return (
<Container fluid style={{ zIndex: 1 }} key={`${budget?.id}-${needReload}`}>
<Container
fluid
style={{ zIndex: 1 }}
key={`${budget?.id}-${needReload}`}
role="main"
>
<ToastContainer
className="p-2"
position={"bottom-center"}
Expand Down Expand Up @@ -133,7 +138,8 @@ export function BudgetPage() {
<div className="card-columns">
<StatCard
key={`${budget?.expenses.total} + ${budget?.incomes.total}-${budget.id}-stat-card`}
onShowGraphs={() => setShowGraphs(true)}
onShowGraphs={() =>
setShowGraphs(true)}
/>

<div className="mt-3" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function NavBar() {
onToggle={() => setExpanded(!expanded)}
data-testid="header"
>
<Container fluid className="flex-row">
<Container fluid className="flex-row" role="heading" aria-level={1}>
{shouldShowBrand && (
<OverlayTrigger
delay={250}
Expand Down
15 changes: 8 additions & 7 deletions src/components/StatCard/StatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ export function StatCard({ onShowGraphs }: StatCardProps) {
const stat = budget?.stats;
const [autoGoal, setAutoGoal] = useState(false);

const shouldCalculateAvailablePerc =
revenuePercentage <= 100 && stat && stat.available > 0;
const shouldCalculateAvailablePerc = revenuePercentage <= 100 && stat &&
stat.available > 0;

const goalRef =
useRef<HTMLInputElement>() as React.MutableRefObject<HTMLInputElement>;
const reservesRef =
useRef<HTMLInputElement>() as React.MutableRefObject<HTMLInputElement>;
const goalRef = useRef<HTMLInputElement>() as React.MutableRefObject<
HTMLInputElement
>;
const reservesRef = useRef<HTMLInputElement>() as React.MutableRefObject<
HTMLInputElement
>;

useHotkeys("g", (e) => !e.repeat && focusRef(goalRef), {
preventDefault: true,
Expand Down Expand Up @@ -120,7 +122,6 @@ export function StatCard({ onShowGraphs }: StatCardProps) {
min={0}
max={100}
now={revenuePercentage}
label={`${revenuePercentage}%`}
visuallyHidden
/>
</Col>
Expand Down

0 comments on commit b4c7642

Please sign in to comment.