@@ -1445,4 +1445,85 @@ describe('b-tooltip', () => {
14451445
14461446 wrapper . destroy ( )
14471447 } )
1448+
1449+ it ( 'saves title in data attribute on open and adds to back on hide' , async ( ) => {
1450+ jest . useFakeTimers ( )
1451+ const wrapper = mount ( App , {
1452+ attachTo : createContainer ( ) ,
1453+ propsData : {
1454+ triggers : 'click' ,
1455+ show : false ,
1456+ titleAttr : 'bar'
1457+ } ,
1458+ slots : {
1459+ default : 'title'
1460+ }
1461+ } )
1462+
1463+ expect ( wrapper . vm ) . toBeDefined ( )
1464+ await waitNT ( wrapper . vm )
1465+ await waitRAF ( )
1466+ await waitNT ( wrapper . vm )
1467+ await waitRAF ( )
1468+ jest . runOnlyPendingTimers ( )
1469+
1470+ expect ( wrapper . element . tagName ) . toBe ( 'ARTICLE' )
1471+ expect ( wrapper . attributes ( 'id' ) ) . toBeDefined ( )
1472+ expect ( wrapper . attributes ( 'id' ) ) . toEqual ( 'wrapper' )
1473+
1474+ // The trigger button
1475+ const $button = wrapper . find ( 'button' )
1476+ expect ( $button . exists ( ) ) . toBe ( true )
1477+ expect ( $button . attributes ( 'id' ) ) . toBeDefined ( )
1478+ expect ( $button . attributes ( 'id' ) ) . toEqual ( 'foo' )
1479+ expect ( $button . attributes ( 'title' ) ) . toBeDefined ( )
1480+ expect ( $button . attributes ( 'title' ) ) . toEqual ( 'bar' )
1481+ expect ( $button . attributes ( 'data-original-title' ) ) . not . toBeDefined ( )
1482+ expect ( $button . attributes ( 'aria-describedby' ) ) . not . toBeDefined ( )
1483+
1484+ // Show tooltip
1485+ await wrapper . setProps ( { show : true } )
1486+
1487+ expect ( $button . attributes ( 'title' ) ) . toBeDefined ( )
1488+ expect ( $button . attributes ( 'title' ) ) . toEqual ( '' )
1489+ expect ( $button . attributes ( 'data-original-title' ) ) . toBeDefined ( )
1490+ expect ( $button . attributes ( 'data-original-title' ) ) . toEqual ( 'bar' )
1491+ expect ( $button . attributes ( 'aria-describedby' ) ) . toBeDefined ( )
1492+ // ID of the tooltip that will be in the body
1493+ const adb = $button . attributes ( 'aria-describedby' )
1494+
1495+ // <b-tooltip> wrapper
1496+ const $tipHolder = wrapper . findComponent ( BTooltip )
1497+ expect ( $tipHolder . exists ( ) ) . toBe ( true )
1498+ expect ( $tipHolder . element . nodeType ) . toEqual ( Node . COMMENT_NODE )
1499+
1500+ // Find the tooltip element in the document
1501+ const tip = document . getElementById ( adb )
1502+ expect ( tip ) . not . toBe ( null )
1503+ expect ( tip ) . toBeInstanceOf ( HTMLElement )
1504+ expect ( tip . tagName ) . toEqual ( 'DIV' )
1505+ expect ( tip . classList . contains ( 'tooltip' ) ) . toBe ( true )
1506+ expect ( tip . classList . contains ( 'b-tooltip' ) ) . toBe ( true )
1507+ expect ( tip . classList . contains ( 'interactive' ) ) . toBe ( false )
1508+ expect ( tip . textContent ) . toEqual ( 'title' )
1509+
1510+ // Hide the tooltip
1511+ await wrapper . setProps ( { show : false } )
1512+ await waitRAF ( )
1513+ await waitRAF ( )
1514+ jest . runOnlyPendingTimers ( )
1515+ await waitNT ( wrapper . vm )
1516+ await waitRAF ( )
1517+
1518+ expect ( $button . attributes ( 'title' ) ) . toBeDefined ( )
1519+ expect ( $button . attributes ( 'title' ) ) . toEqual ( 'bar' )
1520+ expect ( $button . attributes ( 'data-original-title' ) ) . not . toBeDefined ( )
1521+ expect ( $button . attributes ( 'aria-describedby' ) ) . not . toBeDefined ( )
1522+
1523+ // Tooltip element should not be in the document
1524+ expect ( document . body . contains ( tip ) ) . toBe ( false )
1525+ expect ( document . querySelector ( adb ) ) . toBe ( null )
1526+
1527+ wrapper . destroy ( )
1528+ } )
14481529} )
0 commit comments