The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): cover remote Files panel download action
xxxigmd28f2ed05b33
diff --git a/apps/desktop/src/store/file-actions.test.ts b/apps/desktop/src/store/file-actions.test.tsnew file mode 100644index 00000000000..d78780c5d21--- /dev/null+++ b/apps/desktop/src/store/file-actions.test.ts@@ -0,0 +1,58 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import { $notifications, clearNotifications } from '@/store/notifications'++vi.mock('@/lib/media', () => ({+ downloadGatewayMediaFile: vi.fn()+}))++const media = await import('@/lib/media')+const downloadGatewayMediaFile = vi.mocked(media.downloadGatewayMediaFile)++const { downloadRemoteFile, shouldOfferRemoteFileDownload } = await import('./file-actions')++describe('shouldOfferRemoteFileDownload', () => {+ it('is only for files on a remote backend', () => {+ expect(shouldOfferRemoteFileDownload(false, true)).toBe(true)+ expect(shouldOfferRemoteFileDownload(true, true)).toBe(false)+ expect(shouldOfferRemoteFileDownload(false, false)).toBe(false)+ expect(shouldOfferRemoteFileDownload(true, false)).toBe(false)+ })+})++describe('downloadRemoteFile', () => {+ beforeEach(() => {+ clearNotifications()+ downloadGatewayMediaFile.mockReset()+ })++ afterEach(() => {+ clearNotifications()+ })++ it('saves a remote gateway file through the native download bridge', async () => {+ downloadGatewayMediaFile.mockResolvedValue({ path: '/Users/me/Downloads/notes.md', saved: true })++ await downloadRemoteFile('/home/linux/project/notes.md')++ expect(downloadGatewayMediaFile).toHaveBeenCalledWith('/home/linux/project/notes.md')+ expect($notifications.get()[0]?.message).toBe('Saved')+ })++ it('stays quiet when the save dialog is canceled', async () => {+ downloadGatewayMediaFile.mockResolvedValue({ canceled: true, saved: false })++ await downloadRemoteFile('/home/linux/project/notes.md')++ expect($notifications.get()).toEqual([])+ })++ it('toasts when the gateway download fails', async () => {+ downloadGatewayMediaFile.mockRejectedValue(new Error('Desktop file download bridge is unavailable'))++ await downloadRemoteFile('/home/linux/project/notes.md')++ expect($notifications.get()[0]?.kind).toBe('error')+ expect($notifications.get()[0]?.title).toBe('Download failed')+ })+})