import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { ComponentProps } from "react"; import { ApiError } from "@/lib/api/client"; import { SettingsSaveProvider } from "./settings-save-provider"; import { SidebarLayoutEditor } from "./sidebar-layout-editor"; const mocks = vi.hoisted(() => ({ state: { workspaces: { activeId: "workspace-1" }, userSettings: { sidebarLayoutsByWorkspace: {} }, }, catalog: [] as Array<{ target: { kind: "destination"; id: string }; label: string; available: boolean; }>, isMobile: false, setUserSettings: vi.fn(), updateUserSettings: vi.fn(), fetchUserSettings: vi.fn(), })); const SIDEBAR_LABEL = "Sidebar"; const ADD_SECTION_LABEL = "Add shortcut section"; const SECTION_NAME_LABEL = "Section name"; const MOVE_UP_LABEL = "Move up"; const MOVE_DOWN_LABEL = "Move down"; const LOAD_LATEST_LABEL = "Load latest"; const RETRY_SAVE_LABEL = "Retry save"; const LOADING_LABEL = "Loading"; vi.mock("@/components/state-provider", () => ({ useAppStore: (selector: (state: typeof mocks.state) => unknown) => selector(mocks.state), useAppStoreApi: () => ({ getState: () => mocks.state }), })); vi.mock("react-i18next", () => ({ Trans: ({ children }: { children?: unknown }) => children, useTranslation: () => ({ t: (key: string) => ({ "settings:sidebar": SIDEBAR_LABEL, "settings:addShortcutSection": ADD_SECTION_LABEL, "settings:sectionName": SECTION_NAME_LABEL, "settings:moveUp": MOVE_UP_LABEL, "settings:moveDown": MOVE_DOWN_LABEL, "settings:sidebarConflict": "Conflict", "settings:sidebarLoadLatest": LOAD_LATEST_LABEL, "settings:retrySave": RETRY_SAVE_LABEL, "common:loading": LOADING_LABEL, })[key] ?? key, }), })); vi.mock("@/hooks/use-responsive-breakpoint", () => ({ useResponsiveBreakpoint: () => ({ isMobile: mocks.isMobile, isFinePointer: true }), })); vi.mock("@/hooks/domains/sidebar/use-sidebar-shortcut-catalog", () => ({ useSidebarShortcutCatalog: () => ({ workspaceId: mocks.state.workspaces.activeId, catalog: mocks.catalog, loading: false, error: null, refresh: vi.fn(), }), })); vi.mock("@/lib/api/domains/settings-api", () => ({ updateUserSettings: (...args: unknown[]) => mocks.updateUserSettings(...args), fetchUserSettings: (...args: unknown[]) => mocks.fetchUserSettings(...args), })); type MockSwitchProps = ComponentProps<"button"> & { checked?: boolean; onCheckedChange?: (checked: boolean) => void; }; vi.mock("@kandev/ui/switch", () => ({ Switch: ({ checked = false, onCheckedChange, ...props }: MockSwitchProps) => (