@@ -965,4 +965,159 @@ describe("Comment", () => {
965965 ) ;
966966 } ) ;
967967 } ) ;
968+
969+ describe ( "Undo deletion popup for comments (bug 1999154)" , ( ) => {
970+ let pages ;
971+
972+ beforeEach ( async ( ) => {
973+ pages = await loadAndWait (
974+ "tracemonkey.pdf" ,
975+ ".annotationEditorLayer" ,
976+ "page-fit" ,
977+ null ,
978+ { enableComment : true }
979+ ) ;
980+ } ) ;
981+
982+ afterEach ( async ( ) => {
983+ await closePages ( pages ) ;
984+ } ) ;
985+
986+ it ( "must check that deleting a comment can be undone using the undo button" , async ( ) => {
987+ await Promise . all (
988+ pages . map ( async ( [ browserName , page ] ) => {
989+ await switchToHighlight ( page ) ;
990+ await highlightSpan ( page , 1 , "Abstract" ) ;
991+ const editorSelector = getEditorSelector ( 0 ) ;
992+ const comment = "Test comment for undo" ;
993+ await editComment ( page , editorSelector , comment ) ;
994+
995+ // Stay in highlight mode - don't disable it
996+ await waitAndClick (
997+ page ,
998+ `${ editorSelector } .annotationCommentButton`
999+ ) ;
1000+
1001+ await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1002+ await waitAndClick ( page , "button.commentPopupDelete" ) ;
1003+
1004+ await page . waitForSelector ( "#editorUndoBar" , { visible : true } ) ;
1005+ await page . waitForSelector ( "#editorUndoBarUndoButton" , {
1006+ visible : true ,
1007+ } ) ;
1008+ await page . click ( "#editorUndoBarUndoButton" ) ;
1009+
1010+ // Check that the comment is restored by hovering to show the popup
1011+ await page . hover ( `${ editorSelector } .annotationCommentButton` ) ;
1012+ await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1013+ const popupText = await page . evaluate (
1014+ ( ) =>
1015+ document . querySelector ( "#commentPopup .commentPopupText" )
1016+ ?. textContent
1017+ ) ;
1018+ expect ( popupText ) . withContext ( `In ${ browserName } ` ) . toEqual ( comment ) ;
1019+ } )
1020+ ) ;
1021+ } ) ;
1022+
1023+ it ( "must check that the undo deletion popup displays 'Comment removed' message" , async ( ) => {
1024+ await Promise . all (
1025+ pages . map ( async ( [ browserName , page ] ) => {
1026+ await switchToHighlight ( page ) ;
1027+ await highlightSpan ( page , 1 , "Abstract" ) ;
1028+ const editorSelector = getEditorSelector ( 0 ) ;
1029+ await editComment ( page , editorSelector , "Test comment" ) ;
1030+
1031+ // Stay in highlight mode - don't disable it
1032+ await waitAndClick (
1033+ page ,
1034+ `${ editorSelector } .annotationCommentButton`
1035+ ) ;
1036+
1037+ await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1038+ await waitAndClick ( page , "button.commentPopupDelete" ) ;
1039+
1040+ await page . waitForFunction ( ( ) => {
1041+ const messageElement = document . querySelector (
1042+ "#editorUndoBarMessage"
1043+ ) ;
1044+ return messageElement && messageElement . textContent . trim ( ) !== "" ;
1045+ } ) ;
1046+ const message = await page . waitForSelector ( "#editorUndoBarMessage" ) ;
1047+ const messageText = await page . evaluate (
1048+ el => el . textContent ,
1049+ message
1050+ ) ;
1051+ expect ( messageText )
1052+ . withContext ( `In ${ browserName } ` )
1053+ . toContain ( "Comment removed" ) ;
1054+ } )
1055+ ) ;
1056+ } ) ;
1057+
1058+ it ( "must check that the undo bar closes when clicking the close button" , async ( ) => {
1059+ await Promise . all (
1060+ pages . map ( async ( [ browserName , page ] ) => {
1061+ await switchToHighlight ( page ) ;
1062+ await highlightSpan ( page , 1 , "Abstract" ) ;
1063+ const editorSelector = getEditorSelector ( 0 ) ;
1064+ await editComment ( page , editorSelector , "Test comment" ) ;
1065+
1066+ // Stay in highlight mode - don't disable it
1067+ await waitAndClick (
1068+ page ,
1069+ `${ editorSelector } .annotationCommentButton`
1070+ ) ;
1071+
1072+ await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1073+ await waitAndClick ( page , "button.commentPopupDelete" ) ;
1074+
1075+ await page . waitForSelector ( "#editorUndoBar" , { visible : true } ) ;
1076+ await waitAndClick ( page , "#editorUndoBarCloseButton" ) ;
1077+ await page . waitForSelector ( "#editorUndoBar" , { hidden : true } ) ;
1078+ } )
1079+ ) ;
1080+ } ) ;
1081+
1082+ it ( "must check that deleting a comment can be undone using Ctrl+Z" , async ( ) => {
1083+ await Promise . all (
1084+ pages . map ( async ( [ browserName , page ] ) => {
1085+ await switchToHighlight ( page ) ;
1086+ await highlightSpan ( page , 1 , "Abstract" ) ;
1087+ const editorSelector = getEditorSelector ( 0 ) ;
1088+ const comment = "Test comment for Ctrl+Z undo" ;
1089+ await editComment ( page , editorSelector , comment ) ;
1090+
1091+ // Stay in highlight mode - don't disable it
1092+ await waitAndClick (
1093+ page ,
1094+ `${ editorSelector } .annotationCommentButton`
1095+ ) ;
1096+
1097+ await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1098+ await waitAndClick ( page , "button.commentPopupDelete" ) ;
1099+
1100+ await page . waitForSelector ( "#editorUndoBar" , { visible : true } ) ;
1101+
1102+ // Use Ctrl+Z to undo
1103+ await kbModifierDown ( page ) ;
1104+ await page . keyboard . press ( "z" ) ;
1105+ await kbModifierUp ( page ) ;
1106+
1107+ // The undo bar should be hidden after undo
1108+ await page . waitForSelector ( "#editorUndoBar" , { hidden : true } ) ;
1109+
1110+ // Check that the comment is restored by hovering to show the popup
1111+ await page . hover ( `${ editorSelector } .annotationCommentButton` ) ;
1112+ await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1113+ const popupText = await page . evaluate (
1114+ ( ) =>
1115+ document . querySelector ( "#commentPopup .commentPopupText" )
1116+ ?. textContent
1117+ ) ;
1118+ expect ( popupText ) . withContext ( `In ${ browserName } ` ) . toEqual ( comment ) ;
1119+ } )
1120+ ) ;
1121+ } ) ;
1122+ } ) ;
9681123} ) ;
0 commit comments