11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
3- import { TestSuite } from '../types' ;
3+ import { TestDefinition , TestSuite } from '../types' ;
4+
5+ const focusStatesPath = 'input/focus-states' ;
6+ const inputSelector = ( testId : string ) => `[data-testid="${ testId } "] input` ;
7+ // Pointer target outside any input: the page heading.
8+ const headingSelector = 'h1' ;
49
510const suite : TestSuite = {
611 description : 'Input' ,
@@ -21,6 +26,36 @@ const suite: TestSuite = {
2126 path : 'input/inline-label-permutations' ,
2227 screenshotType : 'permutations' ,
2328 } ,
29+ {
30+ description : 'focus states - rest' ,
31+ path : focusStatesPath ,
32+ screenshotType : 'screenshotArea' ,
33+ } ,
34+ // Focus is produced with page.click(): the input's focus styles are plain CSS :focus/:focus-within,
35+ // which a dispatched focusin event (page.focusInputs()) does not trigger. Only one element can hold
36+ // focus, so each input gets its own focused entry.
37+ ...[ 'readonly' , 'native-invalid' , 'suffix' , 'prefix' ] . flatMap (
38+ testId =>
39+ [
40+ {
41+ description : `focus states - focused ${ testId } ` ,
42+ path : focusStatesPath ,
43+ screenshotType : 'screenshotArea' ,
44+ setup : async ( { page } ) => {
45+ await page . click ( inputSelector ( testId ) ) ;
46+ } ,
47+ } ,
48+ {
49+ description : `focus states - focused ${ testId } , pointer away` ,
50+ path : focusStatesPath ,
51+ screenshotType : 'screenshotArea' ,
52+ setup : async ( { page } ) => {
53+ await page . click ( inputSelector ( testId ) ) ;
54+ await page . hoverElement ( headingSelector ) ;
55+ } ,
56+ } ,
57+ ] as TestDefinition [ ]
58+ ) ,
2459 ] ,
2560} ;
2661
0 commit comments