mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Tiling compositors ignore a client's minimum size, so a tile narrower than 800 px laid the webview out at 800 px and scaled it down. The minimum is now 400 px on every platform. At that width the welcome page header and action tiles wrap, the title bar's run and VCS widgets ellipsize instead of covering the toolbar, dialog footers wrap, and below 560 px the left and right tool windows collapse (their stripe buttons stay, the saved layout is unchanged, a wider window brings them back). Closes #3046 Co-authored-by: TaylorBurke <TaylorBurke@users.noreply.github.com>
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { registerToolWindow } from "./contributions";
|
|
import { installNarrowWindow, NARROW_WINDOW_QUERY } from "./narrowWindow";
|
|
import { isToolWindowVisible, loadToolWindowLayout, resetToolWindowLayout, showToolWindow } from "./toolwindows/store";
|
|
|
|
const Empty = () => null;
|
|
|
|
/** A matchMedia whose result a test flips, firing the change listeners. */
|
|
function stubMedia(initial: boolean) {
|
|
const listeners = new Set<() => void>();
|
|
const query = {
|
|
matches: initial,
|
|
addEventListener: (_: string, fn: () => void) => listeners.add(fn),
|
|
removeEventListener: (_: string, fn: () => void) => listeners.delete(fn),
|
|
};
|
|
vi.stubGlobal("matchMedia", () => query);
|
|
return {
|
|
set(matches: boolean) {
|
|
query.matches = matches;
|
|
listeners.forEach((fn) => fn());
|
|
},
|
|
listeners,
|
|
};
|
|
}
|
|
|
|
let disposers: Array<() => void> = [];
|
|
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
resetToolWindowLayout();
|
|
disposers = [
|
|
registerToolWindow({ id: "project", title: "Project", icon: "folder", anchor: "left", component: Empty }),
|
|
];
|
|
loadToolWindowLayout("/work/a");
|
|
});
|
|
|
|
afterEach(() => {
|
|
disposers.forEach((d) => d());
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("installNarrowWindow", () => {
|
|
it("collapses the sides when the window narrows and restores them when it widens", () => {
|
|
const media = stubMedia(false);
|
|
const dispose = installNarrowWindow();
|
|
expect(isToolWindowVisible("project")).toBe(true);
|
|
media.set(true);
|
|
expect(isToolWindowVisible("project")).toBe(false);
|
|
media.set(false);
|
|
expect(isToolWindowVisible("project")).toBe(true);
|
|
dispose();
|
|
expect(media.listeners.size).toBe(0);
|
|
});
|
|
|
|
it("collapses at startup in a narrow window and again for the next project", () => {
|
|
stubMedia(true);
|
|
const dispose = installNarrowWindow();
|
|
expect(isToolWindowVisible("project")).toBe(false);
|
|
loadToolWindowLayout("/work/b");
|
|
expect(isToolWindowVisible("project")).toBe(false);
|
|
showToolWindow("project");
|
|
expect(isToolWindowVisible("project")).toBe(true);
|
|
dispose();
|
|
});
|
|
|
|
it("collapses again when the same project reopens", () => {
|
|
stubMedia(true);
|
|
const dispose = installNarrowWindow();
|
|
showToolWindow("project");
|
|
loadToolWindowLayout("/work/a");
|
|
expect(isToolWindowVisible("project")).toBe(false);
|
|
dispose();
|
|
});
|
|
|
|
it("does nothing where matchMedia is missing", () => {
|
|
vi.stubGlobal("matchMedia", undefined);
|
|
expect(() => installNarrowWindow()()).not.toThrow();
|
|
expect(isToolWindowVisible("project")).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("narrow window breakpoint", () => {
|
|
it("is the one the title bar and welcome page stylesheets use", () => {
|
|
for (const file of ["./TitleBar.module.css", "../features/welcome/Welcome.module.css"]) {
|
|
const css = readFileSync(new URL(file, import.meta.url), "utf8");
|
|
expect(css).toContain(`@media ${NARROW_WINDOW_QUERY}`);
|
|
}
|
|
});
|
|
});
|