fix: focusable element when webcam expanded with no devices, add error test

- LaunchWindow: render sr-only <select> when webcamExpanded but
  cameraDevices.length === 0 (loading/error/empty), so keyboard users
  always have a focusable element even in no-camera states
- useCameraDevices.test: add error-branch test asserting error message,
  empty devices array and isLoading=false when enumerateDevices rejects
This commit is contained in:
Etienne Lescot
2026-03-27 16:28:53 +01:00
parent 9817c85acf
commit baec9a7585
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ export function LaunchWindow() {
/>
</>
))}
{!webcamExpanded && (
{(!webcamExpanded || cameraDevices.length === 0) && (
<select
value={webcamDeviceId || selectedCameraId}
onChange={(e) => {
+13
View File
@@ -71,6 +71,19 @@ describe("useCameraDevices", () => {
expect(mockGetUserMedia).not.toHaveBeenCalled();
});
it("should set error state when enumeration fails", async () => {
mockEnumerateDevices.mockRejectedValueOnce(new Error("Permission denied"));
const { result } = renderHook(() => useCameraDevices(true));
await waitFor(() => {
expect(result.current.error).toBe("Permission denied");
});
expect(result.current.devices).toHaveLength(0);
expect(result.current.isLoading).toBe(false);
});
it("should fall back to first available device when selected device is unplugged", async () => {
const { result } = renderHook(() => useCameraDevices(true));