Файли
openidea/src/editor/core/fileAttributes.test.ts
T
l0ng-ai c59f93988b feat(vcs): PyCharm-style Commit view and one shared message dialog
- workbench/messages: one promise-based ask/confirm/confirmChecked/showError
  host replaces the per-feature confirm dialogs (app, services, vcs,
  project tree, keymap, run, database, find, LSP choice popup).
- Commit tool window: Commit | Shelf | Stash tabs as the title, IDEA's
  toolbar (Update Project, View Options, Select Opened File), Unversioned
  collapsed, Commit / Commit and Push on one row, empty-message error.
- Commit Options popup: author, sign-off, before-commit checks, Git hooks;
  vcs_commit takes CommitOptions (--author, --no-verify).
- Remove from Recent Projects asks first; refused history rewrites show an
  error dialog.

Claude-Session: https://claude.ai/code/session_01B65qLEKnkeYTGdbwhLpjCu
2026-10-23 22:59:06 +08:00

46 рядки
1.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { DocModel } from "./model/document";
import { readOnlyQuestion, toggleReadOnly } from "./fileAttributes";
function model(readOnly: boolean, extra: Partial<{ virtual: boolean; banner: string | null }> = {}) {
const meta = { readOnly, banner: extra.banner ?? (readOnly ? "readOnly" : null) };
return {
path: "/p/a.txt",
virtual: extra.virtual ?? false,
getMeta: () => meta,
setReadOnly: vi.fn((ro: boolean) => void (meta.readOnly = ro)),
} as unknown as DocModel & { setReadOnly: ReturnType<typeof vi.fn> };
}
let answer = true;
const { confirm } = vi.hoisted(() => ({ confirm: vi.fn(async () => answer) }));
vi.mock("@/workbench/messages", () => ({ confirm }));
beforeEach(() => confirm.mockClear());
describe("Toggle Read-only Attribute", () => {
it("asks before making a read-only file writable, then toggles", async () => {
const m = model(true);
answer = true;
toggleReadOnly(m);
expect(confirm).toHaveBeenCalledWith(expect.objectContaining({ title: "Make File Writable", ok: "Make Writable" }));
await vi.waitFor(() => expect(m.setReadOnly).toHaveBeenCalledWith(false));
});
it("Cancel leaves the file alone", async () => {
const m = model(false);
answer = false;
toggleReadOnly(m);
expect(confirm).toHaveBeenCalledWith(expect.objectContaining({ title: "Make File Read-only" }));
await Promise.resolve();
expect(m.setReadOnly).not.toHaveBeenCalled();
});
it("does nothing for library and binary documents", () => {
toggleReadOnly(model(true, { virtual: true }));
toggleReadOnly(model(true, { banner: "binary" }));
expect(confirm).not.toHaveBeenCalled();
expect(readOnlyQuestion("a.txt", false).confirm).toBe("Make Read-only");
});
});