| 1 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | import { useSessionDetailRuntimeStore } from '../../../src/renderer/src/store/sessionDetailRuntimeStore' |
| 3 | |
| 4 | describe('session detail runtime store', () => { |
| 5 | beforeEach(() => { |
| 6 | useSessionDetailRuntimeStore.getState().setAddElementHandler(null) |
| 7 | }) |
| 8 | |
| 9 | it('delegates element insertion to the registered editor handler', async () => { |
| 10 | const handler = vi.fn().mockResolvedValue(true) |
| 11 | useSessionDetailRuntimeStore.getState().setAddElementHandler(handler) |
| 12 | |
| 13 | const result = await useSessionDetailRuntimeStore |
| 14 | .getState() |
| 15 | .addElement('./images/generated.png', 'generated.png', { |
| 16 | persistImmediately: true, |
| 17 | asBackground: true |
| 18 | }) |
| 19 | |
| 20 | expect(result).toBe(true) |
| 21 | expect(handler).toHaveBeenCalledWith('./images/generated.png', 'generated.png', { |
| 22 | persistImmediately: true, |
| 23 | asBackground: true |
| 24 | }) |
| 25 | }) |
| 26 | |
| 27 | it('returns false when the editor is unavailable', async () => { |
| 28 | await expect( |
| 29 | useSessionDetailRuntimeStore |
| 30 | .getState() |
| 31 | .addElement('./images/generated.png', 'generated.png') |
| 32 | ).resolves.toBe(false) |
| 33 | }) |
| 34 | }) |
| 35 |