Skip to content
Source
Sign inSign up

threadUndo.test.ts

29 lines1.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import * as ThreadUndo from "@t3tools/client-runtime/state/thread-undo";
4​
5describe("thread action ownership", () => {
6 it("does not revive the first Undo after a later pin and unpin", () => {
7 const firstUnpin = ThreadUndo.begin("pin", "env/thread");
8 ThreadUndo.invalidate("pin", "env/thread");
9 const secondUnpin = ThreadUndo.begin("pin", "env/thread");
10 expect(firstUnpin.isCurrent()).toBe(false);
11 expect(secondUnpin.isCurrent()).toBe(true);
12 firstUnpin.finish();
13 expect(secondUnpin.isCurrent()).toBe(true);
14 secondUnpin.finish();
15 expect(firstUnpin.isCurrent()).toBe(false);
16 });
17​
18 it("expires an Undo without invalidating another environment or thread", () => {
19 const first = ThreadUndo.begin("pin", "one/thread");
20 const otherEnvironment = ThreadUndo.begin("pin", "two/thread");
21 const otherThread = ThreadUndo.begin("pin", "one/other");
22 first.finish();
23 expect(first.isCurrent()).toBe(false);
24 expect(otherEnvironment.isCurrent()).toBe(true);
25 expect(otherThread.isCurrent()).toBe(true);
26 otherEnvironment.finish();
27 otherThread.finish();
28 });
29});