| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { createGenerationNotificationToast } from '../../../src/renderer/src/hooks/generationNotificationToast' |
| 3 | |
| 4 | const t = (key: string, params?: Record<string, string | number>): string => { |
| 5 | if (key === 'generationNotifications.completed') return `"${params?.title}" generation completed` |
| 6 | if (key === 'generationNotifications.partial') { |
| 7 | return `"${params?.title}" completed with ${params?.count} failed page(s)` |
| 8 | } |
| 9 | if (key === 'generationNotifications.failed') return `"${params?.title}" generation failed` |
| 10 | return key |
| 11 | } |
| 12 | |
| 13 | const action = { |
| 14 | label: 'View', |
| 15 | onClick: () => {} |
| 16 | } |
| 17 | |
| 18 | describe('generation notification toast', () => { |
| 19 | it('summarizes failed jobs without showing the raw failure message', () => { |
| 20 | const toast = createGenerationNotificationToast({ |
| 21 | event: { |
| 22 | type: 'run_error', |
| 23 | payload: { |
| 24 | message: 'A very long model stack trace and job failure payload' |
| 25 | } |
| 26 | }, |
| 27 | title: 'Quarterly Review', |
| 28 | action, |
| 29 | t |
| 30 | }) |
| 31 | |
| 32 | expect(toast).toEqual({ |
| 33 | type: 'error', |
| 34 | message: '"Quarterly Review" generation failed', |
| 35 | options: { |
| 36 | action, |
| 37 | duration: 8000 |
| 38 | } |
| 39 | }) |
| 40 | expect(toast.options.description).toBeUndefined() |
| 41 | }) |
| 42 | |
| 43 | it('keeps completed and partial completion notifications informative', () => { |
| 44 | expect( |
| 45 | createGenerationNotificationToast({ |
| 46 | event: { |
| 47 | type: 'run_completed', |
| 48 | payload: { |
| 49 | failedPageCount: 2 |
| 50 | } |
| 51 | }, |
| 52 | title: 'Quarterly Review', |
| 53 | action, |
| 54 | t |
| 55 | }) |
| 56 | ).toMatchObject({ |
| 57 | type: 'warning', |
| 58 | message: '"Quarterly Review" completed with 2 failed page(s)' |
| 59 | }) |
| 60 | |
| 61 | expect( |
| 62 | createGenerationNotificationToast({ |
| 63 | event: { |
| 64 | type: 'run_completed', |
| 65 | payload: { |
| 66 | failedPageCount: 0 |
| 67 | } |
| 68 | }, |
| 69 | title: 'Quarterly Review', |
| 70 | action, |
| 71 | t |
| 72 | }) |
| 73 | ).toMatchObject({ |
| 74 | type: 'success', |
| 75 | message: '"Quarterly Review" generation completed' |
| 76 | }) |
| 77 | }) |
| 78 | }) |
| 79 |