- Widen TaskStatus to include "cancelled"; add it to TasksView's STATUSES filter dropdown. - Add TaskCancellationResponse type and cancelTask(taskId) to api.ts. - Add a Cancel button to TasksView's task detail panel, gated on tasks:submit and a non-terminal task status; updates the displayed status on success and surfaces errors via the existing error path. - Extract the cancellability rule into a pure taskCancellation.ts module (mirroring taskProgress.ts/plannerHistory.ts) with unit tests, since the project has no Vue component-mounting test setup. Task 6/9 of task-cancellation change.
25 lines
765 B
TypeScript
25 lines
765 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { canCancelTask } from "./taskCancellation";
|
|
import type { TaskStatus } from "./types";
|
|
|
|
describe("canCancelTask", () => {
|
|
it.each<TaskStatus>(["queued", "assigned", "dispatched"])(
|
|
"allows cancelling a %s task when the caller can submit",
|
|
(status) => {
|
|
expect(canCancelTask(status, true)).toBe(true);
|
|
},
|
|
);
|
|
|
|
it.each<TaskStatus>(["done", "failed", "cancelled"])(
|
|
"refuses to cancel a terminal %s task even when the caller can submit",
|
|
(status) => {
|
|
expect(canCancelTask(status, true)).toBe(false);
|
|
},
|
|
);
|
|
|
|
it("refuses to cancel a cancellable task when the caller lacks submit permission", () => {
|
|
expect(canCancelTask("assigned", false)).toBe(false);
|
|
});
|
|
});
|