1import { describe, expect, it } from "vite-plus/test";
2
3import * as ThreadUndo from "./threadUndo";
4
5describe("thread action ownership", () => {
6 it("keeps claims for different action kinds independent", () => {
7 const pin = ThreadUndo.begin("pin", "env/shared");
8 const archive = ThreadUndo.begin("archive", "env/shared");
9 ThreadUndo.invalidate("pin", "env/shared");
10 expect(pin.isCurrent()).toBe(false);
11 expect(archive.isCurrent()).toBe(true);
12 archive.finish();
13 });
14
15 it("does not revive the first Undo after a later pin and unpin", () => {
16 const firstUnpin = ThreadUndo.begin("pin", "env/thread");
17 ThreadUndo.invalidate("pin", "env/thread");
18 const secondUnpin = ThreadUndo.begin("pin", "env/thread");
19 expect(firstUnpin.isCurrent()).toBe(false);
20 expect(secondUnpin.isCurrent()).toBe(true);
21 firstUnpin.finish();
22 expect(secondUnpin.isCurrent()).toBe(true);
23 secondUnpin.finish();
24 expect(firstUnpin.isCurrent()).toBe(false);
25 });
26
27 it("rejects a late unpin completion after a newer pin started", () => {
28 const pendingUnpin = ThreadUndo.begin("pin", "env/late");
29 ThreadUndo.invalidate("pin", "env/late");
30 expect(pendingUnpin.isCurrent()).toBe(false);
31 });
32
33 it("expires an Undo without invalidating another environment or thread", () => {
34 const first = ThreadUndo.begin("pin", "one/thread");
35 const otherEnvironment = ThreadUndo.begin("pin", "two/thread");
36 const otherThread = ThreadUndo.begin("pin", "one/other");
37 first.finish();
38 expect(first.isCurrent()).toBe(false);
39 expect(otherEnvironment.isCurrent()).toBe(true);
40 expect(otherThread.isCurrent()).toBe(true);
41 otherEnvironment.finish();
42 otherThread.finish();
43 });
44});