Skip to content
Source
Sign inSign up

composerDraftOperations.test.ts

42 lines1.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 abortComposerDraftOperations,
5 startComposerDraftOperation,
6} from "./composerDraftOperations";
7​
8describe("composer draft operations", () => {
9 it("aborts every running operation for the draft and leaves other drafts alone", () => {
10 const first = startComposerDraftOperation("thread-a");
11 const second = startComposerDraftOperation("thread-a");
12 const other = startComposerDraftOperation("thread-b");
13​
14 abortComposerDraftOperations("thread-a");
15​
16 expect(first.signal.aborted).toBe(true);
17 expect(second.signal.aborted).toBe(true);
18 expect(other.signal.aborted).toBe(false);
19 other.finish();
20 });
21​
22 it("does not abort an operation that finished before the draft switched", () => {
23 const finished = startComposerDraftOperation("thread-c");
24 finished.finish();
25 const running = startComposerDraftOperation("thread-c");
26​
27 abortComposerDraftOperations("thread-c");
28​
29 expect(finished.signal.aborted).toBe(false);
30 expect(running.signal.aborted).toBe(true);
31 });
32​
33 it("keeps tracking an operation started after an abort when an older one finishes", () => {
34 const before = startComposerDraftOperation("thread-d");
35 abortComposerDraftOperations("thread-d");
36 const after = startComposerDraftOperation("thread-d");
37 before.finish();
38 abortComposerDraftOperations("thread-d");
39​
40 expect(after.signal.aborted).toBe(true);
41 });
42});