import { describe, it, expect, beforeEach } from "vitest"; import { PluginBusyManagerImpl } from "./plugin-busy-manager"; describe("PluginBusyManagerImpl", () => { let manager: PluginBusyManagerImpl; beforeEach(() => { manager = new PluginBusyManagerImpl(); }); describe("addTask", () => { it("should add a task", () => { const task = { taskId: "1", taskDescription: "Loading plugin" }; manager.addTask(task); expect(manager.getTasks()).toContain(task); }); it("should not add a task if taskId already exists", () => { const task1 = { taskId: "1", taskDescription: "First task" }; const task2 = { taskId: "1", taskDescription: "Duplicate task" }; manager.addTask(task1); manager.addTask(task2); const tasks = manager.getTasks(); expect(tasks.length).toBe(1); expect(tasks[0]).toEqual(task1); }); }); describe("removeTask", () => { it("should remove a task if it exists", () => { const task = { taskId: "1", taskDescription: "Loading plugin" }; manager.addTask(task); manager.removeTask("1"); expect(manager.getTasks()).not.toContain(task); }); it("should do nothing if task does not exist", () => { const task = { taskId: "1", taskDescription: "Loading plugin" }; manager.addTask(task); manager.removeTask("non-existent"); expect(manager.getTasks()).toContain(task); }); }); describe("isBusy", () => { it("should return false when no tasks exist", () => { expect(manager.isBusy()).toBe(false); }); it("should return true when tasks exist", () => { manager.addTask({ taskId: "1", taskDescription: "Busy" }); expect(manager.isBusy()).toBe(true); }); }); describe("clearAll", () => { it("should clear all tasks", () => { manager.addTask({ taskId: "1", taskDescription: "Busy" }); manager.clearAll(); expect(manager.getTasks()).toHaveLength(0); }); }); describe("getTasks", () => { it("should return current tasks", () => { const task = { taskId: "1", taskDescription: "Loading plugin" }; manager.addTask(task); expect(manager.getTasks()).toEqual([task]); }); }); });