Files
agentic-mobile-control/cloud-console/src/taskCancellation.test.ts
T
q792602257 4d04d7ac83 Add Cloud Console cancel action and cancelled status
- 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.
2026-07-15 18:43:55 +08:00

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);
});
});