@@ -614,7 +614,7 @@ module.exports = {
614614 editor . destroy ( ) ;
615615 editor . container . remove ( ) ;
616616 } ,
617- "test: selection should follow hovermarker if setSelectOnHover true" : function ( done ) {
617+ "test: selection should follow hovermarker if setSelectOnHover true" : function ( ) {
618618 editor = initEditor ( "hello world\n" ) ;
619619
620620 editor . completers = [
@@ -643,19 +643,20 @@ module.exports = {
643643 assert . equal ( editor . completer . popup . isOpen , true ) ;
644644 assert . equal ( completer . popup . getRow ( ) , 0 ) ;
645645
646+ editor . completer . popup . renderer . $loop . _flush ( ) ;
647+
646648 var text = completer . popup . renderer . content . childNodes [ 2 ] ;
647649 var rect = text . getBoundingClientRect ( ) ;
648650
649651 // We need two mouse events to trigger the updating of the hover marker.
650652 text . dispatchEvent ( new MouseEvent ( "move" , { x : rect . left , y : rect . top } ) ) ;
651653 // Hover over the second row.
652- text . dispatchEvent ( new MouseEvent ( "move" , { x : rect . left + 1 , y : rect . top + 20 } ) ) ;
654+ var lineHeight = completer . popup . renderer . lineHeight ;
655+ text . dispatchEvent ( new MouseEvent ( "move" , { x : rect . left + 1 , y : rect . top + 1.5 * lineHeight } ) ) ;
653656
654657 // Selected row should follow mouse.
655658 editor . completer . popup . renderer . $loop . _flush ( ) ;
656- assert . equal ( completer . popup . getRow ( ) , 2 ) ;
657-
658- done ( ) ;
659+ assert . equal ( completer . popup . getRow ( ) , 1 ) ;
659660 } ,
660661 "test: selection should not follow hovermarker if setSelectOnHover not set" : function ( done ) {
661662 editor = initEditor ( "hello world\n" ) ;
@@ -1705,7 +1706,7 @@ module.exports = {
17051706 } ) ;
17061707 }
17071708 } ,
1708- "test: doc tooltip positioning" : function ( done ) {
1709+ "test: doc tooltip positioning" : async function ( done ) {
17091710 var editor = initEditor ( "" ) ;
17101711 var longDoc = "This is a very long documentation text that should wrap and test the tooltip width constraints." ;
17111712
@@ -1717,70 +1718,79 @@ module.exports = {
17171718 caption : "completion1" ,
17181719 value : "completion1" ,
17191720 docHTML : longDoc
1721+ } ,
1722+ {
1723+ caption : "completion2" ,
1724+ value : "completion2"
1725+ } ,
1726+ {
1727+ caption : "completion3" ,
1728+ value : "completion3"
17201729 }
17211730 ] ) ;
17221731 }
17231732 }
17241733 ] ;
17251734
1726- user . type ( "c" ) ;
1735+
1736+ editor . resize ( ) ;
1737+ await editor . renderer . once ( "afterRender" ) ;
1738+ editor . completer . showPopup ( editor ) ;
17271739
17281740 var popup = editor . completer . popup ;
1741+ var popupRect , tooltipRect ;
17291742
1730- function checkTooltipPosition ( positionCheck , message , next ) {
1731- afterRenderCheck ( popup , function ( ) {
1732- editor . completer . onLayoutChange ( ) ;
1733- var tooltipNode = editor . completer . tooltipNode ;
1734- var popupRect = popup . container . getBoundingClientRect ( ) ;
1735- var tooltipRect = tooltipNode . getBoundingClientRect ( ) ;
1736- assert . ok ( positionCheck ( popupRect , tooltipRect ) , message ) ;
1737- next ( ) ;
1738- } ) ;
1743+ async function waitForDocTooltip ( ) {
1744+ editor . renderer . $loop . _flush ( ) ;
1745+ await new Promise ( resolve => { setTimeout ( resolve , 50 ) ; } ) ;
1746+ editor . completer . onLayoutChange ( ) ;
1747+ var tooltipNode = editor . completer . tooltipNode ;
1748+ popupRect = popup . container . getBoundingClientRect ( ) ;
1749+ tooltipRect = tooltipNode . getBoundingClientRect ( ) ;
17391750 }
17401751
17411752 // Mock the CSS behaviour
17421753 popup . container . style . width = "300px" ;
17431754 popup . container . style . height = "300px" ;
1744- const editorWidth = 400 ;
1755+ var editorWidth = 400 ;
17451756 editor . container . style . width = editorWidth + "px" ;
17461757 editor . container . style . height = "100px" ;
17471758 editor . container . style . left = "0px" ;
17481759 editor . container . style . top = "0px" ;
1760+ popup . container . style . positionHint = "fixed" ;
1761+
1762+
1763+ user . type ( "c" ) ;
1764+ await waitForDocTooltip ( ) ;
1765+ assert . ok ( tooltipRect . left > popupRect . right , "Tooltip should appear on the right" ) ;
17491766
1750- checkTooltipPosition ( ( popupRect , tooltipRect ) => tooltipRect . left > popupRect . right ,
1751- "Tooltip should appear on the right" , ( ) => {
1752- editor . container . style . left = ( window . innerWidth - editorWidth ) + "px" ;
1753- user . type ( "o" ) ;
1754-
1755- checkTooltipPosition ( ( popupRect , tooltipRect ) => tooltipRect . right < popupRect . left ,
1756- "Tooltip should appear on the left" , ( ) => {
1757- editor . container . style . left = "400px" ;
1758- editor . container . style . top = "0px" ;
1759- popup . isTopdown = true ;
1760- user . type ( "Escape" ) ;
1761- user . type ( "Enter" ) ;
1762- user . type ( "c" ) ;
1763-
1764- checkTooltipPosition ( ( popupRect , tooltipRect ) => tooltipRect . top > popupRect . bottom ,
1765- "Tooltip should appear below" , ( ) => {
1766- editor . container . style . top = ( window . innerHeight - 100 ) + "px" ;
1767- editor . container . style . left = "0px" ;
1768- popup . isTopdown = false ;
1769- user . type ( "Escape" ) ;
1770- user . type ( "Enter" ) ;
1771- user . type ( "c" ) ;
1772-
1773- checkTooltipPosition ( ( popupRect , tooltipRect ) => tooltipRect . bottom <= popupRect . top ,
1774- "Tooltip should appear above" , function ( ) {
1775- done ( ) ;
1776- }
1777- ) ;
1778- }
1779- ) ;
1780- }
1781- ) ;
1782- }
1783- ) ;
1767+ editor . container . style . left = ( window . innerWidth - editorWidth ) + "px" ;
1768+ user . type ( "o" ) ;
1769+
1770+ await waitForDocTooltip ( ) ;
1771+
1772+ assert . ok ( tooltipRect . right <= popupRect . left , "Tooltip should appear on the left" ) ;
1773+
1774+ editor . container . style . left = "400px" ;
1775+ editor . container . style . top = "0px" ;
1776+ popup . container . style . width = ( window . innerWidth - 100 ) + "px" ;
1777+ user . type ( "Escape" ) ;
1778+ user . type ( "Enter" ) ;
1779+ user . type ( "c" ) ;
1780+
1781+ await waitForDocTooltip ( ) ;
1782+ assert . ok ( tooltipRect . top >= popupRect . bottom , "Tooltip should appear below" ) ;
1783+
1784+ editor . container . style . top = ( window . innerHeight - 100 ) + "px" ;
1785+ editor . container . style . left = "0px" ;
1786+ user . type ( "Escape" ) ;
1787+ user . type ( "Enter" ) ;
1788+ user . type ( "c" ) ;
1789+
1790+ await waitForDocTooltip ( ) ;
1791+ assert . ok ( tooltipRect . bottom <= popupRect . top , "Tooltip should appear above" ) ;
1792+
1793+ done ( ) ;
17841794 } ,
17851795} ;
17861796
0 commit comments