@@ -103,6 +103,23 @@ describe('vaadin-tooltip', () => {
103
103
await nextUpdate ( tooltip ) ;
104
104
expect ( overlay . hasAttribute ( 'hidden' ) ) . to . be . true ;
105
105
} ) ;
106
+
107
+ it ( 'should fire content-changed event when text changes' , async ( ) => {
108
+ const spy = sinon . spy ( ) ;
109
+ tooltip . addEventListener ( 'content-changed' , spy ) ;
110
+
111
+ tooltip . text = 'Foo' ;
112
+ await nextUpdate ( tooltip ) ;
113
+ expect ( spy . calledOnce ) . to . be . true ;
114
+ expect ( spy . firstCall . args [ 0 ] . detail ) . to . deep . equal ( { content : 'Foo' } ) ;
115
+
116
+ spy . resetHistory ( ) ;
117
+
118
+ tooltip . text = null ;
119
+ await nextUpdate ( tooltip ) ;
120
+ expect ( spy . calledOnce ) . to . be . true ;
121
+ expect ( spy . firstCall . args [ 0 ] . detail ) . to . deep . equal ( { content : '' } ) ;
122
+ } ) ;
106
123
} ) ;
107
124
108
125
describe ( 'generator' , ( ) => {
@@ -147,6 +164,41 @@ describe('vaadin-tooltip', () => {
147
164
await nextUpdate ( tooltip ) ;
148
165
expect ( overlay . hasAttribute ( 'hidden' ) ) . to . be . true ;
149
166
} ) ;
167
+
168
+ it ( 'should fire content-changed event when generator changes' , async ( ) => {
169
+ const spy = sinon . spy ( ) ;
170
+ tooltip . addEventListener ( 'content-changed' , spy ) ;
171
+
172
+ tooltip . generator = ( ) => 'Foo' ;
173
+ await nextUpdate ( tooltip ) ;
174
+ expect ( spy . calledOnce ) . to . be . true ;
175
+ expect ( spy . firstCall . args [ 0 ] . detail ) . to . deep . equal ( { content : 'Foo' } ) ;
176
+
177
+ spy . resetHistory ( ) ;
178
+
179
+ tooltip . generator = ( ) => '' ;
180
+ await nextUpdate ( tooltip ) ;
181
+ expect ( spy . calledOnce ) . to . be . true ;
182
+ expect ( spy . firstCall . args [ 0 ] . detail ) . to . deep . equal ( { content : '' } ) ;
183
+ } ) ;
184
+
185
+ it ( 'should fire content-changed event when context changes' , async ( ) => {
186
+ const spy = sinon . spy ( ) ;
187
+ tooltip . addEventListener ( 'content-changed' , spy ) ;
188
+
189
+ tooltip . context = { text : 'Foo' } ;
190
+ tooltip . generator = ( context ) => context . text ;
191
+ await nextUpdate ( tooltip ) ;
192
+ expect ( spy . calledOnce ) . to . be . true ;
193
+ expect ( spy . firstCall . args [ 0 ] . detail ) . to . deep . equal ( { content : 'Foo' } ) ;
194
+
195
+ spy . resetHistory ( ) ;
196
+
197
+ tooltip . context = { text : 'Bar' } ;
198
+ await nextUpdate ( tooltip ) ;
199
+ expect ( spy . calledOnce ) . to . be . true ;
200
+ expect ( spy . firstCall . args [ 0 ] . detail ) . to . deep . equal ( { content : 'Bar' } ) ;
201
+ } ) ;
150
202
} ) ;
151
203
152
204
describe ( 'target' , ( ) => {
0 commit comments