11import { expect } from '@playwright/test' ;
22import { test } from '@stencil/playwright' ;
33
4+ declare global {
5+ interface Window {
6+ __focusinEventCount : number ;
7+ __focusEventCount : number ;
8+ }
9+ }
10+
411test . describe ( 'kol-tree' , ( ) => {
512 test ( 'focus() method sets focus on the first focusable tree item' , async ( { page } ) => {
613 await page . setContent ( `
@@ -48,15 +55,15 @@ test.describe('kol-tree - Focus Performance', () => {
4855
4956 // Initialize focusin event counter on the tree host
5057 await treeHost . evaluate ( ( ) => {
51- ( window as any ) . __focusinEventCount = 0 ;
58+ window . __focusinEventCount = 0 ;
5259 } ) ;
5360
5461 // Add focusin event listener to count events
5562 await treeHost . evaluate ( ( ) => {
56- const tree = document . querySelector ( 'kol-tree' ) ;
57- if ( tree ) {
58- tree . addEventListener ( 'focusin' , ( ) => {
59- ( window as any ) . __focusinEventCount ++ ;
63+ const treeElement = document . querySelector ( 'kol-tree' ) ;
64+ if ( treeElement ) {
65+ treeElement . addEventListener ( 'focusin' , ( ) => {
66+ window . __focusinEventCount ++ ;
6067 } ) ;
6168 }
6269 } ) ;
@@ -73,7 +80,7 @@ test.describe('kol-tree - Focus Performance', () => {
7380 await expect ( firstItemLink ) . toBeFocused ( ) ;
7481
7582 // Check focusin event count - should be max 1 (guard clause prevents multiple triggers)
76- const focusinCount = await page . evaluate ( ( ) => ( window as any ) . __focusinEventCount ) ;
83+ const focusinCount = await page . evaluate ( ( ) => window . __focusinEventCount ) ;
7784 expect ( focusinCount ) . toBeLessThanOrEqual ( 1 ) ;
7885 } ) ;
7986
@@ -104,15 +111,15 @@ test.describe('kol-tree - Focus Performance', () => {
104111
105112 // Initialize focus event counter
106113 await page . evaluate ( ( ) => {
107- ( window as any ) . __focusEventCount = 0 ;
114+ window . __focusEventCount = 0 ;
108115 } ) ;
109116
110117 // Add focus event listener on the tree host
111118 await tree . evaluate ( ( ) => {
112119 const treeElement = document . querySelector ( 'kol-tree' ) ;
113120 if ( treeElement ) {
114121 treeElement . addEventListener ( 'focusin' , ( ) => {
115- ( window as any ) . __focusEventCount ++ ;
122+ window . __focusEventCount ++ ;
116123 } ) ;
117124 }
118125 } ) ;
@@ -123,7 +130,7 @@ test.describe('kol-tree - Focus Performance', () => {
123130
124131 // Reset counter after focus is set
125132 await page . evaluate ( ( ) => {
126- ( window as any ) . __focusEventCount = 0 ;
133+ window . __focusEventCount = 0 ;
127134 } ) ;
128135
129136 // Expand Item 2
@@ -135,7 +142,7 @@ test.describe('kol-tree - Focus Performance', () => {
135142 await page . waitForTimeout ( 100 ) ;
136143
137144 // Check focus event count - should be <= 1 (at most 1 from expand, not multiple)
138- const focusCount = await page . evaluate ( ( ) => ( window as any ) . __focusEventCount ) ;
145+ const focusCount = await page . evaluate ( ( ) => window . __focusEventCount ) ;
139146 expect ( focusCount ) . toBeLessThanOrEqual ( 1 ) ;
140147
141148 // Verify Item 2 is still focused
@@ -218,15 +225,15 @@ test.describe('kol-tree - Focus Performance', () => {
218225
219226 // Initialize event counter before any navigation
220227 await page . evaluate ( ( ) => {
221- ( window as any ) . __focusinEventCount = 0 ;
228+ window . __focusinEventCount = 0 ;
222229 } ) ;
223230
224231 // Add focusin event listener during navigation phase
225232 await tree . evaluate ( ( ) => {
226233 const treeElement = document . querySelector ( 'kol-tree' ) ;
227234 if ( treeElement ) {
228235 treeElement . addEventListener ( 'focusin' , ( ) => {
229- ( window as any ) . __focusinEventCount ++ ;
236+ window . __focusinEventCount ++ ;
230237 } ) ;
231238 }
232239 } ) ;
@@ -245,7 +252,7 @@ test.describe('kol-tree - Focus Performance', () => {
245252
246253 // Check focusin event count - should match number of focus changes (3 items focused)
247254 // Each focus generates 1 focusin event; what matters is that there's no redundancy
248- const focusinCount = await page . evaluate ( ( ) => ( window as any ) . __focusinEventCount ) ;
255+ const focusinCount = await page . evaluate ( ( ) => window . __focusinEventCount ) ;
249256 expect ( focusinCount ) . toBeLessThanOrEqual ( 3 ) ;
250257
251258 // Verify final focus is on Item 4
0 commit comments