diff --git a/src/components/AppShell.test.tsx b/src/components/AppShell.test.tsx index f402f60..b7ee66c 100644 --- a/src/components/AppShell.test.tsx +++ b/src/components/AppShell.test.tsx @@ -1,8 +1,12 @@ -import { render, screen } from "@testing-library/react"; -import { describe, expect, it } from "vitest"; +import { cleanup, fireEvent, render, screen } from "@testing-library/react"; +import { afterEach, describe, expect, it } from "vitest"; import { AppShell } from "./AppShell"; describe("AppShell", () => { + afterEach(() => { + cleanup(); + }); + it("не показывает общую ленту навигации между приложениями", () => { const view = render( @@ -37,4 +41,29 @@ describe("AppShell", () => { expect(screen.getByText("Число слов: 42")).toBeInTheDocument(); expect(screen.getByText("125%")).toBeInTheDocument(); }); + + it("отправляет команды панели быстрого доступа активному приложению", () => { + const commands: string[] = []; + function onCommand(event: WindowEventMap["qoffice-command"]) { + commands.push(event.detail.command); + } + window.addEventListener("qoffice-command", onCommand); + + try { + const view = render( + +
Рабочая область QWord
+
+ ); + const quickAccessButtons = view.container.querySelectorAll(".quick-access button"); + + fireEvent.click(quickAccessButtons[0]); + fireEvent.click(quickAccessButtons[1]); + fireEvent.click(quickAccessButtons[2]); + + expect(commands).toEqual(["save", "undo", "redo"]); + } finally { + window.removeEventListener("qoffice-command", onCommand); + } + }); }); diff --git a/src/components/AppShell.tsx b/src/components/AppShell.tsx index 5f4c3e4..4a32e7e 100644 --- a/src/components/AppShell.tsx +++ b/src/components/AppShell.tsx @@ -6,7 +6,8 @@ import { Share2, Undo2 } from "lucide-react"; -import type { ReactNode } from "react"; +import type { MouseEvent, ReactNode } from "react"; +import type { QOfficeCommand } from "../hooks/useQOfficeCommand"; import type { AppId } from "../types"; interface AppShellProps { @@ -28,6 +29,14 @@ const appTitles: Record = { mail: "Почта - QOutlook" }; +function dispatchQOfficeCommand(command: QOfficeCommand) { + window.dispatchEvent(new CustomEvent("qoffice-command", { detail: { command } })); +} + +function keepActiveEditorFocus(event: MouseEvent) { + event.preventDefault(); +} + export function AppShell({ activeApp, status, children }: AppShellProps) { const statusClassName = ["statusbar", status.className].filter(Boolean).join(" "); @@ -36,13 +45,13 @@ export function AppShell({ activeApp, status, children }: AppShellProps) {
- - -