@@ -33,6 +33,14 @@ const switchToHighlight = switchToEditor.bind(null, "Highlight");
3333const switchToStamp = switchToEditor . bind ( null , "Stamp" ) ;
3434const switchToComment = switchToEditor . bind ( null , "Comment" ) ;
3535
36+ const highlightSpan = async ( page , pageIndex , text ) => {
37+ const rect = await getSpanRectFromText ( page , pageIndex , text ) ;
38+ const x = rect . x + rect . width / 2 ;
39+ const y = rect . y + rect . height / 2 ;
40+ await page . mouse . click ( x , y , { count : 2 , delay : 100 } ) ;
41+ await page . waitForSelector ( getEditorSelector ( 0 ) ) ;
42+ } ;
43+
3644describe ( "Comment" , ( ) => {
3745 describe ( "Comment edit dialog must be visible in ltr" , ( ) => {
3846 let pages ;
@@ -417,5 +425,48 @@ describe("Comment", () => {
417425 } )
418426 ) ;
419427 } ) ;
428+
429+ it ( "must check that comments are in chronological order" , async ( ) => {
430+ await Promise . all (
431+ pages . map ( async ( [ browserName , page ] ) => {
432+ await switchToComment ( page ) ;
433+
434+ const checkDates = async ( ) => {
435+ const dates = await page . evaluate ( ( ) =>
436+ Array . from (
437+ document . querySelectorAll (
438+ `#editorCommentParamsToolbar ul > li > time`
439+ )
440+ ) . map ( time => new Date ( time . getAttribute ( "datetime" ) ) )
441+ ) ;
442+ for ( let i = 0 ; i < dates . length - 1 ; i ++ ) {
443+ expect ( dates [ i ] )
444+ . withContext ( `In ${ browserName } ` )
445+ . toBeGreaterThanOrEqual ( dates [ i + 1 ] ) ;
446+ }
447+ } ;
448+ await checkDates ( ) ;
449+
450+ // Add an highlight with a comment and check the order again.
451+ await switchToHighlight ( page ) ;
452+ await highlightSpan ( page , 1 , "Languages" ) ;
453+ const editorSelector = getEditorSelector ( 9 ) ;
454+ await page . waitForSelector ( editorSelector ) ;
455+ const commentButtonSelector = `${ editorSelector } button.comment` ;
456+ await waitAndClick ( page , commentButtonSelector ) ;
457+
458+ const textInputSelector = "#commentManagerTextInput" ;
459+ await page . waitForSelector ( textInputSelector , {
460+ visible : true ,
461+ } ) ;
462+ await page . type ( textInputSelector , "Hello world!" ) ;
463+ await page . click ( "#commentManagerSaveButton" ) ;
464+ await waitForSerialized ( page , 1 ) ;
465+
466+ await switchToComment ( page ) ;
467+ await checkDates ( ) ;
468+ } )
469+ ) ;
470+ } ) ;
420471 } ) ;
421472} ) ;
0 commit comments