RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { newTask, readTask, editTask } from "../../../../src/lib/features/pm/storage/notes.ts";
|
||||
import { validateFields, type TaskFields } from "../../../../src/lib/features/pm/model/model.ts";
|
||||
|
||||
const fields: TaskFields = {
|
||||
status: "todo",
|
||||
tags: [],
|
||||
sessions: [],
|
||||
archived: false,
|
||||
};
|
||||
|
||||
test("optional card fields survive moves and can be removed without changing other note data", () => {
|
||||
const note = newTask(
|
||||
"Customer work",
|
||||
{
|
||||
...fields,
|
||||
color: "purple",
|
||||
assignees: ["Alex", "Northwind"],
|
||||
customFields: [
|
||||
{ name: "Customer ID", value: "0012" },
|
||||
{ name: "Contact", value: "[email protected]" },
|
||||
],
|
||||
},
|
||||
"Keep **these details**.\n",
|
||||
);
|
||||
const source = note.source.replace(
|
||||
" schema: 1",
|
||||
" extra: keep-me # future property\n schema: 1",
|
||||
);
|
||||
const task = readTask(note.path, source)!;
|
||||
assert.equal(task.color, "purple");
|
||||
assert.deepEqual(task.assignees, ["Alex", "Northwind"]);
|
||||
assert.equal(task.customFields?.[0].value, "0012");
|
||||
const moved = readTask(
|
||||
note.path,
|
||||
editTask(task, { status: "done", listId: "done" }),
|
||||
)!;
|
||||
assert.deepEqual(moved.customFields, task.customFields);
|
||||
assert.equal(moved.color, "purple");
|
||||
const cleared = editTask(moved, {
|
||||
color: undefined,
|
||||
assignees: [],
|
||||
customFields: [],
|
||||
});
|
||||
assert.ok(cleared.includes("extra: keep-me # future property"));
|
||||
assert.equal(readTask(note.path, cleared)!.body, task.body);
|
||||
assert.equal(readTask(note.path, cleared)!.color, undefined);
|
||||
assert.deepEqual(readTask(note.path, cleared)!.customFields, []);
|
||||
});
|
||||
|
||||
test("invalid optional fields and duplicate names cannot enter saved notes", () => {
|
||||
for (const patch of [
|
||||
{ color: "url(bad)" },
|
||||
{ assignees: "Alex" },
|
||||
{ assignees: [1] },
|
||||
{ customFields: [null] },
|
||||
{ customFields: [{ name: "", value: "x" }] },
|
||||
{
|
||||
customFields: [
|
||||
{ name: "ID", value: "1" },
|
||||
{ name: " id ", value: "2" },
|
||||
],
|
||||
},
|
||||
])
|
||||
assert.throws(() => validateFields({ ...fields, ...patch } as TaskFields));
|
||||
const old = newTask("Basic", fields);
|
||||
assert.equal(readTask(old.path, old.source)!.color, undefined);
|
||||
});
|
||||
Reference in New Issue
Block a user