Archived
test: close audit cleanup findings
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { activateSelectableRow, activateSelectableRowFromKeyboard, handleSelectableRowKeyboard } from "./selectableRow";
|
||||
import { activateSelectableRow, handleSelectableRowKeyboard } from "./selectableRow";
|
||||
|
||||
describe("selectable row activation", () => {
|
||||
it("activates rows from non-interactive click targets", () => {
|
||||
@@ -20,8 +20,8 @@ describe("selectable row activation", () => {
|
||||
const enter = keyboardEventWithPath("Enter", matchTarget(() => false));
|
||||
const space = keyboardEventWithPath(" ", matchTarget(() => false));
|
||||
|
||||
activateSelectableRowFromKeyboard(enter, enterAction);
|
||||
activateSelectableRowFromKeyboard(space, spaceAction);
|
||||
expect(handleSelectableRowKeyboard(enter, { activate: enterAction })).toBe(true);
|
||||
expect(handleSelectableRowKeyboard(space, { activate: spaceAction })).toBe(true);
|
||||
|
||||
expect(enterAction).toHaveBeenCalledOnce();
|
||||
expect(spaceAction).toHaveBeenCalledOnce();
|
||||
@@ -33,7 +33,7 @@ describe("selectable row activation", () => {
|
||||
const action = vi.fn();
|
||||
const event = keyboardEventWithPath("Enter", matchTarget((selector: string) => selector.includes("button")));
|
||||
|
||||
activateSelectableRowFromKeyboard(event, action);
|
||||
expect(handleSelectableRowKeyboard(event, { activate: action })).toBe(false);
|
||||
|
||||
expect(action).not.toHaveBeenCalled();
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
|
||||
@@ -11,8 +11,9 @@ const interactiveSelector = [
|
||||
].join(",");
|
||||
|
||||
type ComposedPathEvent = Pick<Event, "composedPath">;
|
||||
type SelectableKeyboardEvent = ComposedPathEvent & Pick<KeyboardEvent, "key" | "preventDefault">;
|
||||
type SelectableNavigationKeyboardEvent = SelectableKeyboardEvent & Partial<Pick<KeyboardEvent, "currentTarget" | "stopPropagation">>;
|
||||
type SelectableNavigationKeyboardEvent = ComposedPathEvent
|
||||
& Pick<KeyboardEvent, "key" | "preventDefault">
|
||||
& Partial<Pick<KeyboardEvent, "currentTarget" | "stopPropagation">>;
|
||||
|
||||
export interface SelectableRowKeyboardOptions {
|
||||
activate: () => void;
|
||||
@@ -37,13 +38,6 @@ export function activateSelectableRow(event: ComposedPathEvent, action: () => vo
|
||||
action();
|
||||
}
|
||||
|
||||
export function activateSelectableRowFromKeyboard(event: SelectableKeyboardEvent, action: () => void): void {
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
if (isFromInteractiveElement(event)) return;
|
||||
event.preventDefault();
|
||||
action();
|
||||
}
|
||||
|
||||
export function handleSelectableRowKeyboard(event: SelectableNavigationKeyboardEvent, options: SelectableRowKeyboardOptions): boolean {
|
||||
if (isFromInteractiveElement(event)) return false;
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
|
||||
Reference in New Issue
Block a user