@@ -3,40 +3,43 @@ import registry from "../../core/registry";
3
3
import utils from "../../core/utils" ;
4
4
5
5
describe ( "pat-autofocus" , function ( ) {
6
- it ( "Focus the first element." , async ( ) => {
6
+ it ( "1 - Focus the first element." , async ( ) => {
7
7
document . body . innerHTML = `
8
8
<input name="i1" type="text" class="pat-autofocus"/>
9
9
<input name="i2" type="text" class="pat-autofocus"/>
10
10
<input name="i3" type="text" class="pat-autofocus"/>
11
11
` ;
12
12
registry . scan ( document . body ) ;
13
- await utils . timeout ( 100 ) ;
13
+ await utils . timeout ( 1 ) ; // Wait for async pattern initialization.
14
+ await utils . timeout ( 100 ) ; // Wait for autofocus timeout.
14
15
15
16
const should_be_active = document . querySelector ( "input[name=i1]" ) ;
16
17
expect ( document . activeElement ) . toBe ( should_be_active ) ;
17
18
} ) ;
18
19
19
- it ( "Focus the first empty element, if available." , async ( ) => {
20
+ it ( "2 - Focus the first empty element, if available." , async ( ) => {
20
21
document . body . innerHTML = `
21
22
<input name="i1" type="text" class="pat-autofocus" value="okay"/>
22
23
<input name="i2" type="text" class="pat-autofocus"/>
23
24
<input name="i3" type="text" class="pat-autofocus"/>
24
25
` ;
25
26
registry . scan ( document . body ) ;
26
- await utils . timeout ( 100 ) ;
27
+ await utils . timeout ( 1 ) ; // Wait for async pattern initialization.
28
+ await utils . timeout ( 100 ) ; // Wait for autofocus timeout.
27
29
28
30
const should_be_active = document . querySelector ( "input[name=i2]" ) ;
29
31
expect ( document . activeElement ) . toBe ( should_be_active ) ;
30
32
} ) ;
31
33
32
- it ( "Don't focus hidden elements." , async ( ) => {
34
+ it ( "3 - Don't focus hidden elements." , async ( ) => {
33
35
document . body . innerHTML = `
34
36
<input name="i1" type="text" class="pat-autofocus" value="okay"/>
35
37
<input name="i2" type="text" class="pat-autofocus" hidden/>
36
38
<input name="i3" type="text" class="pat-autofocus"/>
37
39
` ;
38
40
registry . scan ( document . body ) ;
39
- await utils . timeout ( 100 ) ;
41
+ await utils . timeout ( 1 ) ; // Wait for async pattern initialization.
42
+ await utils . timeout ( 100 ) ; // Wait for autofocus timeout.
40
43
41
44
const should_be_active = document . querySelector ( "input[name=i3]" ) ;
42
45
expect ( document . activeElement ) . toBe ( should_be_active ) ;
0 commit comments