@@ -76,6 +76,7 @@ vi.mock("./useDismissedToasts", () => ({
7676} ) ) ;
7777
7878import { ToastArea } from "./index" ;
79+ import { showTransientToast , useTransientToast } from "./transient" ;
7980
8081describe ( "ToastArea" , ( ) => {
8182 beforeEach ( ( ) => {
@@ -86,9 +87,11 @@ describe("ToastArea", () => {
8687 mocks . updateSettingsTabState . mockClear ( ) ;
8788 mocks . clearDevtoolsPreview . mockClear ( ) ;
8889 mocks . setToastActionTarget . mockClear ( ) ;
90+ useTransientToast . getState ( ) . clearToast ( ) ;
8991 } ) ;
9092
9193 afterEach ( ( ) => {
94+ useTransientToast . getState ( ) . clearToast ( ) ;
9295 cleanup ( ) ;
9396 document . body . innerHTML = "" ;
9497 vi . useRealTimers ( ) ;
@@ -139,7 +142,7 @@ describe("ToastArea", () => {
139142 expect ( toastContainer ?. style . top ) . toBe ( "88px" ) ;
140143 } ) ;
141144
142- it ( "positions the left sidebar toast relative to the main content panel" , ( ) => {
145+ it ( "centers the left sidebar toast on the main content panel" , ( ) => {
143146 const mainContentPanel = document . createElement ( "div" ) ;
144147 mainContentPanel . setAttribute ( "data-main-content-panel" , "" ) ;
145148 vi . spyOn ( mainContentPanel , "getBoundingClientRect" ) . mockReturnValue ( {
@@ -161,9 +164,9 @@ describe("ToastArea", () => {
161164 bottom : 520 ,
162165 height : 500 ,
163166 left : 300 ,
164- right : 900 ,
167+ right : 700 ,
165168 top : 20 ,
166- width : 600 ,
169+ width : 400 ,
167170 x : 300 ,
168171 y : 20 ,
169172 toJSON : ( ) => ( { } ) ,
@@ -184,6 +187,60 @@ describe("ToastArea", () => {
184187 expect ( toastContainer ?. style . top ) . toBe ( "56px" ) ;
185188 } ) ;
186189
190+ it ( "centers anchored transient toasts on the main content panel" , ( ) => {
191+ const mainContentPanel = document . createElement ( "div" ) ;
192+ mainContentPanel . setAttribute ( "data-main-content-panel" , "" ) ;
193+ vi . spyOn ( mainContentPanel , "getBoundingClientRect" ) . mockReturnValue ( {
194+ bottom : 520 ,
195+ height : 500 ,
196+ left : 200 ,
197+ right : 1_000 ,
198+ top : 20 ,
199+ width : 800 ,
200+ x : 200 ,
201+ y : 20 ,
202+ toJSON : ( ) => ( { } ) ,
203+ } ) ;
204+ document . body . appendChild ( mainContentPanel ) ;
205+
206+ const mainSurface = document . createElement ( "div" ) ;
207+ mainSurface . setAttribute ( "data-chat-floating-anchor" , "" ) ;
208+ vi . spyOn ( mainSurface , "getBoundingClientRect" ) . mockReturnValue ( {
209+ bottom : 520 ,
210+ height : 500 ,
211+ left : 300 ,
212+ right : 700 ,
213+ top : 20 ,
214+ width : 400 ,
215+ x : 300 ,
216+ y : 20 ,
217+ toJSON : ( ) => ( { } ) ,
218+ } ) ;
219+ document . body . appendChild ( mainSurface ) ;
220+
221+ showTransientToast (
222+ {
223+ id : "transcription-language-warning" ,
224+ description : "Model doesn't support all languages." ,
225+ anchor : "main-content-panel" ,
226+ } ,
227+ { durationMs : null } ,
228+ ) ;
229+
230+ render ( < ToastArea /> ) ;
231+
232+ act ( ( ) => {
233+ vi . advanceTimersByTime ( 500 ) ;
234+ } ) ;
235+
236+ const toastContainer = screen
237+ . getByText ( "Model doesn't support all languages." )
238+ . closest ( ".fixed" ) as HTMLElement | null ;
239+
240+ expect ( toastContainer ?. style . left ) . toBe ( "600px" ) ;
241+ expect ( toastContainer ?. style . top ) . toBe ( "56px" ) ;
242+ } ) ;
243+
187244 it ( "repositions the left sidebar toast when the main surface scrolls" , ( ) => {
188245 const mainSurface = document . createElement ( "div" ) ;
189246 mainSurface . setAttribute ( "data-chat-floating-anchor" , "" ) ;
0 commit comments