From edc5bf57ee92978008a55aafd686b16223dc718a Mon Sep 17 00:00:00 2001 From: rare-magma Date: Thu, 12 Oct 2023 15:19:25 +0200 Subject: [PATCH] feat: improve screen reader a11y Signed-off-by: rare-magma --- src/App.test.tsx | 2 +- .../CalculateButton/CalculateButton.test.tsx | 81 +++++++------------ .../CalculateButton/CalculateButton.tsx | 40 ++++----- src/components/Chart/Chart.tsx | 2 +- src/components/ErrorModal/ErrorModal.tsx | 20 +++-- .../ItemForm/ItemFormGroup.test.tsx | 2 +- src/components/ItemForm/ItemFormGroup.tsx | 4 +- src/components/NavBar/NavBar.tsx | 22 ++--- src/components/NavBar/NavBarDelete.tsx | 4 +- src/components/NavBar/NavBarExport.tsx | 2 +- src/components/Notification/Notification.tsx | 2 +- src/components/StatCard/StatCard.tsx | 16 ++-- src/components/TableCard/TableCard.tsx | 4 +- 13 files changed, 94 insertions(+), 107 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index 539754f..34e8b37 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -17,7 +17,7 @@ describe("App", () => { render(comp); expect(screen.getAllByText("guitos")[0]).toBeInTheDocument(); expect(screen.getByRole("status")).toBeInTheDocument(); - expect(screen.getByText(/v[0-9.]/)).toBeInTheDocument(); + expect(screen.getByLabelText("open guitos changelog")).toBeInTheDocument(); expect(budgetsDB.config("name")).toBe("guitos"); expect(budgetsDB.config("storeName")).toBe("budgets"); expect(optionsDB.config("name")).toBe("guitos"); diff --git a/src/components/CalculateButton/CalculateButton.test.tsx b/src/components/CalculateButton/CalculateButton.test.tsx index 271bbdc..ed73d80 100644 --- a/src/components/CalculateButton/CalculateButton.test.tsx +++ b/src/components/CalculateButton/CalculateButton.test.tsx @@ -24,13 +24,13 @@ describe("CalculateButton", () => { it("renders initial state", () => { expect( - screen.getByLabelText("select operations to change item value amount"), + screen.getByLabelText("select operation type to item value"), ).toBeInTheDocument(); }); it("opens popover when clicking the button", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); @@ -40,20 +40,18 @@ describe("CalculateButton", () => { }), ).toBeInTheDocument(); - expect( - screen.getByLabelText("change item value amount"), - ).toBeInTheDocument(); + expect(screen.getByLabelText("addition")).toBeInTheDocument(); expect( screen.getByRole("button", { - name: "accept change item value amount", + name: "apply change to item value", }), ).toBeInTheDocument(); }); it("closes when clicking the button", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); @@ -68,7 +66,7 @@ describe("CalculateButton", () => { it("closes when pressing Escape key", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); @@ -76,27 +74,21 @@ describe("CalculateButton", () => { name: "select type of operation on item value", }); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "{Escape}", - ); + await userEvent.type(screen.getByLabelText("addition"), "{Escape}"); expect(button2).not.toBeInTheDocument(); }); it("calls onCalculate when accepting change > 0", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); const acceptButton = screen.getByRole("button", { - name: "accept change item value amount", + name: "apply change to item value", }); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "123", - ); + await userEvent.type(screen.getByLabelText("add"), "123"); await userEvent.click(acceptButton); expect(onCalculate).toBeCalledWith(123, "add"); @@ -104,78 +96,63 @@ describe("CalculateButton", () => { it("calls onCalculate when change > 0 and enter is pressed", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "123", - ); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "{enter}", - ); + await userEvent.type(screen.getByLabelText("addition"), "123"); + await userEvent.type(screen.getByLabelText("addition"), "{enter}"); expect(onCalculate).toBeCalledWith(123, "add"); }); it("calls onCalculate with sub", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); const acceptButton = screen.getByRole("button", { - name: "accept change item value amount", + name: "apply change to item value", }); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "123", - ); + await userEvent.type(screen.getByLabelText("add"), "123"); - await userEvent.click(screen.getByLabelText("subtract to item value")); + await userEvent.click(screen.getByLabelText("subtraction")); await userEvent.click(acceptButton); - expect(onCalculate).toBeCalledWith(123, "sub"); + expect(onCalculate).toBeCalledWith(123, "subtract"); }); - it("calls onCalculate with mul", async () => { + it("calls onCalculate with multiply", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); const acceptButton = screen.getByRole("button", { - name: "accept change item value amount", + name: "apply change to item value", }); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "123", - ); + await userEvent.type(screen.getByLabelText("add"), "123"); - await userEvent.click(screen.getByLabelText("multiply item value")); + await userEvent.click(screen.getByLabelText("multiplication")); await userEvent.click(acceptButton); - expect(onCalculate).toBeCalledWith(123, "mul"); + expect(onCalculate).toBeCalledWith(123, "multiply"); }); it("calls onCalculate with div", async () => { const button = screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }); await userEvent.click(button); const acceptButton = screen.getByRole("button", { - name: "accept change item value amount", + name: "apply change to item value", }); - await userEvent.type( - screen.getByLabelText("change item value amount"), - "123", - ); + await userEvent.type(screen.getByLabelText("add"), "123"); - await userEvent.click(screen.getByLabelText("divide item value")); + await userEvent.click(screen.getByLabelText("division")); await userEvent.click(acceptButton); - expect(onCalculate).toBeCalledWith(123, "div"); + expect(onCalculate).toBeCalledWith(123, "divide"); }); }); diff --git a/src/components/CalculateButton/CalculateButton.tsx b/src/components/CalculateButton/CalculateButton.tsx index a7c6368..8380483 100644 --- a/src/components/CalculateButton/CalculateButton.tsx +++ b/src/components/CalculateButton/CalculateButton.tsx @@ -68,36 +68,36 @@ function CalculateButton({ variant="outline-secondary" id="dropdown-operation" > - {operation === "add" && } - {operation === "sub" && } - {operation === "mul" && } - {operation === "div" && } + {operation === "add" && } + {operation === "subtract" && } + {operation === "multiply" && } + {operation === "divide" && } setOperation("add")} > - + setOperation("sub")} + aria-label="subtraction" + onClick={() => setOperation("subtract")} > - + setOperation("mul")} + aria-label="multiplication" + onClick={() => setOperation("multiply")} > - + setOperation("div")} + aria-label="division" + onClick={() => setOperation("divide")} > - + @@ -105,7 +105,7 @@ function CalculateButton({ id={`${label}-${itemForm.id}-operation-value`} key={`item-${itemForm.id}-operation-value`} className="text-end form-control straight-corners fixed-width-font" - aria-label={"change item value amount"} + aria-label={`${operation}`} name="item-operate-value" intlConfig={intlConfig} defaultValue={0} @@ -120,7 +120,7 @@ function CalculateButton({ @@ -138,7 +138,7 @@ function CalculateButton({ diff --git a/src/components/Chart/Chart.tsx b/src/components/Chart/Chart.tsx index e607e55..f3a5a03 100644 --- a/src/components/Chart/Chart.tsx +++ b/src/components/Chart/Chart.tsx @@ -137,7 +137,7 @@ function Chart({ disabled /> - + )} diff --git a/src/components/ErrorModal/ErrorModal.tsx b/src/components/ErrorModal/ErrorModal.tsx index 7f3e762..50984b6 100644 --- a/src/components/ErrorModal/ErrorModal.tsx +++ b/src/components/ErrorModal/ErrorModal.tsx @@ -64,7 +64,7 @@ function ErrorModal({ handleShow(false); }} > - + @@ -87,7 +87,7 @@ function ErrorModal({ @@ -110,7 +110,10 @@ function ErrorModal({ key={`${jsonError.file}-item-${i}`} eventKey={jsonError.file} > - + {jsonError.file} { @@ -154,7 +157,7 @@ function ErrorModal({ handleError(); }} > - + @@ -168,7 +171,10 @@ function ErrorModal({ key={`${csvError.file}-item-${i}`} eventKey={csvError.file} > - + {csvError.file} { it("opens popover when clicking the button", async () => { await userEvent.click( screen.getByRole("button", { - name: "select operations to change item value amount", + name: "select operation type to item value", }), ); diff --git a/src/components/ItemForm/ItemFormGroup.tsx b/src/components/ItemForm/ItemFormGroup.tsx index 09596cc..b893aaa 100644 --- a/src/components/ItemForm/ItemFormGroup.tsx +++ b/src/components/ItemForm/ItemFormGroup.tsx @@ -177,7 +177,7 @@ function ItemFormGroup({ handleRemove(itemForm); }} > - + @@ -196,7 +196,7 @@ function ItemFormGroup({ }, 0); }} > - + diff --git a/src/components/NavBar/NavBar.tsx b/src/components/NavBar/NavBar.tsx index 61c9b9d..90a7251 100644 --- a/src/components/NavBar/NavBar.tsx +++ b/src/components/NavBar/NavBar.tsx @@ -271,7 +271,7 @@ function NavBar({ tooltipText={"go to older budget"} buttonAriaLabel={"go to older budget"} buttonVariant={"go-button"} - buttonIcon={} + buttonIcon={} /> } + buttonIcon={} /> )} @@ -321,7 +321,6 @@ function NavBar({ @@ -334,7 +333,7 @@ function NavBar({ variant="outline-secondary" onClick={() => setExpanded(false)} > - {} + {} @@ -370,7 +369,7 @@ function NavBar({ buttonAriaLabel={"new budget"} buttonClassName="w-100" buttonVariant={"outline-success"} - buttonIcon={expanded ? "new" : } + buttonIcon={expanded ? "new" : } /> {hasOneOrMoreBudgets && ( <> @@ -382,7 +381,7 @@ function NavBar({ buttonAriaLabel={"clone budget"} buttonClassName="w-100" buttonVariant={"outline-success"} - buttonIcon={expanded ? "clone" : } + buttonIcon={expanded ? "clone" : } /> )} -