@@ -28,6 +28,16 @@ describe('d2l-button-copy', () => {
2828 expect ( dispatched ) . to . be . false ;
2929 } ) ;
3030
31+ it ( 'stops propagation when clicked' , async ( ) => {
32+ const el = await fixture ( html `< d2l-button-copy > </ d2l-button-copy > ` ) ;
33+ let propagated = false ;
34+ el . parentElement . addEventListener ( 'click' , ( ) => propagated = true ) ;
35+ const buttonIcon = el . shadowRoot . querySelector ( 'd2l-button-icon' ) ;
36+ clickElem ( buttonIcon ) ;
37+ await oneEvent ( el , 'click' ) ;
38+ expect ( propagated ) . to . be . false ;
39+ } ) ;
40+
3141 } ) ;
3242
3343 describe ( 'writeTextToClipboard' , ( ) => {
@@ -62,4 +72,32 @@ describe('d2l-button-copy', () => {
6272
6373 } ) ;
6474
75+ describe ( 'icon state' , ( ) => {
76+
77+ it ( 'clears previous timeout on multiple clicks' , async ( ) => {
78+ const writeTextStub = stub ( navigator . clipboard , 'writeText' ) . resolves ( ) ;
79+ const el = await fixture ( html `< d2l-button-copy > </ d2l-button-copy > ` ) ;
80+
81+ // First click
82+ clickElem ( el ) ;
83+ let event = await oneEvent ( el , 'click' ) ;
84+ await event . detail . writeTextToClipboard ( 'first' ) ;
85+ await el . updateComplete ;
86+
87+ const firstTimeoutId = el . _iconCheckTimeoutId ;
88+
89+ // Second click before timeout expires
90+ clickElem ( el ) ;
91+ event = await oneEvent ( el , 'click' ) ;
92+ await event . detail . writeTextToClipboard ( 'second' ) ;
93+ await el . updateComplete ;
94+
95+ const secondTimeoutId = el . _iconCheckTimeoutId ;
96+
97+ expect ( firstTimeoutId ) . to . not . equal ( secondTimeoutId ) ;
98+ writeTextStub . restore ( ) ;
99+ } ) ;
100+
101+ } ) ;
102+
65103} ) ;
0 commit comments