|
|
@@ -1141,39 +1141,26 @@ describe('timeline projection', () => {
|
|
|
describe('session log export', () => {
|
|
|
afterEach(() => {
|
|
|
vi.unstubAllGlobals()
|
|
|
- Reflect.deleteProperty(URL, 'createObjectURL')
|
|
|
Reflect.deleteProperty(HTMLAnchorElement.prototype, 'click')
|
|
|
})
|
|
|
|
|
|
it('downloads the host-streamed ZIP with descendants on click', async () => {
|
|
|
- // exportLog always fetches a URL instance, so the mock's shape stays narrow.
|
|
|
- const fetchMock = vi.fn(async (input: URL) => {
|
|
|
- expect(input.pathname).toBe('/api/session.export')
|
|
|
- expect(input.searchParams.get('sessionId')).toBe(SID)
|
|
|
- expect(input.searchParams.get('includeDescendants')).toBe('true')
|
|
|
- return new Response('zip-bytes')
|
|
|
- })
|
|
|
- vi.stubGlobal('fetch', fetchMock)
|
|
|
- const createObjectURL = vi.fn(() => 'blob:export')
|
|
|
- URL.createObjectURL = createObjectURL
|
|
|
const clickAnchor = vi.fn()
|
|
|
HTMLAnchorElement.prototype.click = clickAnchor
|
|
|
const b = await bench(historySnapshot(NODES))
|
|
|
mount(b.slots)
|
|
|
fireEvent.click(screen.getByRole('tab', { name: 'Trajectory' }))
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Export session log' }))
|
|
|
- await vi.waitFor(() => {
|
|
|
- expect(fetchMock).toHaveBeenCalledOnce()
|
|
|
- })
|
|
|
- // The blob download lands a few microtasks after the fetch settles.
|
|
|
- await vi.waitFor(() => {
|
|
|
- expect(createObjectURL).toHaveBeenCalled()
|
|
|
- })
|
|
|
- expect(clickAnchor).toHaveBeenCalled()
|
|
|
+ await vi.waitFor(() => { expect(clickAnchor).toHaveBeenCalledOnce() })
|
|
|
+ const anchor = clickAnchor.mock.contexts[0] as HTMLAnchorElement
|
|
|
+ const url = new URL(anchor.href)
|
|
|
+ expect(url.pathname).toBe('/api/session.export')
|
|
|
+ expect(url.searchParams.get('sessionId')).toBe(SID)
|
|
|
+ expect(url.searchParams.get('includeDescendants')).toBe('true')
|
|
|
})
|
|
|
|
|
|
- it('surfaces the download failure in the visible alert bar', async () => {
|
|
|
- vi.stubGlobal('fetch', vi.fn(async () => new Response('boom', { status: 404 })))
|
|
|
+ it('surfaces a browser handoff failure in the visible alert bar', async () => {
|
|
|
+ HTMLAnchorElement.prototype.click = vi.fn(() => { throw new Error('download denied') })
|
|
|
const b = await bench(historySnapshot(NODES))
|
|
|
mount(b.slots)
|
|
|
fireEvent.click(screen.getByRole('tab', { name: 'Trajectory' }))
|
|
|
@@ -1181,7 +1168,7 @@ describe('session log export', () => {
|
|
|
await vi.waitFor(() => {
|
|
|
const alert = screen.queryByRole('alert')
|
|
|
expect(alert).not.toBeNull()
|
|
|
- expect(alert!.textContent).toContain('HTTP 404')
|
|
|
+ expect(alert!.textContent).toContain('download denied')
|
|
|
})
|
|
|
})
|
|
|
})
|