| 1 | import { afterEach, describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { appAtomRegistry } from "./atom-registry"; |
| 4 | import { |
| 5 | clearThreadComposerError, |
| 6 | clearThreadComposerErrorsForEnvironment, |
| 7 | setThreadComposerError, |
| 8 | threadComposerErrorsAtom, |
| 9 | } from "./thread-composer-error"; |
| 10 | |
| 11 | afterEach(() => { |
| 12 | appAtomRegistry.set(threadComposerErrorsAtom, {}); |
| 13 | }); |
| 14 | |
| 15 | describe("thread composer errors", () => { |
| 16 | it("clears a message-scoped error only for that message", () => { |
| 17 | setThreadComposerError("environment-1:thread-1", "rejected", "message-1"); |
| 18 | |
| 19 | clearThreadComposerError("environment-1:thread-1", "message-2"); |
| 20 | expect(appAtomRegistry.get(threadComposerErrorsAtom)["environment-1:thread-1"]?.message).toBe( |
| 21 | "rejected", |
| 22 | ); |
| 23 | |
| 24 | clearThreadComposerError("environment-1:thread-1"); |
| 25 | expect(appAtomRegistry.get(threadComposerErrorsAtom)).toEqual({}); |
| 26 | }); |
| 27 | |
| 28 | it("clears every thread's error for a removed environment and no others", () => { |
| 29 | setThreadComposerError("environment-1:thread-1", "one"); |
| 30 | setThreadComposerError("environment-1:thread-2", "two"); |
| 31 | setThreadComposerError("environment-10:thread-1", "other environment"); |
| 32 | |
| 33 | clearThreadComposerErrorsForEnvironment("environment-1"); |
| 34 | |
| 35 | expect(Object.keys(appAtomRegistry.get(threadComposerErrorsAtom))).toEqual([ |
| 36 | "environment-10:thread-1", |
| 37 | ]); |
| 38 | }); |
| 39 | }); |