@@ -17,6 +17,7 @@ import {
1717 awaitPromise ,
1818 clearEditors ,
1919 closePages ,
20+ countStorageEntries ,
2021 dragAndDrop ,
2122 getAnnotationSelector ,
2223 getEditors ,
@@ -1236,3 +1237,43 @@ describe("Ink must update its color", () => {
12361237 ) ;
12371238 } ) ;
12381239} ) ;
1240+
1241+ describe ( "Ink must committed when leaving the tab" , ( ) => {
1242+ let pages ;
1243+
1244+ beforeEach ( async ( ) => {
1245+ pages = await loadAndWait ( "empty.pdf" , ".annotationEditorLayer" ) ;
1246+ } ) ;
1247+
1248+ afterEach ( async ( ) => {
1249+ await closePages ( pages ) ;
1250+ } ) ;
1251+
1252+ it ( "must check that the annotation storage is updated when leaving the tab" , async ( ) => {
1253+ await Promise . all (
1254+ pages . map ( async ( [ browserName , page ] ) => {
1255+ await switchToInk ( page ) ;
1256+
1257+ const rect = await getRect ( page , ".annotationEditorLayer" ) ;
1258+
1259+ const x = rect . x + 20 ;
1260+ const y = rect . y + 20 ;
1261+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
1262+
1263+ const count = await countStorageEntries ( page ) ;
1264+ expect ( count ) . withContext ( `In ${ browserName } ` ) . toEqual ( 0 ) ;
1265+
1266+ // Trigger the beforeunload event to force auto-commit
1267+ await page . evaluate ( ( ) => {
1268+ window . dispatchEvent ( new Event ( "beforeunload" ) ) ;
1269+ } ) ;
1270+
1271+ // Wait for the annotation to be committed to storage
1272+ await waitForStorageEntries ( page , 1 ) ;
1273+
1274+ const countAfter = await countStorageEntries ( page ) ;
1275+ expect ( countAfter ) . withContext ( `In ${ browserName } ` ) . toEqual ( 1 ) ;
1276+ } )
1277+ ) ;
1278+ } ) ;
1279+ } ) ;
0 commit comments