feat: add tags workflow
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { findFieldRange, replaceFrontmatterField } from "./frontmatterFields";
|
||||
import {
|
||||
findFieldRange,
|
||||
formatTagsYamlValue,
|
||||
replaceFrontmatterField,
|
||||
setFrontmatterTags,
|
||||
} from "./frontmatterFields";
|
||||
|
||||
const sample = `---
|
||||
id: abc
|
||||
title: Hello
|
||||
status: todo
|
||||
priority: medium
|
||||
tags: [old]
|
||||
---
|
||||
|
||||
Body
|
||||
@@ -47,3 +53,26 @@ describe("findFieldRange", () => {
|
||||
expect(line.slice(range!.startCol, range!.endCol)).toBe("todo");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatTagsYamlValue", () => {
|
||||
it("formats empty and simple lists", () => {
|
||||
expect(formatTagsYamlValue([])).toBe("[]");
|
||||
expect(formatTagsYamlValue(["bug", "frontend"])).toBe(
|
||||
"[bug, frontend]",
|
||||
);
|
||||
});
|
||||
|
||||
it("quotes tags with spaces", () => {
|
||||
expect(formatTagsYamlValue(["my tag"])).toBe('["my tag"]');
|
||||
});
|
||||
});
|
||||
|
||||
describe("setFrontmatterTags", () => {
|
||||
it("replaces the tags line", () => {
|
||||
const result = setFrontmatterTags(sample, ["bug", "docs"]);
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(result.content).toContain("tags: [bug, docs]");
|
||||
expect(result.content).not.toContain("tags: [old]");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user