@@ -44,4 +44,72 @@ describe('event-listener-capture using lazy load components', function () {
44
44
// check if event fired 6 times
45
45
await expect ( reattach ) . toHaveText ( expect . stringContaining ( 'Event fired times: 6' ) ) ;
46
46
} ) ;
47
+
48
+ it ( 'should attach keydown event listener once per component' , async ( ) => {
49
+ const elem = document . createElement ( 'event-re-register' ) as HTMLElement ;
50
+ elem . setAttribute ( 'id' , 'elem1' ) ;
51
+ document . body . appendChild ( elem ) ;
52
+
53
+ const reattach = $ ( '#elem1' ) ;
54
+ await expect ( reattach ) . toBePresent ( ) ;
55
+
56
+ // focus on element 1
57
+ await reattach . click ( ) ;
58
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
59
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
60
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
61
+
62
+ // check if event fired 3 times on first element
63
+ await expect ( reattach ) . toHaveText ( expect . stringContaining ( 'Event fired times: 3' ) , {
64
+ message : 'Second element should have fired 3 times' ,
65
+ } ) ;
66
+
67
+ const elem2 = document . createElement ( 'event-re-register' ) as HTMLElement ;
68
+ elem2 . setAttribute ( 'id' , 'elem2' ) ;
69
+ document . body . appendChild ( elem2 ) ;
70
+
71
+ const reattach2 = $ ( '#elem2' ) ;
72
+ await expect ( reattach2 ) . toBePresent ( ) ;
73
+
74
+ // focus on element 2
75
+ await reattach2 . click ( ) ;
76
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
77
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
78
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
79
+
80
+ // check if event fired 3 times on second element
81
+ await expect ( reattach2 ) . toHaveText ( expect . stringContaining ( 'Event fired times: 3' ) , {
82
+ message : 'Second element should have fired 3 times' ,
83
+ } ) ;
84
+
85
+ // remove node from DOM
86
+ elem . remove ( ) ;
87
+ elem2 . remove ( ) ;
88
+
89
+ // reattach node to DOM
90
+ document . body . appendChild ( elem ) ;
91
+ document . body . appendChild ( elem2 ) ;
92
+
93
+ // retrigger event
94
+ await reattach . click ( ) ;
95
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
96
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
97
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
98
+
99
+ // check if event fired 6 times on first element
100
+ await expect ( reattach ) . toHaveText ( expect . stringContaining ( 'Event fired times: 6' ) , {
101
+ message : 'First element should have fired 3 times' ,
102
+ } ) ;
103
+
104
+ // retrigger event on element 2
105
+ await reattach2 . click ( ) ;
106
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
107
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
108
+ await browser . action ( 'key' ) . down ( 'a' ) . pause ( 100 ) . up ( 'a' ) . perform ( ) ;
109
+
110
+ // check if event fired 3 times on second element
111
+ await expect ( reattach2 ) . toHaveText ( expect . stringContaining ( 'Event fired times: 6' ) , {
112
+ message : 'Second element should have fired 3 times' ,
113
+ } ) ;
114
+ } ) ;
47
115
} ) ;
0 commit comments