@@ -55,14 +55,6 @@ describe('TooltipController', () => {
5555 expect ( tooltip . manual ) . to . be . false ;
5656 } ) ;
5757
58- it ( 'should update tooltip opened using controller setOpened method' , ( ) => {
59- controller . setOpened ( true ) ;
60- expect ( tooltip . opened ) . to . be . true ;
61-
62- controller . setOpened ( false ) ;
63- expect ( tooltip . opened ) . to . be . false ;
64- } ) ;
65-
6658 it ( 'should update tooltip shouldShow using controller shouldShow method' , ( ) => {
6759 const shouldShow = ( ) => true ;
6860 controller . setShouldShow ( shouldShow ) ;
@@ -85,6 +77,25 @@ describe('TooltipController', () => {
8577 controller . setAriaTarget ( input ) ;
8678 expect ( tooltip . ariaTarget ) . to . equal ( input ) ;
8779 } ) ;
80+
81+ it ( 'should delegate open to the tooltip state controller' , ( ) => {
82+ tooltip . _stateController = { open : sinon . spy ( ) , close : sinon . spy ( ) } ;
83+ controller . open ( { hover : true } ) ;
84+ expect ( tooltip . _stateController . open ) . to . be . calledOnceWith ( { hover : true } ) ;
85+ } ) ;
86+
87+ it ( 'should not open the tooltip state controller when the tooltip is disconnected' , ( ) => {
88+ tooltip . _stateController = { open : sinon . spy ( ) , close : sinon . spy ( ) } ;
89+ tooltip . remove ( ) ;
90+ controller . open ( { hover : true } ) ;
91+ expect ( tooltip . _stateController . open ) . to . be . not . called ;
92+ } ) ;
93+
94+ it ( 'should delegate close to the tooltip state controller' , ( ) => {
95+ tooltip . _stateController = { open : sinon . spy ( ) , close : sinon . spy ( ) } ;
96+ controller . close ( true ) ;
97+ expect ( tooltip . _stateController . close ) . to . be . calledOnceWith ( true ) ;
98+ } ) ;
8899 } ) ;
89100
90101 describe ( 'lazy tooltip' , ( ) => {
@@ -139,18 +150,6 @@ describe('TooltipController', () => {
139150 expect ( tooltip . manual ) . to . be . false ;
140151 } ) ;
141152
142- it ( 'should update lazy tooltip opened using controller setOpened method' , async ( ) => {
143- controller . setOpened ( true ) ;
144-
145- host . appendChild ( tooltip ) ;
146- await nextFrame ( ) ;
147-
148- expect ( tooltip . opened ) . to . be . true ;
149-
150- controller . setOpened ( false ) ;
151- expect ( tooltip . opened ) . to . be . false ;
152- } ) ;
153-
154153 it ( 'should update lazy tooltip shouldShow using controller shouldShow method' , async ( ) => {
155154 const shouldShow = ( ) => true ;
156155 controller . setShouldShow ( shouldShow ) ;
@@ -238,5 +237,13 @@ describe('TooltipController', () => {
238237 await nextFrame ( ) ;
239238 expect ( host . hasAttribute ( 'has-tooltip' ) ) . to . be . false ;
240239 } ) ;
240+
241+ it ( 'should not throw when calling open before a tooltip is slotted' , ( ) => {
242+ expect ( ( ) => controller . open ( { hover : true } ) ) . to . not . throw ( ) ;
243+ } ) ;
244+
245+ it ( 'should not throw when calling close before a tooltip is slotted' , ( ) => {
246+ expect ( ( ) => controller . close ( true ) ) . to . not . throw ( ) ;
247+ } ) ;
241248 } ) ;
242249} ) ;
0 commit comments