11import { describe , it , expect , vi , beforeEach } from 'vitest'
22import { mount , flushSync } from 'svelte'
3- import AiNotification from './AiNotification.svelte'
43
54// Track the state object so tests can mutate it
65let mockState = {
@@ -17,17 +16,22 @@ let mockState = {
1716
1817vi . mock ( './ai-state.svelte' , ( ) => ( {
1918 getAiState : ( ) => mockState ,
20- initAiState : vi . fn ( ( ) => Promise . resolve ( ( ) => { } ) ) ,
2119 handleDownload : vi . fn ( ( ) => Promise . resolve ( ) ) ,
2220 handleCancel : vi . fn ( ( ) => Promise . resolve ( ) ) ,
2321 handleDismiss : vi . fn ( ( ) => Promise . resolve ( ) ) ,
2422 handleOptOut : vi . fn ( ( ) => Promise . resolve ( ) ) ,
2523 handleGotIt : vi . fn ( ) ,
2624} ) )
2725
26+ vi . mock ( '$lib/ui/toast' , ( ) => ( {
27+ addToast : vi . fn ( ) ,
28+ dismissToast : vi . fn ( ) ,
29+ } ) )
30+
31+ import AiToastContent from './AiToastContent.svelte'
2832import { handleDownload , handleCancel , handleDismiss , handleOptOut , handleGotIt } from './ai-state.svelte'
2933
30- describe ( 'AiNotification ' , ( ) => {
34+ describe ( 'AiToastContent ' , ( ) => {
3135 beforeEach ( ( ) => {
3236 vi . clearAllMocks ( )
3337 mockState = {
@@ -46,7 +50,7 @@ describe('AiNotification', () => {
4650 it ( 'renders offer notification with download size and settings hint' , ( ) => {
4751 mockState . notificationState = 'offer'
4852 const target = document . createElement ( 'div' )
49- mount ( AiNotification , { target } )
53+ mount ( AiToastContent , { target } )
5054
5155 const description = target . querySelector ( '.ai-description' )
5256 expect ( description ?. textContent ) . toContain ( '2.1 GB' )
@@ -57,17 +61,14 @@ describe('AiNotification', () => {
5761
5862 it ( 'renders nothing when state is hidden' , ( ) => {
5963 const target = document . createElement ( 'div' )
60- mount ( AiNotification , { target } )
61- expect ( target . querySelector ( '.ai-notification ' ) ) . toBeNull ( )
64+ mount ( AiToastContent , { target } )
65+ expect ( target . querySelector ( '.ai-content ' ) ) . toBeNull ( )
6266 } )
6367
6468 it ( "renders offer notification with Download, Not now, and I don't want AI buttons" , ( ) => {
6569 mockState . notificationState = 'offer'
6670 const target = document . createElement ( 'div' )
67- mount ( AiNotification , { target } )
68-
69- const notification = target . querySelector ( '.ai-notification' )
70- expect ( notification ) . not . toBeNull ( )
71+ mount ( AiToastContent , { target } )
7172
7273 const title = target . querySelector ( '.ai-title' )
7374 expect ( title ?. textContent ) . toBe ( 'AI features available' )
@@ -82,7 +83,7 @@ describe('AiNotification', () => {
8283 it ( 'calls handleDownload when Download is clicked' , ( ) => {
8384 mockState . notificationState = 'offer'
8485 const target = document . createElement ( 'div' )
85- mount ( AiNotification , { target } )
86+ mount ( AiToastContent , { target } )
8687
8788 const downloadButton = target . querySelector ( '.ai-button.primary' ) as HTMLButtonElement
8889 downloadButton . click ( )
@@ -94,7 +95,7 @@ describe('AiNotification', () => {
9495 it ( 'calls handleDismiss when Not now is clicked' , ( ) => {
9596 mockState . notificationState = 'offer'
9697 const target = document . createElement ( 'div' )
97- mount ( AiNotification , { target } )
98+ mount ( AiToastContent , { target } )
9899
99100 const dismissButton = target . querySelector ( '.ai-button.secondary' ) as HTMLButtonElement
100101 dismissButton . click ( )
@@ -106,7 +107,7 @@ describe('AiNotification', () => {
106107 it ( "calls handleOptOut when I don't want AI is clicked" , ( ) => {
107108 mockState . notificationState = 'offer'
108109 const target = document . createElement ( 'div' )
109- mount ( AiNotification , { target } )
110+ mount ( AiToastContent , { target } )
110111
111112 const optOutButton = target . querySelector ( '.ai-button.tertiary' ) as HTMLButtonElement
112113 optOutButton . click ( )
@@ -121,7 +122,7 @@ describe('AiNotification', () => {
121122 mockState . progressText = '12% — 500.0 KB / 4.0 MB — 100.0 KB/s — 35s remaining'
122123
123124 const target = document . createElement ( 'div' )
124- mount ( AiNotification , { target } )
125+ mount ( AiToastContent , { target } )
125126
126127 const title = target . querySelector ( '.ai-title' )
127128 expect ( title ?. textContent ) . toBe ( 'Downloading AI model...' )
@@ -135,7 +136,7 @@ describe('AiNotification', () => {
135136 mockState . downloadProgress = null
136137
137138 const target = document . createElement ( 'div' )
138- mount ( AiNotification , { target } )
139+ mount ( AiToastContent , { target } )
139140
140141 const progressText = target . querySelector ( '.ai-progress-text' )
141142 expect ( progressText ?. textContent ) . toBe ( 'Starting download...' )
@@ -146,7 +147,7 @@ describe('AiNotification', () => {
146147 mockState . downloadProgress = { bytesDownloaded : 100 , totalBytes : 1000 , speed : 50 , etaSeconds : 18 }
147148
148149 const target = document . createElement ( 'div' )
149- mount ( AiNotification , { target } )
150+ mount ( AiToastContent , { target } )
150151
151152 const cancelButton = target . querySelector ( '.ai-button.secondary' ) as HTMLButtonElement
152153 cancelButton . click ( )
@@ -159,7 +160,7 @@ describe('AiNotification', () => {
159160 mockState . notificationState = 'installing'
160161
161162 const target = document . createElement ( 'div' )
162- mount ( AiNotification , { target } )
163+ mount ( AiToastContent , { target } )
163164
164165 const title = target . querySelector ( '.ai-title' )
165166 expect ( title ?. textContent ) . toBe ( 'Setting up AI...' )
@@ -175,7 +176,7 @@ describe('AiNotification', () => {
175176 mockState . notificationState = 'ready'
176177
177178 const target = document . createElement ( 'div' )
178- mount ( AiNotification , { target } )
179+ mount ( AiToastContent , { target } )
179180
180181 const title = target . querySelector ( '.ai-title' )
181182 expect ( title ?. textContent ) . toBe ( 'AI ready' )
@@ -188,7 +189,7 @@ describe('AiNotification', () => {
188189 mockState . notificationState = 'ready'
189190
190191 const target = document . createElement ( 'div' )
191- mount ( AiNotification , { target } )
192+ mount ( AiToastContent , { target } )
192193
193194 const button = target . querySelector ( '.ai-button.primary' ) as HTMLButtonElement
194195 button . click ( )
@@ -203,7 +204,7 @@ describe('AiNotification', () => {
203204 mockState . progressText = '50% — 2.0 MB / 4.0 MB'
204205
205206 const target = document . createElement ( 'div' )
206- mount ( AiNotification , { target } )
207+ mount ( AiToastContent , { target } )
207208
208209 const progressBar = target . querySelector ( '.progress-bar-fill' ) as HTMLElement
209210 expect ( progressBar ) . not . toBeNull ( )
0 commit comments