From 71e454600e90099d20448ab75fc2c96222664c39 Mon Sep 17 00:00:00 2001 From: Ku6epXBOCTuK Date: Sat, 18 Jul 2026 07:58:48 +0500 Subject: [PATCH] test: add config and config related tests --- src/config.test.ts | 27 ++++++++++++++++++++++++++ src/model/taskFile.test.ts | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/config.test.ts create mode 100644 src/model/taskFile.test.ts diff --git a/src/config.test.ts b/src/config.test.ts new file mode 100644 index 0000000..eb752fa --- /dev/null +++ b/src/config.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from "vitest"; +import { SettingKey, getConfigSection, getSettingDefault } from "./config"; + +describe("config", () => { + it("getConfigSection returns the section prefix from package.json", () => { + const section = getConfigSection(); + expect(typeof section).toBe("string"); + expect(section).not.toHaveLength(0); + }); + + it("getSettingDefault returns a non-empty default for projectPath", () => { + const value = getSettingDefault("projectPath"); + expect(typeof value).toBe("string"); + expect(value).not.toHaveLength(0); + }); + + it("getSettingDefault returns a string for globalPath (may be empty)", () => { + const value = getSettingDefault("globalPath"); + expect(typeof value).toBe("string"); + }); + + it("throws for missing setting key", () => { + expect(() => getSettingDefault("missing" as SettingKey)).toThrow( + "Missing package.json setting", + ); + }); +}); diff --git a/src/model/taskFile.test.ts b/src/model/taskFile.test.ts new file mode 100644 index 0000000..e4063d7 --- /dev/null +++ b/src/model/taskFile.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from "vitest"; +import { + MAX_TASK_TITLE_LENGTH, + TASK_FILE_EXTENSION, + TASK_LANGUAGE_ID, + isTaskFileName, +} from "./taskFile"; + +describe("taskFile", () => { + it("package.json defines a non-empty file extension", () => { + expect(typeof TASK_FILE_EXTENSION).toBe("string"); + expect(TASK_FILE_EXTENSION).not.toHaveLength(0); + }); + + it("package.json defines a non-empty language id", () => { + expect(typeof TASK_LANGUAGE_ID).toBe("string"); + expect(TASK_LANGUAGE_ID).not.toHaveLength(0); + }); + + it("max title length is a positive number", () => { + expect(typeof MAX_TASK_TITLE_LENGTH).toBe("number"); + expect(Number.isFinite(MAX_TASK_TITLE_LENGTH)).toBe(true); + expect(MAX_TASK_TITLE_LENGTH).toBeGreaterThan(0); + }); + + it("isTaskFileName uses the configured extension", () => { + expect(isTaskFileName(`task${TASK_FILE_EXTENSION}`)).toBe(true); + expect(isTaskFileName(TASK_FILE_EXTENSION)).toBe(true); + }); + + it("isTaskFileName rejects non-matching extensions", () => { + expect(isTaskFileName("task.md")).toBe(false); + expect(isTaskFileName("task.xflow")).toBe(false); + }); + + it("isTaskFileName rejects empty string", () => { + expect(isTaskFileName("")).toBe(false); + }); +});