/** * Tests for the left tool window: hide and show, and keyboard resizing * clamped to the allowed range. */ import { mount } from "@vue/test-utils"; import { describe, expect, it } from "vitest"; import ToolWindow from "../../src/components/layout/ToolWindow.vue"; describe("ToolWindow", () => { it("hides to a stripe and shows again", async () => { const wrapper = mount(ToolWindow, { props: { title: "Project", open: true, "onUpdate:open": (open: boolean) => wrapper.setProps({ open }), }, slots: { default: "
tree
" }, }); expect(wrapper.find("[data-test=content]").exists()).toBe(true); await wrapper.get("[data-test=tool-window-hide]").trigger("click"); expect(wrapper.find("[data-test=content]").exists()).toBe(false); expect(wrapper.find("[data-test=tool-window-stripe]").exists()).toBe(true); await wrapper.get("[data-test=tool-window-show]").trigger("click"); expect(wrapper.find("[data-test=content]").exists()).toBe(true); }); it("resizes with the keyboard within the limits", async () => { const wrapper = mount(ToolWindow, { props: { title: "Project", width: 200, minWidth: 150, maxWidth: 230, "onUpdate:width": (width: number) => wrapper.setProps({ width }), }, }); const splitter = wrapper.get("[data-test=tool-window-splitter]"); await splitter.trigger("keydown", { key: "ArrowRight" }); expect(wrapper.get("[data-test=tool-window]").attributes("style")).toContain("width: 212px"); await splitter.trigger("keydown", { key: "ArrowRight", shiftKey: true }); expect(wrapper.get("[data-test=tool-window]").attributes("style")).toContain("width: 230px"); await splitter.trigger("keydown", { key: "ArrowLeft", shiftKey: true }); await splitter.trigger("keydown", { key: "ArrowLeft", shiftKey: true }); expect(wrapper.get("[data-test=tool-window]").attributes("style")).toContain("width: 150px"); }); });