- Move the storage and model of the plugin into src/lib/features/pm/ as pure TypeScript, so the skill can still bundle them. - Move the DOM interface onto the host menus, the shared tooltip, and the host icons. - A ribbon button opens Project Management. Board tabs keep the owner runestone.pm and the board-<hex> view IDs through view patterns. - Read only .runestone/pm/. Offer the plugin migration, with backups, for legacy notes. - A save, move, or delete reads only that card again. Watcher paths reach the feature. - Add Settings → Project Management and the projectManagement section. View states move to localStorage. - Background reads the boards from workspace.json. Remove api.backgrounds and the boards service. - Add yaml 2.9.1. Use the host markdown-it. - Move 18 plugin test files to tests/unit/features/pm/ and add native tests.
80 lines
3.6 KiB
TypeScript
80 lines
3.6 KiB
TypeScript
// An in-memory workspace for the tests of the native Project Management feature. It records each read.
|
|
import { defaultBoard } from "../../../../src/lib/features/pm/storage/board.ts";
|
|
import { catalogPath } from "../../../../src/lib/features/pm/storage/catalog.ts";
|
|
import { cardPath } from "../../../../src/lib/features/pm/storage/cards.ts";
|
|
import { newTask } from "../../../../src/lib/features/pm/storage/notes.ts";
|
|
import { cardsMarker, privateRulesPath } from "../../../../src/lib/features/pm/storage/persistence.ts";
|
|
import type { TaskFields, Workspace } from "../../../../src/lib/features/pm/model/model.ts";
|
|
|
|
export interface MemoryWorkspace extends Workspace {
|
|
files: Map<string, string>;
|
|
/** Each path that a read asked for, in order. A `readMany` row counts as one read. */
|
|
reads: string[];
|
|
/** Each folder that a listing asked for. */
|
|
lists: string[];
|
|
/** The number of Markdown listings. */
|
|
markdownLists: number;
|
|
}
|
|
|
|
export function memoryWorkspace(initial: Record<string, string> = {}): MemoryWorkspace {
|
|
const files = new Map(Object.entries(initial));
|
|
const reads: string[] = [], lists: string[] = [];
|
|
const parent = (path: string) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
|
|
const workspace: MemoryWorkspace = {
|
|
files, reads, lists, markdownLists: 0,
|
|
async list(path = "") {
|
|
lists.push(path);
|
|
const names = new Map<string, "file" | "folder">();
|
|
for (const file of files.keys()) {
|
|
if (path && !file.startsWith(path + "/")) continue;
|
|
const rest = path ? file.slice(path.length + 1) : file;
|
|
const name = rest.split("/")[0];
|
|
names.set(name, rest.includes("/") ? "folder" : "file");
|
|
}
|
|
return [...names].map(([name, kind]) => ({ name, rel_path: path ? `${path}/${name}` : name, kind }));
|
|
},
|
|
async listMarkdown() {
|
|
workspace.markdownLists++;
|
|
return [...files.keys()].filter(path => /\.(md|markdown|mdown)$/i.test(path) && !path.startsWith(".")).sort();
|
|
},
|
|
async read(path) {
|
|
reads.push(path);
|
|
if (!files.has(path)) throw new Error(`Missing file: ${path}`);
|
|
return files.get(path)!;
|
|
},
|
|
async readMany(paths) {
|
|
reads.push(...paths);
|
|
return paths.map(path => files.has(path) ? { path, source: files.get(path) } : { path, error: "Missing file" });
|
|
},
|
|
async readOptional(path) {
|
|
reads.push(path);
|
|
return files.get(path) ?? null;
|
|
},
|
|
async write(path, contents, expected) {
|
|
if (files.get(path) !== expected) throw new Error(`The file changed: ${path}`);
|
|
files.set(path, contents);
|
|
},
|
|
async create(path, contents) {
|
|
if (files.has(path)) throw new Error(`The file exists: ${path}`);
|
|
void parent(path);
|
|
files.set(path, contents);
|
|
},
|
|
};
|
|
return workspace;
|
|
}
|
|
|
|
export const fields = (extra: Partial<TaskFields> = {}): TaskFields => ({ status: "todo", tags: [], sessions: [], archived: false, ...extra });
|
|
|
|
/** A workspace with hidden storage: one board `board` and the given cards. */
|
|
export function hiddenWorkspace(cards: { id: string; title: string; fields?: Partial<TaskFields> }[] = [], extra: Record<string, string> = {}) {
|
|
const board = defaultBoard("board");
|
|
const files: Record<string, string> = {
|
|
[privateRulesPath]: "*\n",
|
|
[cardsMarker]: "*\n",
|
|
[catalogPath]: JSON.stringify({ schema: 1, boards: [{ name: "Board", value: board }] }, null, 2) + "\n",
|
|
...extra,
|
|
};
|
|
for (const card of cards) files[cardPath(card.id)] = newTask(card.title, fields({ title: card.title, placements: { board: { listId: "todo" } }, ...card.fields }), "Body", card.id).source;
|
|
return memoryWorkspace(files);
|
|
}
|